Skip to main content
After you prepare configuration files, initialize the working directory, and review a plan to see what Terraform intends to do, the final step is terraform apply.
A purple infographic illustrating the Terraform workflow with four steps—Write Configuration (HCL), Initialize, Plan, and Apply—shown as connected purple boxes. A red map-pin labeled "You Are Here" marks the Apply step.
terraform apply is the execution phase: Terraform calls provider APIs to create, update, or destroy resources so the real-world infrastructure matches the desired state defined in your configuration. Everything before this stage is preparation and preview — apply is where your infrastructure-as-code becomes real infrastructure. This guide explains how apply works, what happens under the hood, the different ways to run it, and best practices for using it safely and reliably.

What terraform apply does

  • Terraform reconciles your declared configuration with the current real-world state.
  • Before changing anything, apply effectively runs a plan: it refreshes state, compares current vs desired states, and summarizes proposed changes.
  • By default, Terraform prompts for interactive confirmation after showing the plan. This gives you a final opportunity to review changes before Terraform performs any API operations.

Interactive apply and prompts

Typical interactive workflow:
  1. Run terraform apply.
  2. Terraform shows the planned changes.
  3. You must confirm by typing yes to proceed.
Use interactive apply when you want a manual review step immediately before execution.

When to run apply

Run terraform apply when you want Terraform to:
  • Create new resources,
  • Modify existing resources, or
  • Destroy resources you no longer need.
Common use cases: scaling infrastructure, updating configurations, or tearing down environments.

Operational behavior during apply

  • State locking: Terraform locks the state file during apply to prevent concurrent operations from corrupting the state. Locks are released when the apply completes or fails.
  • Incremental state updates: After each resource operation (create/update/delete), Terraform updates the state immediately. If apply fails partway, resources already completed remain recorded in state.
  • No automatic rollback: Terraform does not automatically roll back completed resource changes when a later operation fails. If partial work completes, you must resolve the error, continue, or destroy/recreate resources as needed.
  • Dependency graph and parallelism: Terraform respects the resource dependency graph and applies changes in the correct order. Independent resources may be created or destroyed in parallel to improve performance.
  • Long-running operations: Some provider operations (databases, complex networking) may take time. Terraform waits on the provider’s API responses and may appear to be paused while operations complete.
A purple presentation slide explaining the Terraform command "terraform apply," which provisions real infrastructure from your configuration. On the right is a photo of several people sitting and working on laptops.

Ways to run terraform apply

Use different invocation modes depending on your workflow and automation requirements. Examples:
For CI/CD pipelines use -input=false to disable interactive prompts. Combine it with -auto-approve only when you have reviewed and accepted the plan in advance (for example, by applying a saved plan approved elsewhere).

Cautions about non-interactive apply

  • -auto-approve skips the confirmation and proceeds immediately after showing the plan. This can be dangerous for destructive or high-impact changes—avoid using it for manual production work.
  • -input=false prevents Terraform from prompting for input and is required in many automation environments to avoid hanging builds or pipelines.
  • When using automation, prefer workflows that generate a plan, have it reviewed/approved, and then apply the saved plan file to guarantee the exact changes are executed.

Best practices for terraform apply

  • Review the plan before applying: For complex or production changes, run terraform plan separately and inspect the output carefully.
  • Confirm context: Ensure you are in the correct directory, backend, and workspace before applying.
  • Use non-production environments: Test changes in dev/staging before applying to production.
  • Watch the plan output: Don’t habitually confirm without reading; check for unexpected deletions or replacements.
  • Be patient: Some resources can take time to provision. Monitor provider operations and logs as needed.
  • Verify after apply: Confirm resources are provisioned and functioning as expected; run integration or smoke tests where applicable.
  • Record changes: Commit configuration updates with clear messages and update runbooks or operational documentation for significant changes.
The image shows a purple infographic titled "Best Practices for terraform apply" with numbered tips for before, during, and after applying changes. On the right, a person is working on a laptop and large monitor displaying code.
If you make significant changes, document them in commit messages and runbooks so teammates can understand why infrastructure changed and how to reproduce or revert it if necessary. That’s the apply stage — the execution phase of Terraform where your planned changes are enacted against real infrastructure.

Watch Video