Terraform Associate · Domain 7 of 8 · 9% of the exam

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

  1. Question 1. Which configuration block brings an existing resource under Terraform management as part of a normal plan and apply?

    1. moved
    2. import
    3. removed
    4. data
    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.

  2. Question 2. You have import blocks but haven't written resource blocks yet. Which command can draft the configuration for you?

    1. terraform import -write-config=generated.tf
    2. terraform show -generate-config generated.tf
    3. terraform plan -generate-config-out=generated.tf
    4. terraform init -import-config=generated.tf
    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.

  3. Question 3. What does the terraform import CLI command do?

    1. Writes a resource block for the object and imports it
    2. Imports the resource into state only; you write the resource block
    3. Downloads a published module from the Terraform Registry
    4. Copies existing state from one backend into another
    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.

  4. Question 4. After importing a resource, terraform plan shows changes to it. What does this usually mean?

    1. The import failed and has to be run again
    2. Terraform will destroy and recreate the resource
    3. The provider version is out of date and needs upgrading
    4. The configuration doesn't match the resource's real settings
    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.

  5. Question 5. How can you import many existing resources of the same type with one import block?

    1. Use for_each on the import block
    2. Pass several ids separated by commas
    3. Use count = -1
    4. It isn't possible
    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.

  6. Question 6. Which value goes in the id argument of an import block?

    1. The resource's Terraform address in the configuration
    2. Any unique string you choose for the import
    3. The import ID the provider documents for that resource type
    4. The serial number recorded in the current state file
    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.

  7. Question 7. What should you do with import blocks after a successful apply?

    1. They must be deleted before the next plan
    2. They can stay or be removed; a completed import does nothing more
    3. Convert them into data blocks
    4. Move them into the backend block
    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.

  8. Question 8. Which command shows the current state in a readable form?

    1. terraform show
    2. terraform state pull -pretty
    3. terraform output -all
    4. terraform plan -state
    Show answer

    Answer: A. terraform show

    With a plan file argument, terraform show shows that plan instead.

  9. Question 9. Which command gives a machine-readable view of the state for scripts or policy tools?

    1. terraform state list -json
    2. terraform output -raw
    3. terraform graph -json
    4. terraform show -json
    Show answer

    Answer: D. terraform show -json

    The JSON format is documented and stable, so tools can parse it.

  10. Question 10. Which command prints all output values from the root module?

    1. terraform show -outputs
    2. terraform output
    3. terraform state outputs
    4. terraform get outputs
    Show answer

    Answer: B. terraform output

    terraform output <name> prints one value; sensitive values appear redacted unless requested by name.

  11. Question 11. Which environment variable turns on detailed Terraform logs?

    1. TF_DEBUG=1
    2. TF_VERBOSE=true
    3. TF_LOG=DEBUG
    4. TERRAFORM_LOGS=on
    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.

  12. Question 12. Which environment variable writes Terraform's logs to a file?

    1. TF_LOG_PATH
    2. TF_LOG_FILE
    3. TF_OUTPUT
    4. TF_DATA_DIR
    Show answer

    Answer: A. TF_LOG_PATH

    TF_LOG_PATH only takes effect when logging is enabled with TF_LOG.

  13. Question 13. Which TF_LOG level gives the most detail?

    1. ERROR
    2. INFO
    3. DEBUG
    4. TRACE
    Show answer

    Answer: D. TRACE

    TRACE includes everything, which helps diagnose provider and core issues but can be very large.

  14. Question 14. How can you enable logging for providers only, without Terraform core's logs?

    1. TF_LOG=PROVIDER
    2. TF_LOG_PROVIDER=DEBUG
    3. TF_PROVIDER_DEBUG=1
    4. TF_LOG_CORE=off
    Show answer

    Answer: B. TF_LOG_PROVIDER=DEBUG

    TF_LOG_CORE and TF_LOG_PROVIDER set levels separately. TF_LOG sets both.

  15. Question 15. What does TF_LOG=JSON produce?

    1. A list of resources in JSON
    2. Plan output in JSON
    3. Trace-level logs in JSON format
    4. Only errors in JSON
    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.

  16. Question 16. When is verbose logging most useful?

    1. Debugging provider or core errors that normal output doesn't explain
    2. On every production apply by default, as an audit trail
    3. When formatting configuration files before a commit
    4. When writing validation rules for input variables
    Show answer

    Answer: A. Debugging provider or core errors that normal output doesn't explain

    Logs can contain sensitive data, so share them carefully.

  17. Question 17. Which command downloads the current state from the backend and prints it?

    1. terraform state get
    2. terraform show -remote
    3. terraform state fetch
    4. terraform state pull
    Show answer

    Answer: D. terraform state pull

    It's useful for inspection or backups. terraform state push overwrites remote state and is rarely needed.

  18. Question 18. A provider releases a new major version. What should you do before upgrading?

    1. Delete the lock file and apply the configuration
    2. Read its upgrade guide, update the constraint, and review the plan
    3. Upgrade the Terraform CLI first, then run apply
    4. Remove every resource from state and import them again
    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.