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
For which kind of module source does the version argument apply?
- Local paths
- Registry modules
- Git repositories
- 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.
Which are valid version constraint strings?
- ~> 2.3
- >= 1.0, < 2.0
- = 1.4.0
- latest
- ^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: 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.
