The core Terraform commands are terraform init (prepare the directory: modules, backend, provider plugins), terraform plan (preview changes), terraform apply (make them), terraform destroy (delete everything Terraform manages), terraform import (bring an existing resource into state), terraform validate (check syntax), terraform state (inspect and edit state) and terraform workspace (separate environments). Run init first: plan, apply, destroy and import won’t work without it. This Terraform commands cheat sheet covers 18 commands from the PDF with the exact syntax, and the PDF is free. Drop your email and it lands in your inbox.
Terraform Commands Cheat Sheet: Install Terraform with curl or tfenv
Install Terraform two ways. The first is a binary download, then unzip it into your PATH. Replace the version with the current one from HashiCorp’s releases page.
curl -O https://releases.hashicorp.com/terraform/1.4.6/terraform_1.4.6_linux_amd64.zip
sudo unzip terraform_1.4.6_linux_amd64.zip -d /usr/local/bin/
The second is tfenv, a version manager. It’s the better choice once different projects pin different Terraform versions.
git clone --depth=1 https://github.com/tfutils/tfenv.git ~/.tfenv
echo 'export PATH="$HOME/.tfenv/bin:$PATH"' >> ~/.bash_profile
tfenv install 1.4.6
tfenv use 1.4.6
Check it with terraform -v. The full list of commands is in HashiCorp’s CLI documentation.
Terraform Init and Terraform Get: Set Up the Working Directory
Per the init docs, terraform init initializes the backend, retrieves referenced modules and installs provider plugins.
terraform init
terraform init -input=false
terraform init -backend-config=cfg/s3.dev.tf -reconfigure
-input=false makes init error instead of prompting, which suits CI. -reconfigure disregards the existing backend configuration and doesn’t migrate state. To copy existing state to a new backend, use -migrate-state instead.
terraform get -update=true downloads and updates the modules declared in the root module. Init also retrieves modules, so you mostly need get when you want to refresh modules that are already downloaded.
Terraform Plan and Terraform Apply: Preview, Then Change

terraform plan shows what would change before anything does. -out writes the plan to a file, in a format Terraform’s plan docs call opaque. Treat that file as sensitive, because it holds your configuration and variable values.
| Command | What it does |
|---|---|
terraform plan -out plan.out | Previews changes and saves the plan |
terraform apply plan.out | Applies a saved plan |
terraform apply | Plans, asks for confirmation, then applies |
terraform apply -auto-approve | Skips the confirmation prompt |
terraform apply -var tags-repository_url=${GIT_URL} | Sets a variable from the command line |
terraform apply -target=module.s3 | Limits the run to one module |
The docs say to use -target in exceptional circumstances only, because routine use can lead to undetected configuration drift.
Terraform Destroy: Tear Down Safely
terraform destroy is shorthand for terraform apply -destroy, per Terraform’s destroy docs, and it deletes every object the configuration manages. Preview it first.
terraform plan -destroy
terraform destroy -target aws_s3_bucket.my_bucket
-target destroys that resource and its dependencies, so the scope can be wider than the one name you typed. The docs aim destroy mainly at temporary development infrastructure.
Terraform Import: Bring an Existing Resource into State

terraform import is one of the most-searched Terraform commands (about 1,000 searches a month in the US). It binds an existing cloud object to a resource address in your state.
terraform import aws_iam_policy.elastic_post arn:aws:iam::123456789:policy/elastic_post
The command updates state only. Write the matching resource block first. Terraform also supports import blocks that run during plan and apply, and since v1.5 terraform plan -generate-config-out=generated.tf can draft the configuration, as an experimental feature. Import each object to one address only: importing the same object twice can cause unwanted behaviour.
Terraform State Commands: Show, Pull, Push and Move
| Command | What it does |
|---|---|
terraform show | Prints the current state in readable form |
terraform state pull > terraform.tfstate | Downloads remote state to a local file |
terraform state push | Uploads a local state file to the remote backend |
terraform state mv aws_iam_role.role1 module.mymodule | Re-binds a resource to a new address |

Without state mv, moving a resource into a module looks to Terraform like a delete and a create. A moved block in your .tf files does the same job in code, with no resource destroyed. To switch to a new backend and copy state, use terraform init -migrate-state rather than state push.
terraform refresh is deprecated
The PDF lists terraform refresh. Terraform’s docs mark it deprecated and recommend terraform apply -refresh-only, which shows the detected changes and asks before updating state.

Terraform Workspace Commands: Manage Multiple Environments
terraform workspace new dev
terraform workspace select dev
terraform workspace list
terraform workspace show
workspace new creates a workspace and switches to it. list marks the active one with an asterisk. Per Terraform’s workspace docs, CLI workspaces use the same backend, so they aren’t a suitable isolation mechanism when each environment needs its own credentials and access controls. If you also run containers, the Docker Compose commands cheat sheet covers the same dev and staging split on the container side.
Terraform Output, Validate, Graph and Console Commands
| Command | What it does |
|---|---|
terraform validate | Checks the syntax of every .tf file in the directory |
terraform graph | dot -Tpng > graph.png | Draws the dependency graph (needs Graphviz) |
terraform console | Tests expressions against the current state |
terraform output -json | Prints outputs as JSON |
validate checks that files parse, not that the plan will succeed. In the console, echo "aws_iam_user.notif.arn" | terraform console returns the real ARN.
Terraform Providers: See What Your Project Depends On
terraform providers shows the provider requirements of the configuration and where each one was detected, per its docs. The PDF’s sample output uses an old provider.aws ~> 1.24.0 format, so your own output will look different. Looking for a specific provider’s documentation instead? Use the Terraform Registry.
Terraform Debugging with TF_LOG, jq and gcloud
TF_LOG_PATH=mylogfile.txt TF_LOG=debug terraform apply
terraform output -json | jq '.elastic_endpoint.value'
gcloud beta resource-config bulk-export --resource-format=terraform
The first writes a debug log to a file. The second uses jq to pull one output value, handy when a pipeline needs a single endpoint. The third exports existing Google Cloud resources as Terraform. Debugging Terraform, Docker and CI/CD failures comes up often in interviews, and our Free DevOps Interview Questions PDF has 180 Q&As across the toolchain. Comparing it with another tool? See Terraform vs Ansible.
Terraform vs OpenTofu: Do These Commands Still Apply?
HashiCorp moved Terraform from the MPL to the BSL licence in August 2023, and IBM completed its $6.4B acquisition of HashiCorp on 2025-02-27. OpenTofu is a Linux Foundation fork that kept the MPL. It’s a fork, so the core commands carry over, but check each tool’s docs for newer features.
What’s Inside the Terraform Commands Cheat Sheet PDF
The PDF is a 2-page Terraform CLI cheat sheet.
- 18 commands and subcommands with syntax: version, init, get, plan, apply, destroy, console, graph, validate, providers, show, refresh, import, workspace, output and state pull, push and mv
- Both install methods, curl and tfenv
- Short tips on jq and gcloud bulk-export
terraform refresh is in the PDF, but it’s deprecated. The moved block, -refresh-only and -migrate-state are on this page, not in the PDF.
Who It’s For
- Beginners who want each command and when to run it
- Engineers who use Terraform daily but forget
state mvor whether-targetworks withplan - DevOps learners. Already know the container side? See the Docker Commands and Dockerfile Commands cheat sheets.
No questions yet. Ask the first one.