Terraform Commands
Terraform CLI commands for infrastructure as code.
Core Workflow
terraform initInitialize working directory
terraform planShow execution plan
terraform applyApply configuration changes
terraform apply -auto-approveApply without confirmation
terraform destroyDestroy managed infrastructure
terraform destroy -auto-approveDestroy without confirmation
terraform validateValidate configuration syntax
State Management
terraform state listList resources in state
terraform state show resource.nameShow resource details from state
terraform state pullPull current state
terraform state mv source destMove resource in state
terraform state rm resource.nameRemove resource from state
terraform state replace-provider old newReplace provider in state
terraform refreshUpdate state with real infrastructure
Workspaces
terraform workspace listList workspaces
terraform workspace showShow current workspace
terraform workspace new devCreate new workspace
terraform workspace select devSwitch to workspace
terraform workspace delete devDelete workspace
Output & Variables
terraform outputShow all outputs
terraform output nameShow specific output
terraform output -jsonShow outputs as JSON
terraform apply -var="key=value"Set variable from command line
terraform apply -var-file="vars.tfvars"Use variables file
Import & Taint
terraform import resource.name idImport existing resource
terraform taint resource.nameMark resource for recreation
terraform untaint resource.nameRemove taint from resource
Planning & Targeting
terraform plan -out=plan.tfplanSave plan to file
terraform apply plan.tfplanApply saved plan
terraform plan -target=resource.namePlan specific resource
terraform apply -target=resource.nameApply specific resource
terraform plan -refresh=falsePlan without refreshing state
terraform plan -destroyShow destroy plan
Formatting & Validation
terraform fmtFormat configuration files
terraform fmt -recursiveFormat all files recursively
terraform fmt -checkCheck if files are formatted
terraform validateValidate configuration
terraform providersShow required providers
Graph & Dependencies
terraform graphGenerate dependency graph (DOT format)
terraform graph | dot -Tpng > graph.pngGenerate visual graph
terraform providers schema -jsonExport provider schemas as JSON
Backend & Remote State
terraform init -backend-config=config.tfbackendInitialize with backend config
terraform init -migrate-stateMigrate state to new backend
terraform init -reconfigureReconfigure backend
terraform force-unlock LOCK_IDForce unlock state
Console & Testing
terraform consoleInteractive console for expressions
terraform testRun integration tests
terraform showShow current state or plan
terraform show -jsonShow state as JSON
terraform versionShow Terraform version
Advanced Options
terraform apply -parallelism=10Set parallel operations limit
terraform apply -lock=falseDisable state locking
terraform apply -refresh-onlyOnly refresh state
terraform apply -replace=resource.nameForce replace specific resource
terraform providers lockUpdate provider lock file