Terraform Associate Domain 7: Maintain Infrastructure with Terraform
18 free practice questions for Maintain Infrastructure with Terraform in the HashiCorp Certified: Terraform Associate (004) exam. Try each question first, then open "Show answer" for the correct option and explanation.
Maintain Infrastructure with Terraform practice questions
-
Question 1. Which configuration block brings an existing resource under Terraform management as part of a normal plan and apply?
Show answer
Answer: B. import
An import block sets to (the resource address) and id (the provider's import ID), and the import is reviewed in the plan.
-
Question 2. You have import blocks but haven't written resource blocks yet. Which command can draft the configuration for you?
Show answer
Answer: C. terraform plan -generate-config-out=generated.tf
Terraform writes resource blocks from the imported objects. Review and tidy the generated code before applying.
-
Question 3. What does the terraform import CLI command do?
Show answer
Answer: B. Imports the resource into state only; you write the resource block
The CLI command changes state right away, without a plan. Import blocks are the reviewable alternative.
-
Question 4. After importing a resource, terraform plan shows changes to it. What does this usually mean?
Show answer
Answer: D. The configuration doesn't match the resource's real settings
Adjust the configuration until the plan shows no changes, unless you really want to change the resource.
-
Question 5. How can you import many existing resources of the same type with one import block?
Show answer
Answer: A. Use for_each on the import block
Import blocks support for_each, with to and id built from each.key and each.value.
-
Question 6. Which value goes in the id argument of an import block?
Show answer
Answer: C. The import ID the provider documents for that resource type
It varies by resource. A bucket might use its name, while a route might combine several IDs.
-
Question 7. What should you do with import blocks after a successful apply?
Show answer
Answer: B. They can stay or be removed; a completed import does nothing more
Import is idempotent, but many teams remove them once done to keep code tidy.
-
Question 8. Which command shows the current state in a readable form?
Show answer
Answer: A. terraform show
With a plan file argument, terraform show shows that plan instead.
-
Question 9. Which command gives a machine-readable view of the state for scripts or policy tools?
Show answer
Answer: D. terraform show -json
The JSON format is documented and stable, so tools can parse it.
-
Question 10. Which command prints all output values from the root module?
Show answer
Answer: B. terraform output
terraform output <name> prints one value; sensitive values appear redacted unless requested by name.
-
Question 11. Which environment variable turns on detailed Terraform logs?
Show answer
Answer: C. TF_LOG=DEBUG
Levels are TRACE, DEBUG, INFO, WARN, and ERROR. Logs go to stderr unless TF_LOG_PATH is set.
-
Question 12. Which environment variable writes Terraform's logs to a file?
Show answer
Answer: A. TF_LOG_PATH
TF_LOG_PATH only takes effect when logging is enabled with TF_LOG.
-
Question 13. Which TF_LOG level gives the most detail?
Show answer
Answer: D. TRACE
TRACE includes everything, which helps diagnose provider and core issues but can be very large.
-
Question 14. How can you enable logging for providers only, without Terraform core's logs?
Show answer
Answer: B. TF_LOG_PROVIDER=DEBUG
TF_LOG_CORE and TF_LOG_PROVIDER set levels separately. TF_LOG sets both.
-
Question 15. What does TF_LOG=JSON produce?
Show answer
Answer: C. Trace-level logs in JSON format
JSON logs are easier to filter with tools. The format isn't covered by compatibility promises.
-
Question 16. When is verbose logging most useful?
Show answer
Answer: A. Debugging provider or core errors that normal output doesn't explain
Logs can contain sensitive data, so share them carefully.
-
Question 17. Which command downloads the current state from the backend and prints it?
Show answer
Answer: D. terraform state pull
It's useful for inspection or backups. terraform state push overwrites remote state and is rarely needed.
-
Question 18. A provider releases a new major version. What should you do before upgrading?
Show answer
Answer: B. Read its upgrade guide, update the constraint, and review the plan
Major versions can change resource schemas. init -upgrade selects the new version, and the plan shows its effect.
HashiCorp, Terraform, and HCP Terraform are trademarks of HashiCorp, Inc. These questions are original study material, not questions from the real exam.