Safe Plan-Apply Workflow
Review Terraform plans carefully and use targeted applies to minimize blast radius when making infrastructure changes.
Prerequisites
- -Terraform installed
Steps
Run terraform plan and save to file
Generate an execution plan and save it as a binary file for later review or application.
Always save the plan to a file. This ensures the exact reviewed plan is what gets applied.
Review the plan in detail
Display the saved plan in human-readable format to review every change before applying.
Apply only the saved plan
Apply the exact saved plan without re-computing changes, ensuring consistency with what was reviewed.
Never run 'terraform apply' without a saved plan in production. It recomputes changes which may differ from what you reviewed.
Target a specific resource for apply
Apply changes to only a specific resource when you want to limit the blast radius.
Targeted applies are useful for debugging but should not be the norm. Terraform warns about this for a reason.
Use detailed exit codes in CI
Use -detailed-exitcode to programmatically determine if changes are pending (exit 2) or clean (exit 0).
Exit code 0 means no changes, 1 means error, 2 means changes pending. Useful for CI/CD decision logic.
Full Script
FAQ
Discussion
Loading comments...