terraform apply: Usage, Options & Common CI Errors
The command that actually changes your infrastructure - run it deliberately.
terraform apply executes the actions proposed by a plan. In CI you apply a saved plan file so the change matches exactly what was reviewed; interactively you pass -auto-approve.
What it does
terraform apply provisions, updates, or destroys resources to match the plan. Given a saved plan file it applies it without prompting; given no plan it generates one and asks for confirmation unless -auto-approve is set.
Common usage
# Apply a reviewed plan (CI pattern - no prompt, exact change)
terraform apply tfplan
# Apply directly, skipping the approval prompt
terraform apply -auto-approve
# Apply with variables and a parallelism cap
terraform apply -var-file=prod.tfvars -parallelism=10 -input=falseCommon error in CI: error creating resource / already exists
Applies commonly fail with "Error: creating EC2 Instance: ... " or "Error: ... already exists" when a resource was created outside Terraform or a prior apply partially succeeded. Fix: import the existing object with terraform import <address> <id> so state knows about it, then re-apply. For partial failures, read the error, fix the root cause (quota, IAM, naming collision), and re-run - Terraform is idempotent and will only finish the unfinished work.
Key options
| Option | Purpose |
|---|---|
| (plan file) | Apply a saved plan exactly |
| -auto-approve | Skip the interactive approval |
| -input=false | Never prompt (required in CI) |
| -parallelism=N | Limit concurrent resource operations |
| -target=ADDR | Apply only specific resources |