Terraform Cheatsheet

Top commands.

Initialisation

terraform init is the first command in any project. Get the providers and backend right and everything that follows is easier; get them wrong and every subsequent command produces confusing errors.

Plan and apply

The plan-then-apply discipline keeps Terraform changes safe. Save the plan, apply that exact plan; do not run plan and apply separately and assume nothing changed in between.

State management

State management is its own discipline. list, rm, import, and mv cover most refactor and recovery patterns; reach for them before reaching for a destructive workaround.

Workspaces

Workspaces are the lightweight environment primitive. Useful for transient and ephemeral environments; directories beat workspaces for serious production separation.

Debugging

Debugging Terraform is its own discipline. Verbose logs, refresh, validate, and fmt cover most of what you reach for during a confused plan output.