A root module uses version = ">= 2.0" for a registry module. Two engineers running init on fresh clones a week apart got different module versions, even though the lock file is committed. Why, and what fixes it?
AThe lock file was stale; deleting it makes both select the same version
BModules are re-downloaded on every plan, so plans must run with -lock=false
CRegistry modules ignore version constraints after the first install
DThe lock file tracks only providers, so pin the module with an exact version
Show the answer and why
AThe lock file was stale; deleting it makes both select the same version
Incorrect
The lock file never contained module versions.
BModules are re-downloaded on every plan, so plans must run with -lock=false
Incorrect
Modules are installed by init, and state locking is unrelated to module versions.
CRegistry modules ignore version constraints after the first install
Incorrect
Constraints are honored; ">= 2.0" simply allows newer releases.
DThe lock file tracks only providers, so pin the module with an exact version
Correct
Terraform does not record module selections in the lock file; an exact version constraint guarantees the same module version.
Providers are locked by .terraform.lock.hcl; modules are locked only by exact constraints.
An organization releases its internal modules with strict semantic versioning and a reviewed release process. What do the version constraint best practices suggest for consuming them?
ANo version argument at all, so callers always get the newest release
BCopy each module's code into every root configuration
CUse only pre-release versions so changes are visible
DVersion ranges are reasonable here
Show the answer and why
ANo version argument at all, so callers always get the newest release
Incorrect
Omitting constraints makes every new install unpredictable.
BCopy each module's code into every root configuration
Incorrect
Copies lose the versioned releases that the registry provides.
CUse only pre-release versions so changes are visible
Incorrect
Pre-releases are for testing, and need exact versions.
DVersion ranges are reasonable here
Correct
The docs suggest version ranges when your organization consistently uses semantic versioning or follows a well-defined release process.
Trusted semantic versioning makes ranges safe; unknown publishers call for tighter pins.
A platform team wants to audit which modules a configuration declares and their sources and versions, as JSON, without running a plan. Which command fits? (Terraform 1.12)
Aterraform providers -json
Bterraform state list -json
Cterraform version -json
Dterraform modules -json
Show the answer and why
Aterraform providers -json
Incorrect
providers lists provider requirements.
Bterraform state list -json
Incorrect
state list prints resource addresses from state, not module declarations.
Cterraform version -json
Incorrect
version reports Terraform and provider versions.
Dterraform modules -json
Correct
terraform modules (Terraform 1.10 and later) gives a view of the declared modules and can print it as JSON.
terraform modules is built for auditing module use.