HashiCorp Terraform Associate (004) · Section 5 · 10% of the exam
Explain how Terraform sources modules
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 team calls the same registry module in 40 repositories with version = ">= 1.0". After the module author releases 2.0.0 with renamed variables, new terraform init -upgrade runs fail in several repositories. Which change best prevents a repeat while still accepting compatible fixes?
- ARemove the
versionargument so Terraform picks a stable release - BUse
version = "~> 1.0"so only 1.x releases are eligible - CAdd the module to
.terraform.lock.hclwithterraform providers lock - DReplace
>=with>so version 1.0.0 is excluded
Show the answer
B. Open-ended constraints accept new major versions, which may break inputs and outputs. ~> 1.0 accepts any 1.x release but excludes 2.0.0, so upgrades to a new major version become a deliberate edit.
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.