Advanced By Samson Tanimawo, PhD Published Sep 22, 2026 6 min read

Terraform State Commands Cheat Sheet

The day Terraform and reality disagree, you reach for these. Back up state first, these commands edit the source of truth.

Backup first, every time

State is the source of truth. Touch it without a backup and you may end up re-creating production resources. There is no Ctrl-Z.

Inspect

Most "what's in state?" questions answer themselves with these.

Move and rename

You renamed a module or resource in HCL and now Terraform wants to destroy/recreate. Don't let it. Move state to match.

Remove

Forgets a resource without destroying it. The cloud resource keeps running; Terraform just stops managing it.

Import

Bring an existing cloud resource under Terraform management. The HCL must already exist; import only updates state.

Taint and refresh

Force a resource to be recreated, or sync state to current cloud reality.

Rescue scenarios

The four situations where state surgery actually earns its keep.