Cheat sheet: Terraform & Helm
Terraform plan/apply/state and Helm install/upgrade/rollback, flag by flag.
Each entry shows the command, a copy button, and what every part does: sub-command, flag, pipe, redirect and placeholder, in the order they appear. <placeholders> are the bits you replace.
Terraform: everyday workflow8
terraform init -upgradeInitialise and upgrade providersWhat each part does
initdownload providers/modules and configure the backend-upgradepick the newest versions allowed by the constraints
terraform fmt -recursive -check && terraform validateFormat and validateWhat each part does
fmt -recursiveformat .tf files in sub-folders too-checkdon't change files; exit non-zero if formatting is needed (CI)validatecheck syntax and internal consistency (no API calls)
terraform plan -var-file=<env>.tfvars -out=tfplanPlan with a var file and save the planWhat each part does
plancompute what would change-var-file=<env>.tfvarsload variable values from a file (repeatable)-out=tfplansave this exact plan to apply later (contains values in clear text: keep it private)
terraform apply tfplanApply exactly the reviewed planCautionWhat each part does
apply tfplanapply the saved plan with no re-planning and no prompt
terraform plan -input=false -no-color -detailed-exitcode -out=tfplanCI-friendly plan: did anything change?What each part does
-input=falsenever prompt for variables-no-colorplain output for logs-detailed-exitcodeexit 0 = no changes, 1 = error, 2 = changes present
terraform plan -target=<address> -out=tfplanPlan only one resource (exceptional cases)What each part does
-target=<address>limit to that resource and its dependencies (use sparingly)
terraform plan -replace=<address> -out=tfplanForce replacement of one resourceCautionWhat each part does
-replace=<address>plan to destroy and recreate it (successor of taint)
terraform -chdir=<dir> planRun in another folder without cdWhat each part does
-chdir=<dir>global option, goes before the subcommand
Terraform: state6
terraform state list | grep <name>Find a resource in stateWhat each part does
state listevery resource address in the state| grep <name>keep matching addresses
terraform state show <address>Inspect one resourceWhat each part does
state show <address>all attributes stored for that resource
terraform state mv <old-address> <new-address>Rename/move without destroyingCautionWhat each part does
state mvchange the address in state (e.g. after refactoring into a module)
Tip Newer alternative: a moved {} block in code.
terraform state rm <address>Stop managing a resource (keep it in the cloud)CautionWhat each part does
state rmforget the resource; the real object is NOT deleted
terraform output -raw <name>Read an output for scriptsWhat each part does
output <name>print an output value-rawplain string without quotes (for shell variables)
terraform force-unlock <lock-id>Release a stuck lockDestructiveWhat each part does
force-unlock <lock-id>remove a lock left by a crashed run (ID is in the error message)
Tip Make sure nothing else is running against this state.
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)
Helm9
helm repo add <name> <url> && helm repo updateAdd a chart repo and refreshWhat each part does
repo add <name> <url>register a chart repositoryrepo updaterefresh the local index of all repos
helm show values <repo>/<chart> > values.yamlLook at a chart's default valuesWhat each part does
show valuesprint the chart's values.yaml> values.yamlsave it as a starting point
helm template <release> <chart> -f <values-file> | lessRender templates locally (no cluster)What each part does
templaterender manifests locally-f <values-file>your values (repeatable; later files win)| lesspage through the output
helm upgrade --install <release> <chart> -n <namespace> --create-namespace -f <values-file> --set <key>=<value> --wait --timeout 5mInstall or upgrade in one commandWhat each part does
upgrade --installupgrade if the release exists, otherwise install (-i)-n <namespace>target namespace--create-namespacecreate it if missing (with --install)-f <values-file>values file--set <key>=<value>override one value on the command line (wins over -f)--waitwait until resources are ready--timeout 5mhow long to wait
helm upgrade --install <release> <chart> --rollback-on-failure --timeout 5mRoll back automatically if the upgrade failsWhat each part does
--rollback-on-failureHelm 4: on failure, roll back to the last good release (implies --wait)
Tip Helm 3 calls this flag --atomic.
helm history <release> -n <namespace>; helm rollback <release> <revision> -n <namespace>Release history and rollbackCautionWhat each part does
historyrevisions with status and chart/app versionsrollback <release> <revision>return to that revision (omit it for the previous one)
helm list -A | grep <release>Find a release in any namespaceWhat each part does
list -Areleases in all namespaces| grep <release>keep the matching row
helm get values <release> -n <namespace> --allValues actually used by a releaseWhat each part does
get valuesuser-supplied values of the deployed release--allinclude chart defaults too
helm uninstall <release> -n <namespace>Remove a releaseDestructiveWhat each part does
uninstalldelete all resources of the release (PVCs may stay)
Helm: charts, repos & debugging16
helm search repo <keyword> --versions; helm search hub <keyword>Search charts in added repos / Artifact HubWhat each part does
search repocharts in your added repos--versionsevery chart version, not only the latestsearch hubsearch Artifact Hub
helm pull <repo>/<chart> --version <version> --untarDownload and unpack a chartWhat each part does
pulldownload the chart .tgz--versionspecific chart version--untarunpack to a folder to read templates
helm show chart <repo>/<chart>; helm show readme <repo>/<chart>Show a chart's metadata and READMEWhat each part does
show chartChart.yaml: version, appVersion, dependenciesshow readmedocumentation
helm upgrade --install <release> oci://<registry>/<path>/<chart> --version <version> -n <namespace>Install a chart from an OCI registryWhat each part does
oci://...charts stored in a container registry (no helm repo add)--versionchart version
helm status <release> -n <namespace>Status and notes of a releaseWhat each part does
statusdeployed / failed / pending-upgrade, revision, and the chart's NOTES
helm get manifest <release> -n <namespace>What did Helm actually deploy?What each part does
get manifestthe rendered YAML of the current revision (--revision <n> for older)
helm list -A --pending --failedReleases stuck or failedWhat each part does
-Aall namespaces--pending --failedonly releases in those states (pending-upgrade blocks new upgrades)
helm upgrade <release> <chart> -f <values-file> --dry-run=server --debug -n <namespace>Preview an upgrade without applyingWhat each part does
--dry-run=serverrender and validate against the cluster, change nothing--debugprint the rendered manifests
helm diff upgrade <release> <chart> -f <values-file> -n <namespace>Diff an upgrade (helm-diff plugin)What each part does
helm diff upgradecolored diff between the live release and what the upgrade would deploy (helm plugin install https://github.com/databus23/helm-diff)
helm upgrade <release> <chart> --reuse-values --set <key>=<value>Keep current values on upgradeCautionWhat each part does
--reuse-valuesstart from the last release's values--setchange only this one
Tip Can hide new chart defaults; --reset-then-reuse-values is safer on Helm 3.14+.
helm create <chart>Create a new chartWhat each part does
helm createscaffold a chart: Chart.yaml, values.yaml, templates
helm lint <chart-dir> -f <values-file>Lint a chartWhat each part does
lintcheck the chart and rendered templates for errors and best practices
helm dependency update <chart-dir>Fetch chart dependenciesWhat each part does
dependency updatedownload the subcharts listed in Chart.yaml into charts/ and update Chart.lock
helm package <chart-dir> && helm push <chart>-<version>.tgz oci://<registry>/<path>Package and push a chart to an OCI registryWhat each part does
packagebuild <chart>-<version>.tgzpush ... oci://upload to the registry (helm registry login first)
helm test <release> -n <namespace>Run a release's testsWhat each part does
helm testrun the chart's test hook pods and report pass/fail
helm plugin listInstalled Helm pluginsWhat each part does
plugin liste.g. diff, secrets, unittest
Nothing matches.
My DevOps Playbook by Angelo John Calleja