Complete Terraform CLI commands cheat sheet for infrastructure as code. Covers init, plan, apply, state management, workspaces, and import operations.
Terraform's CLI is a workflow: init, plan, apply, and a few commands around the state file that records what exists. The ten commands here are the ones a practitioner runs; the notes cover the order and the two mistakes that cost the most — applying without reading the plan, and editing state by hand.
Search all Terraform shortcuts interactively
Interactive Shortcut Finder| Shortcut | Action | What it does |
|---|---|---|
| terraform init | Prepare your working directory for other commands | Prepare your working directory for other commands. |
| terraform validate | Check whether the configuration is valid | Check whether the configuration is valid. |
| terraform plan | Show changes required by the current configuration | Show changes required by the current configuration. |
| terraform apply | Create or update infrastructure | Create or update infrastructure. |
| terraform destroy | Destroy previously-created infrastructure | Destroy previously-created infrastructure. |
| Shortcut | Action | What it does |
|---|---|---|
| terraform console | Try Terraform expressions at an interactive command prompt | Try Terraform expressions at an interactive command prompt. |
| terraform fmt | Reformat your configuration in the standard style | Reformat your configuration in the standard style. |
| terraform force-unlock | Release a stuck lock on the current workspace | Release a stuck lock on the current workspace. |
| terraform get | Install or upgrade remote Terraform modules | Install or upgrade remote Terraform modules. |
| terraform graph | Generate a Graphviz graph of the steps in an operation | Generate a Graphviz graph of the steps in an operation. |
| terraform import | Associate existing infrastructure with a Terraform resource | Associate existing infrastructure with a Terraform resource. |
| terraform login | Obtain and save credentials for a remote host | Obtain and save credentials for a remote host. |
| terraform logout | Remove locally-stored credentials for a remote host | Remove locally-stored credentials for a remote host. |
| terraform metadata | Metadata related commands | Metadata related commands. |
| terraform modules | Show all declared modules in a working directory | Show all declared modules in a working directory. |
| terraform output | Show output values from your root module | Show output values from your root module. |
| terraform providers | Show the providers required for this configuration | Show the providers required for this configuration. |
| terraform refresh | Update the state to match remote systems | Update the state to match remote systems. |
| terraform show | Show the current state or a saved plan | Show the current state or a saved plan. |
| terraform state | Advanced state management | Advanced state management. |
| terraform taint | Mark a resource instance as not fully functional | Mark a resource instance as not fully functional. |
| terraform untaint | Remove the 'tainted' state from a resource instance | Remove the 'tainted' state from a resource instance. |
| terraform version | Show the current Terraform version | Show the current Terraform version. |
| terraform workspace | Workspace management | Workspace management. |
| terraform -help | Show this help output, or the help for a specified subcommand. | Show this help output, or the help for a specified subcommand.. |
| terraform -version | An alias for the "version" subcommand. | An alias for the "version" subcommand.. |
The basic workflow is: terraform init (initialize) → terraform plan (preview) → terraform apply (execute) → terraform destroy (cleanup).
terraform plan creates an execution plan showing what changes will be made to your infrastructure without actually applying them.
Use 'terraform import resource_type.name resource_id' to bring existing infrastructure under Terraform management.
Run 'terraform fmt' to automatically format all .tf files to the canonical style.
Print the Terraform cheat sheet and keep it next to your keyboard for the first week, then switch to active recall: open Shortcut Speedrun and practice Terraform shortcuts against the clock until they're automatic.
Yes — use My Stack to combine Terraform shortcuts with any other platform on this site into one printable reference, which is useful if your daily workflow spans several tools.
Browse shortcuts for 268 platforms
Explore Allterraform init downloads providers and modules and configures the backend; run it after cloning and after adding a provider. terraform fmt and terraform validate tidy and type-check the configuration without touching infrastructure, and belong in CI. terraform plan computes the changes and prints them — read every line, because a resource marked for replacement means downtime — and terraform apply executes them after a confirmation; plan -out=file then apply file guarantees the applied change is the one reviewed. terraform destroy removes everything the configuration manages.
The state file maps configuration to real resources. terraform state list shows what Terraform believes it manages, and state show prints one resource's attributes. terraform import [resource] [ID] brings an existing resource under management by adding it to state — write the configuration block first, import, then plan until the diff is empty. terraform output prints output values, with -json for scripts. Never edit the state file by hand; use the state subcommands, which lock and back it up.
terraform workspace list shows workspaces, which give one configuration several independent states (dev, staging, prod) in the same backend; workspace select switches. For a team, a remote backend with locking (S3 with DynamoDB, Terraform Cloud, GCS) is the first thing to configure, because two people applying against local state is how resources get orphaned.
Open your assistant with this page preloaded as the source — great for follow-up questions like "which of these work in other apps?"