terraform commands
43 commands, each with a one-line explanation. Click a command to copy it, or its title for details.
Commands 43 shown
-
terraform plan -var-file=prod.tfvars -out=plan.tfplanShow changes; save plan artifact for CI gating
-
terraform apply plan.tfplanApply exactly the previously generated plan — no interactive prompts
-
terraform import module.path.resource_type.name <remote-id>Bring an already-existing resource under Terraform control
-
terraform state show module.path.resource_type.nameInspect Terraform state attributes for a single resource
-
terraform state mv old.address new.addressRename/reorganize resource without destroying and recreating it
-
terraform workspace listShow all workspaces; current one marked with *
-
terraform workspace new staging && terraform workspace select stagingCreate a new workspace and switch to it
-
terraform validateCheck Terraform configuration for syntax and consistency errors
-
terraform fmt -recursiveAuto-format all .tf files recursively
-
terraform output -jsonPrint all outputs as JSON; useful for pipeline scripting
-
terraform destroy -target=module.vpc.aws_vpc.mainDestroy a single resource without touching everything else
-
terraform taint module.eks.aws_instance.nodeMark resource for replacement on next apply
-
terraform state rm module.path.resource_type.nameForget a resource from state without destroying it in cloud
-
terraform refresh -var-file=prod.tfvarsUpdate state file to match real infrastructure
-
terraform graph | dot -Tsvg > graph.svgVisualize resource dependency graph (requires Graphviz)
-
terraform state list | grep <pattern>Filter state resources by pattern
-
terraform fmt -recursiveRecursively format all .tf files in subdirectories
-
terraform validateCheck configuration syntax without accessing remote state
-
terraform plan -var-file=prod.tfvars -out=prod.tfplanGenerate plan with prod variables, save to file
-
terraform apply prod.tfplanApply exactly the plan generated earlier (no re-prompts)
-
terraform state show 'aws_instance.web[0]'Display all attributes of a specific resource in state
-
terraform state mv 'aws_instance.web' 'module.app.aws_instance.web'Rename or move a resource without destroying it
-
terraform import 'aws_s3_bucket.mybucket' my-existing-bucketBring an existing resource under Terraform management
-
terraform taint 'aws_instance.web[0]'Mark resource to be destroyed and recreated on next apply
-
terraform state rm 'aws_instance.legacy'Remove a resource from state without destroying it in the cloud
-
terraform output -json | jq 'to_entries[] | {(.key): .value.value}'Print all outputs as compact JSON
-
terraform destroy -target='aws_instance.web' -auto-approveDestroy a single resource without full plan
-
terraform force-unlock <lock-id>Release a stuck state lock after a failed apply
-
terraform workspace new staging && terraform workspace select stagingCreate and activate a Terraform workspace
-
terraform graph | dot -Tsvg > graph.svg && open graph.svgRender resource dependency graph as SVG (requires graphviz)
-
terraform providers lock -platform=linux_amd64 -platform=darwin_arm64Lock provider versions for multiple platforms in .terraform.lock.hcl
-
terraform state mv 'aws_instance.web' 'aws_instance.app'Rename/refactor address without destroy; prefer moved{} block in newer TF
-
terraform state rm 'aws_s3_bucket.legacy'Forget resource from state without deleting real infra; note: object keeps existing
-
terraform state show 'module.vpc.aws_subnet.private[0]'Dump all attributes of one resolved address for drift/debug investigation
-
terraform state list | grep -i 'aws_iam'Filter managed addresses to find what TF tracks before surgery
-
cat > import.tf <<'EOF' import { to = aws_instance.web id = "<id>" } EOF terraform plan -generate-config-out=generated.tfDeclarative import; -generate-config-out scaffolds HCL for the imported object
-
cat >> moved.tf <<'EOF' moved { from = aws_instance.web to = aws_instance.app } EOFRename addresses in code with no destroy/recreate; survives in version control
-
terraform apply -replace='aws_instance.web'Force destroy+recreate of one resource; replaces deprecated terraform taint
-
terraform plan -target='module.db.aws_db_instance.main'Limit plan to one address; note: -target is an escape hatch, can mask drift
-
terraform plan -refresh-onlySync state to real infra without proposing changes; surfaces out-of-band drift
-
terraform init -migrate-state -backend-config=backend.hclMove state to a new backend; use -reconfigure to skip migration and reset
-
terraform output -json | jq -r '.endpoints.value[]'Pipe machine-readable outputs into jq for scripting and downstream wiring
-
TF_LOG=DEBUG TF_LOG_PATH=tf.log terraform planCapture provider/API debug to a file; use TRACE for the most verbose level
no commands match — try a different search