HashiCorp Terraform Associate (004) · Section 5 · 10% of the exam
Manage module versions
One of the objectives of the HashiCorp Certified: Terraform Associate (004) exam, in the section “Terraform modules”. Here is what it covers, the points to remember and a question to try.
What it covers
A module is a folder of Terraform files that you call from another configuration. This lesson covers where a module can come from (local paths, the public and private registries, Git, archives and buckets), how terraform init installs it, and how to pin and upgrade versions with version constraints, Git refs and semantic version tags.
Points to remember
- A module is a directory of .tf files; the working directory is the root module and called modules are child modules.
sourceis required and (in 1.12) a literal string; supported types are local paths, registries, GitHub, Bitbucket, generic Git, HTTP archives, S3, GCS and Mercurial.- Local paths must start with ./ or ../ and have no versions;
acme/vpc/awsis a registry address. versionworks only for registry modules; Git modules pin with ?ref= (tag, branch or SHA), and no ref means the default branch.- Registry address: <NAMESPACE>/<NAME>/<PROVIDER>; private registry adds a hostname first (app.terraform.io for HCP Terraform).
Try a question
A module block uses a registry module and you want to accept any 4.x release but never 5.0. Which version argument does this?
- A
version = "4.*" - B
version = "~> 4.0" - C
version = "> 4.0" - D
version = "= 4.0"
Show the answer
B. The pessimistic constraint operator ~> allows only the right-most version component to increase. ~> 4.0 accepts 4.0.0 up to but excluding 5.0.0.
Written for practice in the style of the exam: never a question from the real exam.
In the course
The lesson Module sources and module versions teaches this objective (about 40 minutes), and 18 practice questions test it. The course has lessons, exam-style questions, timed practice exams and an AI tutor for every objective, and a pass prediction that tells you when you're ready to book.