About the Terraform cheat sheet
Terraform's workflow is init, plan, apply, and nearly every problem worth knowing about lives in the state file rather than the configuration. State records what Terraform believes it created, and the gap between that belief and reality is where incidents come from.
Read plans properly. The symbols matter — create, destroy, update in place, and replace are meaningfully different, and a replace on a database or a load balancer is a destructive operation wearing a routine label. Anyone who applies without reading which resources are being replaced will eventually delete something they did not intend to.
The state operations are worth learning before you need them under pressure. Importing existing infrastructure, moving a resource's address after a refactor, and removing something from state without destroying it are the three that come up most, and all three are far less frightening when practised on something unimportant first.
Frequently asked questions
How do I bring existing infrastructure under Terraform?
Write the resource configuration first, then import the real resource into that address, then run a plan and expect it to be empty. A non-empty plan means your configuration does not match reality — adjust the configuration, not the infrastructure. Import blocks let you express this in code rather than as a one-off command, which leaves a reviewable record.
I renamed a resource and Terraform wants to destroy and recreate it. Why?
Terraform tracks resources by address, so renaming looks like deleting one resource and creating another. Use a moved block to tell Terraform the address changed, and the plan becomes a no-op. This is the correct way to refactor, and it is reviewable, unlike a manual state move.
How do I stop managing a resource without deleting it?
Remove it from state rather than removing it from configuration and applying. Deleting the configuration block tells Terraform to destroy the resource; removing from state tells Terraform to forget it while leaving it running. Confirm with a plan afterwards that nothing else is affected.
What is the safest way to handle state locking?
Use a backend that supports locking and never disable it to get past an error. A stuck lock usually means a previous run was interrupted; force-unlock exists for that, but confirm no apply is genuinely in progress first. Two concurrent applies against the same state is one of the few ways to corrupt it.
Should I use workspaces for environments?
Usually not. Workspaces share one configuration and backend, so an error affects every environment and it is easy to apply to the wrong one. Separate directories or separate state per environment give real isolation and make the blast radius obvious. Workspaces suit short-lived parallel copies of the same thing better than they suit production and staging.