Skip to content

004 · Domain 5: Terraform modules · 12% of the exam

Task 5.4: Manage module versions

The version argument for registry modules, refs for Git sources, version constraint operators, and upgrading modules with init -upgrade.

Study it

  • Module versions: constraints, Git refs and upgrades

    Lesson coming

Sample questions

Try each one before opening the answer. Every option is explained, with the HashiCorp documentation page that proves it.

Question 1 · choose 1

A root module uses a registry module and wants patch and minor releases of major version 3 but never version 4. Which setting expresses this?

  1. Aversion = "~> 3.0" in the module block
  2. Bversion = "~> 3.0.0" in the module block
  3. Csource = "terraform-aws-modules/vpc/aws@3"
  4. DA required_providers entry for the module with version "~> 3.0"
Show the answer and why
  • Aversion = "~> 3.0" in the module block

    Correct

    Registry modules accept a version constraint; "~> 3.0" allows 3.x releases and excludes 4.0.

  • Bversion = "~> 3.0.0" in the module block

    Incorrect

    That allows only 3.0.x patch releases, not 3.1 and later.

  • Csource = "terraform-aws-modules/vpc/aws@3"

    Incorrect

    Terraform does not accept an @ version suffix in a source address.

  • DA required_providers entry for the module with version "~> 3.0"

    Incorrect

    required_providers is for providers, not modules.

Registry modules carry their own version argument with the usual constraint syntax.

Question 2 · choose 1

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?

  1. AThe lock file was stale; deleting it makes both select the same version
  2. BModules are re-downloaded on every plan, so plans must run with -lock=false
  3. CRegistry modules ignore version constraints after the first install
  4. 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.

Question 3 · choose 1

An engineer wants to see which versions of a public registry module exist and get a ready-made snippet for calling it. Where should they look?

  1. AThe output of terraform version in the working directory
  2. BThe module's page in the Terraform Registry, which shows its versions and usage instructions
  3. CThe dependency lock file of another project that uses the module
  4. DThe state file, which records every version a module ever had
Show the answer and why
  • AThe output of terraform version in the working directory

    Incorrect

    version reports Terraform and installed provider versions, not module releases.

  • BThe module's page in the Terraform Registry, which shows its versions and usage instructions

    Correct

    Each registry module is versioned, and its page shows usage instructions you can copy to get started.

  • CThe dependency lock file of another project that uses the module

    Incorrect

    Lock files record provider selections, not module versions.

  • DThe state file, which records every version a module ever had

    Incorrect

    State records resources, not a module's release history.

The Registry page is the catalog of a module's versions and the place to copy its calling syntax.

Question 4 · choose 1

A module should accept any 1.x release from 1.4 upward but not 2.0. Which constraint expresses this?

  1. Aversion = ">= 1.4, < 2.0"
  2. Bversion = "1.4 - 2.0"
  3. Cversion = "^1.4"
  4. Dversion = "1.4+"
Show the answer and why
  • Aversion = ">= 1.4, < 2.0"

    Correct

    Multiple conditions are separated by commas, and versions must meet all of them.

  • Bversion = "1.4 - 2.0"

    Incorrect

    Terraform has no hyphen range syntax.

  • Cversion = "^1.4"

    Incorrect

    ^ is not a Terraform constraint operator.

  • Dversion = "1.4+"

    Incorrect

    + is not a Terraform constraint operator.

Terraform constraints use =, !=, >, >=, <, <= and ~>, combined with commas.

Question 5 · choose 1

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?

  1. ANo version argument at all, so callers always get the newest release
  2. BCopy each module's code into every root configuration
  3. CUse only pre-release versions so changes are visible
  4. 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.

Question 6 · choose 1

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)

  1. Aterraform providers -json
  2. Bterraform state list -json
  3. Cterraform version -json
  4. 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.

Practise domain 5 →Practise all domains →