WebMagicInformatica
Terraform Associate (004) practice questions

Terraform Associate (004) practice questions: Terraform modules

5 free questions on Terraform modules, 10% of the HashiCorp Terraform Associate exam. Try each one, then open the answer and explanation. None of them are in the free readiness check, so you can still take it fresh.

Question 1

A root module calls a child module. How does the root module read the child's vpc_id output?

module "network" {
  source = "./modules/network"
  cidr   = "10.0.0.0/16"
}
  1. A.

    module.network.vpc_id

  2. B.

    network.vpc_id

  3. C.

    module.network.output.vpc_id

  4. D.

    var.network.vpc_id

Show answer and explanation

Answer: A

A child module's outputs are referenced as module.<name>.<output>.

  • network.vpc_id: The module. prefix is required.
  • module.network.output.vpc_id: There is no output segment.
  • var.network.vpc_id: var refers to input variables.
Question 2

What is the root module?

  1. A.

    The configuration in the working directory where you run Terraform commands.

  2. B.

    The first module published to the public registry.

  3. C.

    A module that has no variables.

  4. D.

    A module stored in the .terraform directory.

Show answer and explanation

Answer: A

Every configuration has a root module, which is the set of .tf files in the main working directory. Modules that it calls are child modules.

  • The first module published to the public registry.: The term is unrelated to publishing order.
  • A module that has no variables.: Root modules can have variables.
  • A module stored in the .terraform directory.: That directory caches downloaded modules and providers.
Question 3

A team wants to share approved modules with versioning and discoverability inside their organisation only. What should they use?

  1. A.

    The public Terraform Registry only.

  2. B.

    A zip file attached to the wiki.

  3. C.

    Copy the module into each repository.

  4. D.

    A private registry, such as the private registry in HCP Terraform.

Show answer and explanation

Answer: D

A private registry hosts internal modules and providers with versioning, so approved modules are easy to find and reuse.

  • The public Terraform Registry only.: Public modules are visible to everyone.
  • A zip file attached to the wiki.: It lacks versioning and discoverability.
  • Copy the module into each repository.: Copies diverge and are hard to update.
Question 4

How do you reference the bucket_arn output for the module instance created from "logs"?

module "storage" {
  source   = "./modules/storage"
  for_each = toset(["logs", "assets"])
  name     = each.key
}
  1. A.

    module.storage["logs"].bucket_arn

  2. B.

    module.storage.logs.bucket_arn

  3. C.

    module.storage.bucket_arn

  4. D.

    module.logs.storage.bucket_arn

Show answer and explanation

Answer: A

Modules support for_each, and each instance is accessed with its key in square brackets.

  • module.storage.logs.bucket_arn: The key must be in brackets.
  • module.storage.bucket_arn: This is ambiguous because there are several instances.
  • module.logs.storage.bucket_arn: The module name comes first.
Question 5

Which of these is a valid local path module source?

  1. A.

    source = "modules/network"

  2. B.

    source = "local::modules/network"

  3. C.

    source = "./modules/network"

  4. D.

    source = "file://modules/network.tf"

Show answer and explanation

Answer: C

Local module paths must begin with ./ or ../ so Terraform doesn't confuse them with registry addresses.

  • source = "modules/network": Without the prefix Terraform treats it as a registry address.
  • source = "local::modules/network": There is no such source scheme.
  • source = "file://modules/network.tf": This isn't the local path syntax for modules.

How ready are you for Terraform Associate (004)?

Take the free readiness check: 15 questions from every exam domain in 20 minutes, with your score per domain.

  • 20 minutes
  • 15 questions
  • Free with an account

More Terraform Associate (004) practice by topic

Back to the Terraform Associate (004) practice test →

Independent practice material written from the official exam guide. Not affiliated with or endorsed by the exam provider.