WebMagicInformatica
Terraform Associate (004) practice questions

Terraform Associate (004) practice questions: Maintain infrastructure with Terraform

5 free questions on Maintain infrastructure with Terraform, 8% 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

You need detailed diagnostic output from Terraform and want it written to a file. What should you set?

  1. A.

    Add debug = true to the terraform block.

  2. B.

    Run terraform fmt -debug.

  3. C.

    The TF_LOG environment variable to a level such as DEBUG, and TF_LOG_PATH to the file.

  4. D.

    Delete the .terraform directory.

Show answer and explanation

Answer: C

TF_LOG enables logging at a chosen verbosity, and TF_LOG_PATH sends it to a file.

  • Add debug = true to the terraform block.: No such setting exists.
  • Run terraform fmt -debug.: fmt has no debug option.
  • Delete the .terraform directory.: That removes cached plugins and doesn't produce logs.
Question 2

The team wants to update providers to the newest versions allowed by the constraints in the configuration. Which command does this?

  1. A.

    terraform init -upgrade

  2. B.

    terraform apply -upgrade

  3. C.

    terraform fmt -upgrade

  4. D.

    terraform output -upgrade

Show answer and explanation

Answer: A

terraform init -upgrade ignores selections recorded in the lock file and picks the newest versions that satisfy the constraints, updating the lock file.

  • terraform apply -upgrade: Apply has no upgrade flag.
  • terraform fmt -upgrade: Fmt has no upgrade flag.
  • terraform output -upgrade: Output has no upgrade flag.
Question 3Choose 2

Which TWO commands let you inspect information about infrastructure Terraform is managing? (Choose two.)

  1. A.

    terraform fmt

  2. B.

    terraform show

  3. C.

    terraform init

  4. D.

    terraform login

  5. E.

    terraform state list

Show answer and explanation

Answer: B and E

terraform show prints state (or a saved plan), and terraform state list lists resource addresses in state.

  • terraform fmt: It reformats code.
  • terraform init: It prepares the working directory.
  • terraform login: It stores an API token for HCP Terraform.
Question 4

You need to see all attributes that Terraform has recorded for aws_instance.web. Which command do you use?

  1. A.

    terraform show aws_instance.web --all

  2. B.

    terraform fmt aws_instance.web

  3. C.

    terraform validate aws_instance.web

  4. D.

    terraform state show aws_instance.web

Show answer and explanation

Answer: D

terraform state show <address> prints the recorded attributes of one resource.

  • terraform show aws_instance.web --all: show takes a plan or state file path, not a resource address.
  • terraform fmt aws_instance.web: fmt formats files.
  • terraform validate aws_instance.web: validate checks configuration.
Question 5Choose 2

Which TWO actions are appropriate if a run was interrupted and the state remains locked? (Choose two.)

  1. A.

    Delete the state file.

  2. B.

    Edit the lock file .terraform.lock.hcl.

  3. C.

    Confirm that no other Terraform operation is still running.

  4. D.

    Run terraform destroy.

  5. E.

    Run terraform force-unlock <LOCK_ID>.

Show answer and explanation

Answer: C and E

First verify that nobody else is running an operation, then release the lock with terraform force-unlock and the lock ID.

  • Delete the state file.: This destroys Terraform's records.
  • Edit the lock file .terraform.lock.hcl.: That file tracks provider versions, not state locks.
  • Run terraform destroy.: This would delete the infrastructure.

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.