Domain 5 of 8 · Chapter 4 of 4

Managing module versions

Unlock the complete study guide + 1,040 practice questions across 16 full exams.

Bundled into the existing HashiCorp Certified: Terraform Associate premium course — no separate purchase.

14-day money-back guarantee — no questions asked.

Included in this chapter:

  • Pinning follows the module source
  • Registry modules: the version argument
  • Pinning Git modules with ?ref=
  • Installing and updating modules
  • Exam-pattern recognition: version traps

How module version pinning varies by source type

AspectRegistry moduleGit (VCS) moduleLocal path module
Pinning mechanism`version` argument`?ref=` in the source URLNone (shares caller's version)
Accepted valuesConstraint string: `"~> 1.2"`, `">= 1.0"`, `"1.2.0"`Any git ref: branch, tag, or commit SHANot applicable
If unspecified`init` installs the newest available releaseClones the default branch (`HEAD`)Always in lockstep with the caller
Move to a newer version`init -upgrade` / `get -update` within the constraintEdit `?ref=` to the new tag, then re-initNot applicable

Decision tree

Registry module?YesNoUse the version argumente.g. version = ~> 1.2(omit = newest release)Git (git::) source?NoYesLocal path moduleno version pin;shares caller versionImmutable pin?YesNo?ref= tag or full SHA(immutable pin)?ref= branch, or omittracks HEAD (drifts)

Cheat sheet

  • The version argument works only for registry modules
  • Omitting version installs the newest registry release
  • Version constraint operators for modules
  • Pin Git modules with the ?ref= query argument
  • ref accepts a branch, tag, or commit SHA
  • Pinning module versions is a best practice
  • terraform init installs modules
  • terraform get downloads and updates only modules
  • terraform get -update vs terraform init -upgrade

Unlock with Premium — includes all practice exams and the complete study guide.

References

  1. Version Constraints
  2. Module Sources
  3. Module blocks (Configuration Language)
  4. Use modules in your configuration
  5. Command: terraform get
  6. Command: terraform init