HashiCorp Terraform Associate (004) · 12% practice allocation

HashiCorp 004: Maintain infrastructure with Terraform Practice Questions

5 free sample questions from the Maintain infrastructure with Terraform 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 command lists the addresses of every resource currently tracked in the Terraform state, without showing their attribute values?

  • A. terraform state show
  • B. terraform providers
  • C. terraform output
  • D. terraform state list✓ Correct
Explanation

Option D is correct. terraform state list prints just the resource addresses in state (optionally filtered by a pattern, such as a module path or resource type), giving a quick inventory without the detail of individual attributes. Option A is incorrect — terraform state show requires one specific resource address and prints its full attribute detail, not a listing of all addresses. Option C is incorrect — terraform output prints declared output values, unrelated to the inventory of managed resources. Option B is incorrect — terraform providers reports which provider plugins the configuration requires, not which resources are in state.

2.

A configuration is being split into two smaller root modules. One resource, aws_iam_role.shared, needs to keep its existing real-world identity but should be tracked in the new module's state file instead of the old one, without Terraform destroying and recreating the role. Which command is designed for this?

  • A. Delete the resource block from the old module and add it to the new one, then run terraform apply in both
  • B. terraform taint aws_iam_role.shared in the old module so the new module recreates it fresh
  • C. terraform state mv -state-out=<new-state-path> aws_iam_role.shared aws_iam_role.shared✓ Correct
  • D. terraform state rm aws_iam_role.shared in the old module, followed by terraform import in the new one using the role's ARN
Explanation

Option C is correct. terraform state mv with -state-out moves a state entry directly from one state file to another (or into a different module), preserving the tracked resource's identity without any provider API calls — the real IAM role is untouched throughout. Option D would technically work end-to-end but is the less direct, riskier path when a single-command move is available — removing from state and re-importing means re-typing the exact resource ID and briefly leaves the role completely untracked by Terraform. Option B is incorrect and destructive — tainting marks a resource for destroy-and-recreate on the next apply, which is the opposite of preserving the existing role. Option A is incorrect — simply moving the resource block between configs without a corresponding state operation causes the old module to plan a destroy and the new module to plan a create, losing the resource's existing identity in the process.

3.

A release engineer runs terraform plan -out=tfplan and wants to review exactly what that saved plan file contains before anyone applies it, in a readable format rather than raw binary. Which command should they run?

  • A. terraform plan -detailed-exitcode tfplan
  • B. terraform show tfplan✓ Correct
  • C. terraform validate tfplan
  • D. terraform state show tfplan
Explanation

Option B is correct. terraform show also accepts a saved plan file as an argument and renders its proposed changes in human-readable form (it can additionally emit JSON with -json for tooling). Option D is incorrect — terraform state show takes a resource address from the current state, not a plan file, and would error on a plan file path. Option A is incorrect — -detailed-exitcode is a flag for terraform plan that changes its exit code semantics; it is not how you render a saved plan's contents, and this isn't valid plan syntax. Option C is incorrect — terraform validate checks configuration for syntax errors; it does not accept or display a plan file.

4.

Which TF_LOG value produces the MOST verbose output, useful when troubleshooting a suspected provider plugin bug?

  • A. WARN
  • B. ERROR
  • C. TRACE✓ Correct
  • D. INFO
Explanation

Option C is correct. TRACE is the most detailed logging level Terraform supports, capturing fine-grained internal detail including provider plugin communication — the right choice when diagnosing a suspected bug deep in a provider's behavior. Option B is incorrect — ERROR is the least verbose level, showing only failures. Option A is incorrect — WARN shows errors plus warnings, still far less detail than TRACE. Option D is incorrect — INFO is more verbose than WARN/ERROR but considerably less detailed than TRACE, and would likely omit the low-level plugin communication needed to diagnose a provider issue.

5.

An operator runs terraform state list and sees module.network.aws_subnet.private["east"] among dozens of other addresses. They want to inspect only that resource's current attributes as recorded in state. What should they do next?

  • A. Run terraform state pull | grep east and rely on the raw JSON
  • B. Run terraform state show 'module.network.aws_subnet.private["east"]'✓ Correct
  • C. Run terraform import module.network.aws_subnet.private["east"] to refresh its details
  • D. Run terraform show and manually scroll through the entire output to find that resource
  • E. Run terraform state list module.network.aws_subnet.private again with a -detailed flag
Explanation

Option B is correct. terraform state show <address> takes the exact resource address (module path, resource type, name, and any index/key) and prints just that resource's attributes as recorded in state — quoting is needed here because the address contains brackets and a string key. Option E is incorrect — terraform state list has no -detailed flag, and it only ever prints addresses, not attributes. Option D is technically possible but is not the best answer — it works but is far less direct than targeting the resource by address, which is exactly what state show is for. Option A is a real but clumsy workaround — terraform state pull dumps raw state JSON to stdout, which is unstructured for a human to read reliably by grepping, unlike the purpose-built state show command. Option C is incorrect and risky — terraform import is for attaching an unmanaged resource to state; running it against a resource that is already tracked is not the intended read-only inspection step and can produce confusing errors.

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

Maintain infrastructure with Terraform study guide (004) →

Other 004 domains

← All HashiCorp Terraform Associate study resources