Terraform Associate · Domain 3 of 8 · 15% of the exam

Terraform Associate Domain 3: Core Terraform Workflow

30 free practice questions for Core Terraform Workflow in the HashiCorp Certified: Terraform Associate (004) exam. Try each question first, then open "Show answer" for the correct option and explanation.

Core Terraform Workflow practice questions

  1. Question 1. What is the core Terraform workflow?

    1. Init, destroy, apply
    2. Write, plan, apply
    3. Plan, write, import
    4. Apply, test, plan
    Show answer

    Answer: B. Write, plan, apply

    You write configuration, review the plan, then apply it. init comes first in a new working directory.

  2. Question 2. Which command must you run first in a new working directory before plan or apply?

    1. terraform validate
    2. terraform fmt
    3. terraform init
    4. terraform get
    Show answer

    Answer: C. terraform init

    init prepares the directory so later commands can run.

  3. Question 3. What does terraform init do?

    1. Installs providers and modules and sets up the backend
    2. Creates every resource in the configuration
    3. Formats all .tf files
    4. Checks the cloud for drifted resources
    Show answer

    Answer: A. Installs providers and modules and sets up the backend

    It's safe to run init repeatedly; it won't change infrastructure.

  4. Question 4. When do you need to run terraform init again in an existing directory?

    1. Before every terraform plan, even with no changes
    2. Only when the value of an input variable changes
    3. After each successful terraform apply
    4. After adding a provider or module, or changing the backend
    Show answer

    Answer: D. After adding a provider or module, or changing the backend

    New providers and modules must be installed, and backend changes must be initialized, before plan works.

  5. Question 5. You changed the backend configuration and want to copy the existing state to the new backend. Which command does this?

    1. terraform init -reconfigure
    2. terraform init -migrate-state
    3. terraform state push
    4. terraform apply -backend
    Show answer

    Answer: B. terraform init -migrate-state

    -migrate-state copies state to the new backend. -reconfigure ignores the old configuration and doesn't migrate state.

  6. Question 6. What does terraform validate check?

    1. Syntax and internal consistency, without contacting remote services
    2. Whether the cloud has quota for every resource
    3. Whether the plan matches real infrastructure
    4. Formatting of every file
    Show answer

    Answer: A. Syntax and internal consistency, without contacting remote services

    It catches errors like wrong argument names or types early. It doesn't check real-world things such as whether a name is already taken.

  7. Question 7. Can terraform validate run in a directory that hasn't been initialized?

    1. Yes, because it never needs any provider schemas
    2. Only when it's run together with -auto-approve
    3. No; init must install providers so it can check resource arguments
    4. Only when the configuration sets a remote backend
    Show answer

    Answer: C. No; init must install providers so it can check resource arguments

    validate needs the provider schemas. In CI, terraform init -backend=false is a common way to prepare without touching state.

  8. Question 8. What does terraform fmt do?

    1. Validates resource arguments against provider schemas
    2. Rewrites configuration files into the standard style
    3. Removes unused variables and outputs from the files
    4. Converts HCL configuration files into the JSON format
    Show answer

    Answer: B. Rewrites configuration files into the standard style

    fmt fixes indentation and alignment. Run it before committing so diffs stay clean.

  9. Question 9. In CI, which command fails if any file in the directory tree isn't formatted, without changing files?

    1. terraform validate -format
    2. terraform fmt -write
    3. terraform plan -fmt
    4. terraform fmt -check -recursive
    Show answer

    Answer: D. terraform fmt -check -recursive

    -check exits non-zero if changes are needed, and -recursive includes subdirectories.

  10. Question 10. What does terraform plan do?

    1. Compares configuration with state and reality and proposes changes
    2. Applies changes but asks before each resource
    3. Downloads the latest provider versions
    4. Creates a backup of all resources
    Show answer

    Answer: A. Compares configuration with state and reality and proposes changes

    plan refreshes state, compares it with the configuration, and shows what would be created, updated, replaced, or destroyed.

  11. Question 11. Which command saves a plan to a file so the same plan can be applied later?

    1. terraform plan > tfplan
    2. terraform plan -save tfplan
    3. terraform plan -out=tfplan
    4. terraform show -out=tfplan
    Show answer

    Answer: C. terraform plan -out=tfplan

    A saved plan is binary and should be treated as sensitive, since it can contain secret values.

  12. Question 12. What happens when you run terraform apply tfplan with a saved plan?

    1. It creates a new plan and asks for approval
    2. It applies exactly the saved plan without asking again
    3. It only shows the plan without applying
    4. It refuses unless -auto-approve is set
    Show answer

    Answer: B. It applies exactly the saved plan without asking again

    The approval happened when the plan was reviewed. If state changed since, Terraform rejects the stale plan.

  13. Question 13. In plan output, what does the symbol -/+ mean for a resource?

    1. It will be updated in place without being replaced
    2. It will be read as a data source during the apply
    3. It will be removed from state but keep running
    4. It will be replaced: destroyed, then created
    Show answer

    Answer: D. It will be replaced: destroyed, then created

    Replacement happens when a changed argument can't be updated in place. With create_before_destroy, the symbol is +/-.

  14. Question 14. A resource in plan output is marked with a tilde (~). What will Terraform do to it?

    1. Update it in place
    2. Destroy it
    3. Create it
    4. Import it
    Show answer

    Answer: A. Update it in place

    ~ marks an in-place update. + means create and - means destroy.

  15. Question 15. What happens when you run terraform apply without a saved plan file?

    1. It applies immediately with no review
    2. It fails because a plan file is required
    3. It creates a plan, shows it, and asks for confirmation
    4. It only refreshes state
    Show answer

    Answer: C. It creates a plan, shows it, and asks for confirmation

    Type yes to proceed. Anything else cancels.

  16. Question 16. Which option makes terraform apply skip the interactive approval?

    1. -yes
    2. -auto-approve
    3. -force
    4. -no-confirm
    Show answer

    Answer: B. -auto-approve

    It's used in automation, ideally only after a reviewed plan, for example by applying a saved plan file.

  17. Question 17. Which command destroys all resources managed by the current configuration?

    1. terraform delete
    2. terraform remove -all
    3. terraform state rm -all
    4. terraform destroy
    Show answer

    Answer: D. terraform destroy

    destroy shows a plan of everything to delete and asks for confirmation.

  18. Question 18. Which command previews what terraform destroy would remove, without destroying anything?

    1. terraform plan -destroy
    2. terraform destroy -preview
    3. terraform show -destroy
    4. terraform validate -destroy
    Show answer

    Answer: A. terraform plan -destroy

    terraform destroy is an alias for terraform apply -destroy, and plan -destroy shows the same plan without applying.

  19. Question 19. A VM is unhealthy, and you want Terraform to recreate just that resource. Which command is recommended?

    1. terraform taint aws_instance.web
    2. terraform destroy && terraform apply
    3. terraform apply -replace=aws_instance.web
    4. terraform state rm aws_instance.web
    Show answer

    Answer: C. terraform apply -replace=aws_instance.web

    -replace plans a replacement in one reviewed step. terraform taint is deprecated in its favour.

  20. Question 20. When should you use the -target option?

    1. For every apply that runs against production
    2. Only in exceptional cases, such as recovering from errors
    3. To speed up all plans in large configurations
    4. To select which workspace a command should use
    Show answer

    Answer: B. Only in exceptional cases, such as recovering from errors

    Targeting applies part of the configuration and can leave the rest out of sync. Splitting large configurations is the better long-term fix.

  21. Question 21. How do you set the variable region on the command line?

    1. terraform plan --region us-west-2
    2. terraform plan -set region=us-west-2
    3. terraform plan -env region=us-west-2
    4. terraform plan -var="region=us-west-2"
    Show answer

    Answer: D. terraform plan -var="region=us-west-2"

    -var can be repeated. For many values, use -var-file instead.

  22. Question 22. How do you load variable values from prod.tfvars, which isn't loaded automatically?

    1. terraform plan -var-file=prod.tfvars
    2. terraform plan -config=prod.tfvars
    3. terraform plan -input=prod.tfvars
    4. terraform plan -vars prod.tfvars
    Show answer

    Answer: A. terraform plan -var-file=prod.tfvars

    terraform.tfvars and *.auto.tfvars are loaded automatically; other files need -var-file.

  23. Question 23. With terraform plan -detailed-exitcode, what does exit code 2 mean?

    1. The plan failed with an error
    2. There are no changes
    3. The plan succeeded and changes are present
    4. The state is locked
    Show answer

    Answer: C. The plan succeeded and changes are present

    0 means no changes, 1 means an error, and 2 means changes are pending. CI jobs use it for drift checks.

  24. Question 24. Which command shows a saved plan file in a readable form?

    1. terraform output tfplan
    2. terraform show tfplan
    3. terraform plan -read tfplan
    4. terraform console tfplan
    Show answer

    Answer: B. terraform show tfplan

    Add -json for machine-readable output, for example to feed policy tools.

  25. Question 25. An apply fails halfway through. What is true of the resources created before the error?

    1. They are destroyed automatically by Terraform
    2. They exist in the cloud but aren't recorded anywhere
    3. Terraform rolls back the whole apply to the start
    4. They are recorded in state, so fix the error and apply again
    Show answer

    Answer: D. They are recorded in state, so fix the error and apply again

    Terraform doesn't roll back. The next plan shows only the remaining work.

  26. Question 26. What is terraform console for?

    1. Trying out expressions and functions interactively
    2. Opening a shell on a managed VM
    3. Editing state in place
    4. Streaming logs from HCP Terraform
    Show answer

    Answer: A. Trying out expressions and functions interactively

    It evaluates expressions against the current configuration and state, which helps when writing for expressions or function calls.

  27. Question 27. What does terraform graph output?

    1. A chart of cloud costs over time
    2. A list of state versions
    3. The dependency graph in DOT format
    4. A map of resource regions
    Show answer

    Answer: C. The dependency graph in DOT format

    The DOT output can be rendered with Graphviz to inspect dependencies.

  28. Question 28. By default, how many resource operations does Terraform run at the same time?

    1. 1
    2. 10
    3. 50
    4. Unlimited
    Show answer

    Answer: B. 10

    -parallelism=n changes it, for example to stay under an API's rate limits.

  29. Question 29. Does terraform destroy delete cloud resources that Terraform doesn't track in its state?

    1. Yes, everything in the account is removed
    2. Only resources with matching tags
    3. Yes, if -force is set
    4. No, it only destroys resources recorded in state
    Show answer

    Answer: D. No, it only destroys resources recorded in state

    Terraform only acts on what it manages. Resources made by hand are untouched.

  30. Question 30. You delete a resource block from the configuration and run terraform apply. What does Terraform plan to do?

    1. Destroy that resource
    2. Leave it running but unmanaged
    3. Fail with an error
    4. Recreate it from state
    Show answer

    Answer: A. Destroy that resource

    The resource is still in state but no longer in configuration, so Terraform plans to destroy it. A removed block can forget it instead.

HashiCorp, Terraform, and HCP Terraform are trademarks of HashiCorp, Inc. These questions are original study material, not questions from the real exam.