HashiCorp Terraform Associate (004) · 12% practice allocation

HashiCorp 004: Terraform modules Practice Questions

5 free sample questions from the Terraform modules domain, with answers and explanations. The full 004 bank has 282 questions across 8 domains. Questions are scenario-based and written from the official HashiCorp exam guide.

1.

Which file in a Terraform module is considered the standard location for declaring output blocks that expose values to the calling (root) module?

  • A. outputs.tf✓ Correct
  • B. terraform.tf
  • C. main.tf
  • D. variables.tf
Explanation

Correct: By Terraform convention, outputs.tf is the standard file for declaring all output blocks within a module, improving readability and discoverability. Incorrect: main.tf is the conventional location for resource and data source definitions, not outputs. Incorrect: variables.tf is the conventional location for input variable declarations, not outputs. Incorrect: terraform.tf (or versions.tf) is typically used for the terraform block containing required_providers and version constraints, not outputs.

2.

A module published to the public Terraform Registry displays a 'Verified' badge. What does this badge specifically indicate?

  • A. The module was authored by HashiCorp or by a technology partner that has been vetted by HashiCorp✓ Correct
  • B. The module has achieved a minimum of 1,000 downloads, confirming community trust
  • C. The module has passed a mandatory integration test suite run by the Terraform Registry CI pipeline
  • D. The module's code has been automatically scanned and confirmed free of security vulnerabilities by HashiCorp
Explanation

Correct: The 'Verified' badge on the Terraform Registry indicates that the module is maintained by HashiCorp itself or by an official technology partner (e.g., AWS, Google, Azure) that HashiCorp has reviewed and approved. It is a mark of organizational trust, not automated testing. Incorrect: HashiCorp does not perform automated security vulnerability scanning of module code as the basis for the Verified badge. Incorrect: Download counts do not factor into the Verified badge; a module could have millions of downloads and remain a community module. Incorrect: There is no mandatory CI integration test pipeline run by the Registry that gates the Verified status; the badge is based on the identity and vetting of the publishing organization.

3.

A child module declares the following output:

output "instance_details" {
  value = {
    id         = aws_instance.app.id
    private_ip = aws_instance.app.private_ip
  }
  sensitive = true
}

A root module calls this child module (labeled "app") and tries to use module.app.instance_details.private_ip as the value of another resource argument. Which statements are TRUE about this behavior? (Select TWO)

  • A. Because sensitive = true is set on the output, Terraform will refuse to allow the value to be used in any other resource
  • B. Terraform will throw an error because sensitive outputs cannot be referenced by attribute traversal
  • C. The reference module.app.instance_details.private_ip is valid and Terraform will resolve the nested attribute correctly✓ Correct
  • D. The sensitive flag on a module output only affects CLI display; it has no effect on downstream resource arguments
  • E. The value passed to the other resource will be treated as sensitive and will be redacted in plan/apply output✓ Correct
Explanation

Correct: Accessing a nested attribute of a module output via module.<LABEL>.<OUTPUT>.<ATTRIBUTE> is fully supported when the output value is an object/map; Terraform resolves the traversal correctly. Correct: When a value originates from a sensitive output, Terraform propagates the sensitivity to any resource argument that uses it, redacting it in terraform plan and terraform apply output with '(sensitive value)'. Incorrect: Sensitive outputs can absolutely be referenced and used downstream; sensitive = true only controls display redaction, not usage restrictions. Incorrect: Terraform does not throw an error for attribute traversal on sensitive object outputs; the traversal is valid. Incorrect: The sensitive flag does affect downstream resource arguments by marking their values as sensitive too — it is not solely a display concern limited to the output itself.

4.

A developer writes the following module call in their root configuration:

module "app_server" {
  source = "./modules/compute"

  instance_type = "t3.medium"
  ami_id        = "ami-0abcdef1234567890"
}

After the module is applied, the developer needs to use the module's public_ip output in another resource. Which expression correctly references that output?

  • A. app_server.module.public_ip
  • B. module.app_server.public_ip✓ Correct
  • C. module.compute.public_ip
  • D. module.app_server.outputs.public_ip
Explanation

Correct: Module outputs are referenced with the syntax module.<MODULE_LABEL>.<OUTPUT_NAME>, where the label matches the name given in the module block — in this case app_server. Incorrect: There is no .outputs. segment in the reference path; Terraform does not use that intermediate keyword. Incorrect: module.compute would reference a module labeled compute, but the module block is labeled app_server — the label, not the source directory name, is used. Incorrect: app_server.module.public_ip reverses the syntax and is not valid HCL.

5.

A Terraform module is sourced from a Git repository. A team wants to pin the module to a specific commit SHA for stability. Which source string correctly accomplishes this?

  • A. source = "github.com/example/modules//compute?commit=a1b2c3d4"
  • B. source = "https://github.com/example/modules/archive/a1b2c3d4.zip"
  • C. source = "git::https://github.com/example/modules.git" version = "a1b2c3d4"
  • D. source = "git::https://github.com/example/modules.git?ref=a1b2c3d4"✓ Correct
Explanation

Correct: For Git-based module sources, Terraform supports a ref query parameter to specify a branch, tag, or commit SHA. The format git::https://<REPO>.git?ref=<SHA> correctly pins to a specific commit. Incorrect: The // double-slash separator is used to specify a subdirectory within a repository, and ?commit= is not a recognized query parameter — the correct parameter is ?ref=. Incorrect: The version argument in a module block is only valid for Terraform Registry sources, not for Git sources; mixing a Git source URL with a separate version argument is invalid. Incorrect: Downloading a ZIP archive via HTTPS is a valid source type, but it references the GitHub auto-generated archive URL — while it could work, it does not use the Git ref mechanism and would not be considered a standard way to pin by commit SHA.

Test yourself across every 004 domain

The free 004 practice test mixes about 20 questions weighted like the exam. The full 282-question bank adds instant grading, flashcards and a timed mock exam.

Study this domain

Terraform modules study guide (004) →

Other 004 domains

← All HashiCorp Terraform Associate study resources