Module 3: Core Terraform Workflow

Lesson 3.5: Applying Changes

Plain language

terraform apply executes the changes.

Usage Behavior
terraform apply Creates a fresh plan, shows it, and prompts for yes
terraform apply -auto-approve Creates a fresh plan and applies it without prompting
terraform apply tfplan Applies the saved plan exactly, with no prompt, because you approved it when you saved it
terraform apply -replace=ADDR Plans a forced replacement and applies it
terraform apply -refresh-only Updates state to match reality, without changing infrastructure

Under the hood

  • Stale saved plans. If state changed after you saved a plan (for example, someone else applied), applying the saved plan fails with an error saying the plan is stale. Create a new plan.
  • No automatic rollback. Resources run in parallel when they don't depend on each other. If one fails, Terraform stops starting dependent work, and resources that already succeeded stay created and are recorded in state. Fix the cause and run apply again.
  • Tainted resources. A resource that was created but failed during creation (for example, a provisioner failed) is marked tainted in state. The next plan replaces it.
  • State writes. Apply writes state as it goes, and the state serial increments.