Terraform & Helm: Terraform: workspaces, import & more
15 Terraform & Helm commands: Terraform: workspaces, import & more. Click a command to see what each part does.
Terraform & Helm: Terraform: workspaces, import & moreIndex
Terraform: workspaces, import & more15
terraform workspace list; terraform workspace new <name>; terraform workspace select <name>List, create and switch workspacesWhat each part does
workspace listworkspaces; * marks the current oneworkspace newnew empty state for the same codeworkspace selectswitch
terraform plan -generate-config-out=generated.tfImport an existing resource (block, Terraform 1.5+)What each part does
import block in codeimport { to = aws_s3_bucket.logs id = "my-logs" }-generate-config-outwrite matching resource code for you to review
terraform import <address> <id>Import an existing resource (CLI)What each part does
importrecord a real resource in state<address>resource in your code, e.g. aws_s3_bucket.logs<id>the provider's ID for it
terraform plan -destroy -out=destroy.tfplanPlan destroying everythingDestructiveWhat each part does
-destroyplan to delete every managed resource-outsave it; apply with terraform apply destroy.tfplan
terraform destroy -var-file=<env>.tfvarsDestroy everythingDestructiveWhat each part does
destroydelete all resources in this state (asks to confirm)-var-filesame variables as for apply
terraform apply -refresh-onlySync state with reality without changing anythingCautionWhat each part does
-refresh-onlyupdate state from the real infrastructure (drift), no resource changes; replaces terraform refresh
terraform consoleTry expressions interactivelyWhat each part does
consoleREPL to evaluate expressions, functions and values from state, e.g. cidrsubnet("10.0.0.0/16", 8, 1)
terraform output -json | jqOutputs as JSONWhat each part does
output -jsonevery output with type and sensitive flag| jqpretty-print or pick values
terraform show -json tfplan | jq '.resource_changes[] | {address, actions: .change.actions}'Show a saved plan or state in JSONWhat each part does
show -json tfplanmachine-readable planjq '...'list each resource and its actions (create, update, delete)
terraform state pull > state-backup.tfstateDownload / back up the remote stateWhat each part does
state pullprint the current remote state> filesave a copy before risky state surgery
terraform providers; terraform providers lock -platform=linux_amd64 -platform=darwin_arm64 -platform=windows_amd64Providers and lock file for all platformsWhat each part does
providersprovider requirements per moduleproviders lock -platform=...record checksums for every OS your team and CI use
terraform versionVersions of Terraform and providersWhat each part does
versionTerraform version and the provider versions selected in this directory
terraform graph | dot -Tsvg > graph.svgDependency graphWhat each part does
graphresource dependencies in DOT formatdot -Tsvgrender with Graphviz
terraform testRun Terraform testsWhat each part does
testrun *.tftest.hcl files: plan/apply assertions against your module
terraform init -upgrade -backend=falseUnlock a provider upgrade in one moduleWhat each part does
-upgradenewest allowed provider versions-backend=falsedon't touch the backend (fast, for local checks)
Nothing matches.
My DevOps Playbook by Angelo John Calleja