Skip to content

Terraform & Helm: Terraform: workspaces, import & more

15 Terraform & Helm commands: Terraform: workspaces, import & more. Click a command to see what each part does.

Index
15 items
Click a command to see what each part does.

Terraform: workspaces, import & more15

  • terraform workspace list; terraform workspace new <name>; terraform workspace select <name>List, create and switch workspaces

    What each part does

    1. workspace listworkspaces; * marks the current one
    2. workspace newnew empty state for the same code
    3. workspace selectswitch
  • terraform plan -generate-config-out=generated.tfImport an existing resource (block, Terraform 1.5+)

    What each part does

    1. import block in codeimport { to = aws_s3_bucket.logs id = "my-logs" }
    2. -generate-config-outwrite matching resource code for you to review
  • terraform import <address> <id>Import an existing resource (CLI)

    What each part does

    1. importrecord a real resource in state
    2. <address>resource in your code, e.g. aws_s3_bucket.logs
    3. <id>the provider's ID for it
  • terraform plan -destroy -out=destroy.tfplanPlan destroying everythingDestructive

    What each part does

    1. -destroyplan to delete every managed resource
    2. -outsave it; apply with terraform apply destroy.tfplan
  • terraform destroy -var-file=<env>.tfvarsDestroy everythingDestructive

    What each part does

    1. destroydelete all resources in this state (asks to confirm)
    2. -var-filesame variables as for apply
  • terraform apply -refresh-onlySync state with reality without changing anythingCaution

    What each part does

    1. -refresh-onlyupdate state from the real infrastructure (drift), no resource changes; replaces terraform refresh
  • terraform consoleTry expressions interactively

    What each part does

    1. consoleREPL to evaluate expressions, functions and values from state, e.g. cidrsubnet("10.0.0.0/16", 8, 1)
  • terraform output -json | jqOutputs as JSON

    What each part does

    1. output -jsonevery output with type and sensitive flag
    2. | jqpretty-print or pick values
  • terraform show -json tfplan | jq '.resource_changes[] | {address, actions: .change.actions}'Show a saved plan or state in JSON

    What each part does

    1. show -json tfplanmachine-readable plan
    2. jq '...'list each resource and its actions (create, update, delete)
  • terraform state pull > state-backup.tfstateDownload / back up the remote state

    What each part does

    1. state pullprint the current remote state
    2. > 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 platforms

    What each part does

    1. providersprovider requirements per module
    2. providers lock -platform=...record checksums for every OS your team and CI use
  • terraform versionVersions of Terraform and providers

    What each part does

    1. versionTerraform version and the provider versions selected in this directory
  • terraform graph | dot -Tsvg > graph.svgDependency graph

    What each part does

    1. graphresource dependencies in DOT format
    2. dot -Tsvgrender with Graphviz
  • terraform testRun Terraform tests

    What each part does

    1. testrun *.tftest.hcl files: plan/apply assertions against your module
  • terraform init -upgrade -backend=falseUnlock a provider upgrade in one module

    What each part does

    1. -upgradenewest allowed provider versions
    2. -backend=falsedon't touch the backend (fast, for local checks)

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…