DevOpsil
Terraform22 commands

Terraform CLI Cheat Sheet

Essential Terraform commands for infrastructure as code — init, plan, apply, state management, and workspaces.

Core Workflow

CommandDescription
terraform init
Initialize working directory
terraform plan
Preview changes
terraform apply
Apply changes
terraform apply -auto-approve
Apply without prompt
terraform destroy
Destroy all resources
terraform validate
Validate configuration
terraform fmt
Format config files

State Management

CommandDescription
terraform state list
List resources in state
terraform state show <resource>
Show resource details
terraform state mv <src> <dest>
Move resource in state
terraform state rm <resource>
Remove resource from state
terraform import <resource> <id>
Import existing resource
terraform refresh
Sync state with real resources

Workspaces

CommandDescription
terraform workspace list
List workspaces
terraform workspace new <name>
Create workspace
terraform workspace select <name>
Switch workspace
terraform workspace delete <name>
Delete workspace

Output & Debug

CommandDescription
terraform output
Show all outputs
terraform output <name>
Show specific output
terraform console
Interactive console
terraform graph | dot -Tpng > graph.png
Generate dependency graph
TF_LOG=DEBUG terraform plan
Enable debug logging