Terraform 004 modules explained

Updated November 23, 2026

Objective 5 of the Terraform Associate (004) is modules: reusable packages of configuration. It has four sub-objectives, covering how Terraform sources modules (5a), variable scope inside them (5b), using them in configuration (5c) and managing their versions (5d). The ideas are simple, but the exam likes precise statements about what a module can and cannot see.

What a module is

Every Terraform configuration is a module. The directory you run commands in is the root module, and any module it calls is a child module. A child module is a folder of .tf files with its own input variables, resources and outputs. You call it with a module block that sets a source and passes arguments for its input variables.

5a: Sourcing modules

Source typeExample idea
Local pathA relative folder such as ./modules/network
Terraform RegistryA public or private registry address with a namespace, name and provider
Git, HTTP and other remote sourcesA repository URL, optionally pinned to a ref

After you add or change a module source, run terraform init so Terraform can fetch the module. Registry modules support a version argument; local paths do not, because they are not versioned.

5b: Variable scope

A child module is isolated. It cannot read the parent’s variables, locals or resources. Everything it needs must be passed in as an input variable, and everything the parent needs from it must be returned through an output. The parent reads it as module.<name>.<output>. This isolation is what makes modules reusable and testable.

5c: Using modules

  • Use inputs for anything that varies between uses, and give optional ones sensible defaults.
  • Use outputs for the values callers need, such as IDs.
  • Use count or for_each on a module block to create several instances.
  • Pass providers explicitly when a module needs a non-default provider configuration.

5d: Managing versions

For registry modules, pin with a version constraint such as an exact version, a range or the pessimistic operator (~>), so upgrades are deliberate. Re-run terraform init -upgrade to move to the newest version allowed by the constraint. For Git sources, pin to a tag or commit. Pinning is a best practice because an unpinned module can change under you.

Typical traps

  • Expecting a child module to see the root module’s variables.
  • Forgetting terraform init after adding or changing a module.
  • Using a version argument with a local path module.
  • Referencing a child resource directly instead of through an output.

Sample questions

Question 1. A child module needs the CIDR range defined in a root module variable. What must happen?

  • A. Nothing, the child reads root variables automatically
  • B. The child must declare an output with that name
  • C. The root passes the value to a variable declared in the child
  • D. The value must be copied into the state file by hand
Show answer

Answer: C

Modules are isolated: values reach a child only as input variables passed in the module block. The child cannot read the root’s variables or locals, and outputs flow the other way, from child to parent.

Want more questions like this? Full Terraform 004 practice tests →

Question 2. After adding a new module block that uses a registry source, terraform plan reports that the module is not installed. What is the fix?

  • A. Run terraform init
  • B. Run terraform fmt
  • C. Run terraform apply
  • D. Delete the lock file only
Show answer

Answer: A

Modules are downloaded by terraform init, which must be run after adding or changing a module source. Apply and refresh do not install modules, and fmt only formats files.

Want more questions like this? Full Terraform 004 practice tests →

Question 3. A team wants module upgrades from the registry to be deliberate and reviewable. Which practice helps most?

  • A. Leave the version argument out so the latest is always used
  • B. Add an output for the module version
  • C. Copy the module to a local path and never update it
  • D. Pin the module with a version constraint and upgrade on purpose
Show answer

Answer: D

Pinning the module with a version constraint means the version only changes when someone edits the constraint or deliberately upgrades. Leaving it unpinned allows silent changes, and neither outputs nor local paths control registry versions.

Want more questions like this? Full Terraform 004 practice tests →

Next

See state management for how Terraform tracks what modules create, or go back to configuration.