Bitzu

Terraform Associate 004 ยท Core Terraform workflow

terraform apply

Apply with and without a saved plan, confirmation prompt, -auto-approve, partial failure and state after errors, idempotence (3e).

Key points

  • No plan file: apply builds a new plan, shows it, waits for yes.
  • terraform apply FILE: no prompt, the saved plan counts as approval; no planning options.
  • auto-approve: skips the prompt for a fresh plan, including destructive changes.
  • On error: saves state of what completed, unlocks, exits; no rollback, fix the cause and apply again.
  • Unchanged configuration: re-applying changes nothing (idempotence).

Source: https://developer.hashicorp.com/terraform/cli/commands/apply

Practice questions

Single choice

An apply fails after creating three of five resources. What is the state of the three?

  1. Terraform automatically destroys them
  2. They remain, and the state records them
  3. They are marked tainted and hidden from state
  4. They are rolled back when the lock is released
Show answer

Answer: B. They remain, and the state records them

Terraform saves state for the completed work and does not roll back. You fix the problem and apply again.

Select all that apply

Which statements about -auto-approve are correct?

  1. It skips the interactive approval of a freshly generated plan
  2. It will also carry out destructive changes in that plan
  3. It is required whenever you apply a saved plan file
  4. Terraform ignores it when you pass a saved plan
  5. It rolls back the run if any resource fails
Show answer

Answer: A. It skips the interactive approval of a freshly generated plan, B. It will also carry out destructive changes in that plan, D. Terraform ignores it when you pass a saved plan

-auto-approve removes the prompt for a new plan, including deletes, and is ignored for saved plans. It is not required for saved plans and never rolls anything back.

True or false

If an apply fails halfway, Terraform automatically rolls the infrastructure back to its previous condition.

Show answer

Answer: False

False. Terraform does not roll back a partially completed apply; completed changes stay and are recorded in state.

Practice 8 questions on this topic in Bitzu

Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.

Download on the App StoreGet it on Google Play

More Terraform Associate 004 topics in this module