WebMagicInformatica
Terraform Associate (004) practice questions

Terraform Associate (004) practice questions: Core Terraform workflow

5 free questions on Core Terraform workflow, 12% 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

A pipeline must apply exactly the changes that were reviewed earlier in a separate job. Which approach achieves this?

  1. A.

    Run terraform apply -auto-approve in the second job without a plan file.

  2. B.

    Run terraform fmt in both jobs.

  3. C.

    Run terraform validate before apply.

  4. D.

    Run terraform plan -out=tfplan in the first job and terraform apply tfplan in the second.

Show answer and explanation

Answer: D

Saving a plan file and applying it makes Terraform execute exactly that plan, so the reviewed changes are applied (or Terraform errors if state changed).

  • Run terraform apply -auto-approve in the second job without a plan file.: Terraform would create a new plan that may differ from the reviewed one.
  • Run terraform fmt in both jobs.: Formatting does not preserve a plan.
  • Run terraform validate before apply.: Validation checks syntax and not the actual change set.
Question 2

Which command is equivalent to terraform apply -destroy?

  1. A.

    terraform plan -destroy -out

  2. B.

    terraform state rm

  3. C.

    terraform destroy

  4. D.

    terraform init -reconfigure

Show answer and explanation

Answer: C

terraform destroy creates a plan that destroys all objects managed by the configuration, then asks for confirmation.

  • terraform plan -destroy -out: This only creates a saved destruction plan and does not execute it.
  • terraform state rm: It removes objects from state without destroying real resources.
  • terraform init -reconfigure: It reinitialises the backend, and does not delete resources.
Question 3

A teammate runs the command below. What is the effect?

terraform apply -target=aws_instance.web
  1. A.

    Terraform destroys aws_instance.web.

  2. B.

    Terraform plans and applies only that resource and the resources it depends on, which is meant for exceptional situations.

  3. C.

    Terraform applies all resources except aws_instance.web.

  4. D.

    Terraform imports aws_instance.web into state.

Show answer and explanation

Answer: B

Resource targeting limits the operation to the chosen resource and its dependencies. HashiCorp advises using it only for exceptional cases because it can leave other changes unapplied.

  • Terraform destroys aws_instance.web.: That requires -destroy or the destroy command.
  • Terraform applies all resources except aws_instance.web.: -target includes, not excludes.
  • Terraform imports aws_instance.web into state.: Import uses import blocks or terraform import.
Question 4

You want to format all .tf files in the current directory and all its subdirectories. Which command does this?

  1. A.

    terraform fmt -deep

  2. B.

    terraform fmt -recursive

  3. C.

    terraform validate -recursive

  4. D.

    terraform init -format

Show answer and explanation

Answer: B

terraform fmt formats only the current directory unless -recursive is used.

  • terraform fmt -deep: There is no such flag.
  • terraform validate -recursive: Validate checks, it doesn't format.
  • terraform init -format: init has no format option.
Question 5

Which command outputs a visual representation of the dependency graph of the configuration in DOT format?

  1. A.

    terraform show -graph

  2. B.

    terraform output -dot

  3. C.

    terraform graph

  4. D.

    terraform fmt -graph

Show answer and explanation

Answer: C

terraform graph generates a DOT description of the dependency graph that tools such as Graphviz can render.

  • terraform show -graph: show has no graph option.
  • terraform output -dot: output prints output values.
  • terraform fmt -graph: fmt only formats code.

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.