HashiCorp Terraform Associate (004) Question 131
Single answer5 Terraform modulesYour team maintains a reusable Terraform module that creates a VPC and related networking resources. The module is currently sourced from a local path during development. A second team now needs to consume the module in their own configuration and must be able to pin to a stable released version so future changes do not unexpectedly alter their infrastructure. Which approach best meets this requirement?
- A
Publish the module to a Terraform module registry and have consumers reference it with a version argument.
- B
Keep the module in a local directory and ask consumers to copy the module files into their own repository whenever they need updates.
- C
Reference the module from a Git repository branch name, because branches provide immutable release points for Terraform modules.
- D
Use terraform workspace to separate module versions so each team can select the version they want.
Show answer and explanation
Correct answer: A
Explanation
For reusable modules shared across teams, Terraform best practice is to publish them through a module registry and use semantic versioning so consumers can set explicit version constraints. Registry-based distribution is designed for discoverability, reuse, and controlled upgrades. Although modules can also be sourced from Git, stable version pinning requires immutable references such as tags or commit SHAs, not branch names. Workspaces solve a different problem: managing multiple state instances. Relevant Terraform documentation includes the module block syntax, module source options, and use of the version argument with registry modules, as well as Terraform Registry module publishing guidance.
- A. Correct.
Correct. Publishing the module to a Terraform module registry, such as a private registry in Terraform Cloud/Enterprise or the public Terraform Registry, is the standard way to distribute reusable modules with versioning. Consumers can reference the module source and specify a version constraint, which lets them pin to a stable release and upgrade intentionally. This directly supports the team's requirement to avoid unexpected changes.
- B. Incorrect.
Incorrect. Copying module files between repositories removes the benefits of centralized module reuse and version management. It creates drift, makes updates harder to track, and is not how Terraform recommends sharing reusable modules across teams. While it might appear simple, it does not provide controlled version pinning in a maintainable way.
- C. Incorrect.
Incorrect. Terraform can source modules from Git, and using a tag or commit SHA can support repeatable versions. However, a branch name is not immutable; it can move as new commits are added. That means it does not reliably pin consumers to a stable released version. This option reflects a common misconception that branches are equivalent to releases.
- D. Incorrect.
Incorrect. Workspaces are used to manage multiple state instances for the same configuration, such as dev and prod, not to version Terraform modules. They do not provide a mechanism for publishing, distributing, or pinning reusable modules for different teams.