Terraform Associate Domain 5: Terraform Modules
22 free practice questions for Terraform Modules in the HashiCorp Certified: Terraform Associate (004) exam. Try each question first, then open "Show answer" for the correct option and explanation.
Terraform Modules practice questions
-
Question 1. What is a Terraform module?
Show answer
Answer: B. A set of configuration files in one directory
Every configuration is a module. Modules called from another module are child modules.
-
Question 2. What is the root module?
Show answer
Answer: A. The module in the working directory where you run Terraform
The root module can call child modules, which can call others.
-
Question 3. Which block calls a child module?
Show answer
Answer: D. module "network" { source = ... }
source is required. Other arguments set the child module's input variables.
-
Question 4. Which source format refers to a module on the public Terraform Registry?
Show answer
Answer: B. <NAMESPACE>/<NAME>/<PROVIDER>, such as terraform-aws-modules/vpc/aws
Private registry modules add a hostname, for example app.terraform.io/<ORG>/<NAME>/<PROVIDER>.
-
Question 5. For which module sources can you set the version argument in a module block?
Show answer
Answer: C. Only modules from a registry
For Git sources, pin a version with ?ref= in the URL. Local paths have no version.
-
Question 6. How do you use a module from a Git repository at tag v1.2.0?
Show answer
Answer: A. source = "git::https://example.com/vpc.git?ref=v1.2.0"
ref accepts a branch, tag, or commit. Pinning to a tag or commit keeps runs repeatable.
-
Question 7. How does Terraform recognize a local module source?
Show answer
Answer: D. It starts with ./ or ../
For example, source = "./modules/network". Local modules aren't downloaded, so changes take effect at once.
-
Question 8. You add a new module block to a configuration. What must you do before terraform plan?
Show answer
Answer: B. Run terraform init (or terraform get) to install it
init installs modules into .terraform/modules. Plan fails with a module not installed error otherwise.
-
Question 9. How do you pass a value into a child module?
Show answer
Answer: C. Set the module's input variable as an argument in the module block
Arguments in the module block, other than meta-arguments like source and count, set the child's variables.
-
Question 10. How does the root module use output vpc_id from module "network"?
Show answer
Answer: A. module.network.vpc_id
Only values the child declares as outputs are visible to the caller.
-
Question 11. Can a child module read the parent module's variables directly?
Show answer
Answer: D. No; values must be passed in as inputs
Each module has its own namespace. That keeps modules reusable and their interface explicit.
-
Question 12. Can the root module reference a resource inside a child module directly, such as module.network.aws_vpc.this.id?
Show answer
Answer: B. No, only through outputs the child declares
Expose what callers need with output blocks in the child module.
-
Question 13. Can you use count or for_each on a module block?
Show answer
Answer: C. Yes, to create several instances of the module
Instances are addressed as module.network[0] or module.network["east"].
-
Question 14. If a child module doesn't receive a providers argument, which provider configurations does it use?
Show answer
Answer: A. The default provider configurations inherited from the parent
Child modules shouldn't define provider blocks themselves. They declare required_providers and receive configurations from the caller.
-
Question 15. Why should you constrain the versions of modules you consume?
Show answer
Answer: D. So upstream changes don't alter your infrastructure unexpectedly
Upgrade deliberately, read the changelog, and review the plan.
-
Question 16. What naming pattern must a module repository follow to be published on the public Terraform Registry?
Show answer
Answer: B. terraform-<PROVIDER>-<NAME>
For example terraform-aws-vpc. The registry also expects the standard module structure and semantic version tags.
-
Question 17. Where does terraform init put downloaded modules?
Show answer
Answer: C. In .terraform/modules
Like providers, this directory is created by init and shouldn't be committed.
-
Question 18. Which HCP Terraform feature lets an organization publish and share its own modules internally?
Show answer
Answer: A. The private registry
The private registry works like the public one but is visible only inside the organization.
-
Question 19. What does the standard module structure usually include?
Show answer
Answer: D. main.tf, variables.tf, outputs.tf, and a README
The registry uses this layout to generate documentation for inputs and outputs.
-
Question 20. In state, what is the address of resource aws_vpc.this created by module "network"?
Show answer
Answer: B. module.network.aws_vpc.this
Nested modules chain addresses, for example module.app.module.network.aws_vpc.this.
-
Question 21. Can a module block's source argument be set from a variable?
Show answer
Answer: C. No, source must be a literal string
Terraform installs modules during init, before variables are evaluated.
-
Question 22. A child module's output is marked sensitive. What happens if the root module outputs that value without sensitive = true?
Show answer
Answer: A. Terraform reports an error until the root output also sets sensitive = true
Terraform won't silently drop sensitivity, so the root output must also be declared sensitive.
HashiCorp, Terraform, and HCP Terraform are trademarks of HashiCorp, Inc. These questions are original study material, not questions from the real exam.