Terraform CLI Cheat Sheet is the complete quick-reference of Terraform CLI commands grouped by function. Copy any command with one click and find what you need with Ctrl+F in under 3 seconds.
Init & Configuration
Action
Command
Useful flags
Init
terraform init
Cli configuration
Terraform CLI configuration file
Init
terraform init -upgrade
-upgrade
Init
terraform init -backend-config=<config>
-backe
Reconfigure backend
terraform init -reconfigure
-reconfigure
Disable interactive input
terraform init -input=false
-input
Disable state locking
terraform init -lock=false
-lock
Set lock timeout
terraform init -lock-timeout=5m
-lock-timeout
Migrate existing state
terraform init -migrate-state
-migrate-state
Set plugin directory
terraform init -plugin-dir=./plugins
-plugin-dir
Plan & Apply
Action
Command
Useful flags
Apply
terraform -chdir=environments/production apply
-chdir
Plan
terraform plan
Plan
terraform plan -out will-by-applied.zip
-by-applied -out
Apply
terraform apply
Apply
terraform apply -auto-approve
-auto-approve
Apply
terraform apply will-by-applied.zip
-by-applied
State Management
Action
Command
Useful flags
Push
terraform state push -force terraform.tfstate
-force
List
terraform state list
Show
terraform state show <resource>
Present state:
Show present state:
State files
Terraform state files can contain sensitive data. Encrypting and storing them in a secure backend is crucial for security and compliance.
State
Terraform State
Show
terraform state show <resource>
Workspaces
Action
Command
Useful flags
List workspaces
terraform workspace list
Show current workspace
terraform workspace show
Create new workspace
terraform workspace new myworkspace
Select workspace
terraform workspace select myworkspace
List workspaces (JSON)
terraform workspace list -json
-json
Create workspace from another
terraform workspace new -from=sourceworkspace myworkspace
-from=sourceworkspace
Modules
Action
Command
Useful flags
May be
Terraform may be unable to find providers, modules, and other artifacts.
Initialize and download modules
terraform init
-reconfigure -upgrade
Validate configuration with modules
terraform validate
-json
Show provider requirements including modules
terraform providers
-json
Show execution plan with module resources
terraform plan
-out=tfplan
List resources with module paths in state
terraform state list
Inspect state/plan with module details
terraform show
Visualize dependency graph including modules
terraform graph
-draw-cycles
Retrieve output values including module outputs
terraform output
-json
Import & Move
Action
Command
Useful flags
Import
terraform import <resource> <id>
Move resource in state
terraform state mv aws_instance.example aws_instance.new
Terraform refers to a number of environment variables to customize various
List outputs
terraform output
Show outputs as JSON
terraform output -json
-json
Get raw output
terraform output -raw <output_name>
-raw
Open interactive console
terraform console
Console with variable
terraform console -var 'key=value'
-var
Plan with variable
terraform plan -var 'key=value'
-var
Plan with variable file
terraform plan -var-file=file.tfvars
-var-file
Apply with variable
terraform apply -var 'key=value'
-var
Destroy & Cleanup
Action
Command
Useful flags
Destroy ⚠️
terraform destroy
Plan destruction
terraform plan
-destroy -out=destroy.tfplan
Apply destroy plan
terraform apply
-destroy -auto-approve
Remove resource from state
terraform state rm 'aws_instance.example'
Reconfigure backend
terraform init
-reconfigure
List all state resources
terraform state list
Show a state resource
terraform state show aws_instance.example
Move a resource in state
terraform state mv aws_instance.old aws_instance.new
⚠️ Dangerous / Destructive Commands
These commands are irreversible. Verify your environment (dev/staging vs prod) before running them.
Action
Command
Warning
⚠️ Destroy ⚠️
terraform destroy
Irreversible — verify the target before running
FAQ — Frequently Asked Questions
What is the difference between Init & Configuration and Plan & Apply?
Each group in this Terraform CLI cheat sheet covers a distinct area. Init & Configuration focuses on its specific scope, while Plan & Apply and the remaining groups cover networking, storage, security and diagnostics respectively.
How do I check the installed Terraform CLI version?
Run the version command (usually terraform version or terraform --version). The output shows the client and, when applicable, the server version.
Why does Terraform CLI return ‘permission denied’?
A ‘permission denied’ error in Terraform CLI usually means the current user lacks sufficient privileges or credentials are not configured. Check: (1) assigned IAM/RBAC roles, (2) an active authentication context via the corresponding login command.
How do I filter Terraform CLI output by status or name?
Use flags such as --filter, --selector or --query depending on the tool. You can also pipe into grep or jq to process JSON:
terraform list | grep RUNNING
What is the fastest way to debug a Terraform CLI error?
Add the verbose flag (--verbose, -v or --debug) to the failing command. This reveals the underlying HTTP/API calls and the full error response body.
Official sources & references
Commands cross-checked against vendor documentation and high-authority repositories: