Terraform Cheats for Debugging

Reading plan output, fixing state, recovering from broken applies. The terraform commands worth memorising.

Reading plans

Reading the plan before apply is the daily discipline. The surprise is always in the diff; saving the plan and applying only the saved file removes the gap between "what I read" and "what runs."

State surgery

State surgery is the recovery toolkit when reality and state diverge. List, remove, move resources at the state layer without touching the cloud. Always snapshot before cutting.

Import

Import recovers from manual changes by pulling existing cloud resources back into Terraform's state. The trick is making the matching config match exactly, then verifying zero drift before the next apply.