Tool cheatsheet
Terraform 1 Cheatsheet
Write, plan, apply and manage infrastructure as code with the Terraform CLI.
Core workflow
- Check the Terraform version — Print the Terraform version and the provider versions in use.
- Initialize a working directory — Download providers and modules and set up the backend. Run it first and after changing providers.
- Upgrade providers — Install the newest provider versions allowed by your version constraints.
- Format the code — Rewrite configuration files into the canonical style, including subfolders.
- Validate the configuration — Check the configuration for syntax and consistency errors.
- Preview changes — Show what Terraform would create, change or destroy.
- Save a plan to a file — Save the plan so you can apply exactly what you reviewed.
- Apply changes — Create or update infrastructure after you confirm the plan.
- Apply a saved plan — Apply a plan file without a further prompt.
- Destroy all managed infrastructure — Delete everything the configuration manages.
- Apply without confirmation — Skip the approval prompt, as CI pipelines do.
Variables, targets and outputs
- Set a variable — Pass a value for an input variable.
- Use a variable file — Load variable values from a file.
- Apply a single resource — Limit the run to one resource and what it depends on.
- Force a resource to be recreated — Destroy and recreate a resource. This replaces the old taint command.
- Show outputs — Print all of the configuration's output values.
- Read one output as a plain value — Print a single output without quotes, handy in scripts.
- Open an expression console — Try expressions and inspect values interactively.
State
- List resources in state — Show every resource Terraform tracks.
- Show a resource in state — Print the recorded attributes of one resource.
- Rename a resource in state — Move a resource to a new address, for example after renaming it in code.
- Forget a resource — Stop tracking a resource without destroying it.
- Import an existing resource — Bring a resource that already exists under Terraform's management, here an S3 bucket.
- Sync state with reality — Update the state to match real infrastructure without changing anything.
- Release a stuck state lock — Remove a lock that a crashed run left behind, using the lock ID from the error.
Workspaces and providers
- List workspaces — Show workspaces; the current one is starred.
- Create a workspace — Create and switch to a new workspace with its own state.
- Switch workspace — Switch to an existing workspace.
- List required providers — Show the providers the configuration needs.
- Draw the dependency graph — Output the graph in DOT format; render it with Graphviz.
- Log in to HCP Terraform — Get an API token for remote runs and the private registry.
Related cheatsheets
- Ansible 2 cheatsheet — Run ad-hoc commands and playbooks, manage inventories, roles, collections and secrets with Ansible.
- Argo CD 3 cheatsheet — Install Argo CD, define Applications declaratively, and manage sync, diffs, history and rollbacks with the argocd CLI.
- AWS CLI 2 cheatsheet — Configure credentials and manage S3, EC2, Lambda, logs, containers and secrets with the AWS CLI v2.
- Azure CLI 2 cheatsheet — Sign in and manage resource groups, VMs, web apps, storage, Kubernetes, registries and secrets with the az command.
- Bash and Linux 5 cheatsheet — Everyday shell and Linux commands for files, searching text, permissions, processes and servers.
- Claude API cheatsheet — Call Claude from Python, TypeScript or curl: messages, streaming, thinking, tools, structured output, caching, batches and error handling.