Black Friday: 50% off every workbook with code . Ends Nov 30, 23:59 ET. Buy Now

Last day: 50% off every workbook ends tonight at 23:59 ET. Code Buy Now

Skip to main content
intermediate Free with email

What Are the 18 Terraform Commands You Actually Need?

Reviewed 2026-09-28

Direct answer
The core Terraform commands are terraform init (prepare the directory), terraform plan (preview changes), terraform apply (make them), terraform destroy (delete what Terraform manages), terraform import (bring an existing resource into state), terraform validate, terraform state and terraform workspace. Run init first: plan, apply, destroy and import won't work without it.

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 commands in order: terraform init, terraform plan -out plan.out, then terraform apply plan.out
The core Terraform workflow: set up the directory, save a plan, apply exactly that plan.

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.

CommandWhat it does
terraform plan -out plan.outPreviews changes and saves the plan
terraform apply plan.outApplies a saved plan
terraform applyPlans, asks for confirmation, then applies
terraform apply -auto-approveSkips the confirmation prompt
terraform apply -var tags-repository_url=${GIT_URL}Sets a variable from the command line
terraform apply -target=module.s3Limits 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 in three steps: write the resource block, run terraform import with the address and ID, then run terraform plan to check for changes
terraform import binds an existing object to a resource address. It updates state, not your configuration.

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

CommandWhat it does
terraform showPrints the current state in readable form
terraform state pull > terraform.tfstateDownloads remote state to a local file
terraform state pushUploads a local state file to the remote backend
terraform state mv aws_iam_role.role1 module.mymoduleRe-binds a resource to a new address
Terraform state mv compared with a moved block: both rename a resource in state without destroying and recreating it
Move or rename a resource without a destroy and create: state mv from the CLI, or a moved block in code.

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 refresh compared with terraform apply -refresh-only: refresh is deprecated, refresh-only shows the changes and asks for confirmation
terraform refresh is deprecated. terraform apply -refresh-only shows the changes first.

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

CommandWhat it does
terraform validateChecks the syntax of every .tf file in the directory
terraform graph | dot -Tpng > graph.pngDraws the dependency graph (needs Graphviz)
terraform consoleTests expressions against the current state
terraform output -jsonPrints 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 mv or whether -target works with plan
  • DevOps learners. Already know the container side? See the Docker Commands and Dockerfile Commands cheat sheets.

Frequently asked questions

What are the basic Terraform commands?
terraform init prepares a directory, terraform plan previews changes, terraform apply makes them, and terraform destroy removes what Terraform manages. terraform validate checks syntax and terraform import brings an existing resource into state.
Is Terraform written in YAML or JSON?
Neither. Configuration uses HCL, HashiCorp Configuration Language. Terraform can read a JSON syntax as an alternative, but YAML isn't supported.
What does terraform init do?
It prepares a working directory. It initializes the backend, retrieves referenced modules and installs provider plugins. Run it first, before plan, apply, destroy or import.
What is the difference between terraform plan and terraform apply?
terraform plan previews changes and never touches real infrastructure. terraform apply carries them out. Run plan first, or let apply show the plan and ask for confirmation.
How do I import a resource in Terraform?
Write a matching resource block, then run terraform import
, for example terraform import aws_iam_policy.elastic_post arn:aws:iam::123456789:policy/elastic_post. The command updates state only. Terraform 1.5 and later also support import blocks.
What does terraform destroy do?
It deletes every object the configuration manages. It's shorthand for terraform apply -destroy. Run terraform plan -destroy first to review what will be deleted.
How do I destroy a single resource in Terraform?
Add -target, for example terraform destroy -target aws_s3_bucket.my_bucket. It also destroys that resource's dependencies, and Terraform's docs say to use -target only in exceptional circumstances.
Is terraform refresh deprecated?
Yes. Terraform's docs recommend terraform apply -refresh-only, which shows detected changes and asks before updating state.

Questions about this PDF

No questions yet. Ask the first one.

Ask a question

Your email address won't be published. We review every question before it appears. How we handle your data. Required fields are marked

Reviewed by

Senior Network Automation Engineer

How to cite this resource

SMEnode Labs (2026). What Are the 18 Terraform Commands You Actually Need?. SMEnode Labs. https://smenode-labs.com/free-pdf/devops/terraform-commands/

APA

SMEnode Labs. (2026). What Are the 18 Terraform Commands You Actually Need?. SMEnode Labs. https://smenode-labs.com/free-pdf/devops/terraform-commands/

BibTeX

@misc{smenodelabs2026,
  title = {What Are the 18 Terraform Commands You Actually Need?},
  author = {{SMEnode Labs}},
  year = {2026},
  url = {https://smenode-labs.com/free-pdf/devops/terraform-commands/},
  note = {SMEnode Labs}
}