Bitzu

Terraform Associate 004 ยท Terraform modules

How do you manage module versions?

version argument only for registry sources, constraints, Git ref pinning, upgrading with init -upgrade (5d).

Key points

  • The version argument takes a constraint and works only for registry modules.
  • Git modules are pinned with ?ref= (branch, tag or commit), and local paths share the caller's version.
  • After changing source or version, run terraform init; add -upgrade to move to the newest release the constraint allows.

Source: https://developer.hashicorp.com/terraform/language/modules/sources

Practice questions

Single choice

For which kind of module source does the version argument apply?

  1. Local paths
  2. Registry modules
  3. Git repositories
  4. S3 buckets
Show answer

Answer: B. Registry modules

version is only valid for modules from a registry. Git uses ref, and local paths have no separate version.

Select all that apply

Which are valid version constraint strings?

  1. ~> 2.3
  2. >= 1.0, < 2.0
  3. = 1.4.0
  4. latest
  5. ^1.2
Show answer

Answer: A. ~> 2.3, B. >= 1.0, < 2.0, C. = 1.4.0

~> pessimistic, comma-joined ranges and = exact pins are all valid. "latest" and caret ranges are not Terraform constraint syntax.

True or false

True or false: you can use the version argument to pin a module loaded from a local path.

Show answer

Answer: False

False. A local module shares its caller's version, so version is not supported there.

Practice 8 questions on this topic in Bitzu

Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.

Download on the App StoreGet it on Google Play

More Terraform Associate 004 topics in this module