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
An apply fails after creating three of five resources. What is the state of the three?
- Terraform automatically destroys them
- They remain, and the state records them
- They are marked tainted and hidden from state
- 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.
Which statements about -auto-approve are correct?
- It skips the interactive approval of a freshly generated plan
- It will also carry out destructive changes in that plan
- It is required whenever you apply a saved plan file
- Terraform ignores it when you pass a saved plan
- 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.
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.
