xutil.dev
Login

Terraform Cheatsheet

Quick reference for Terraform CLI commands covering init, plan, apply, state management, workspaces, import, output, and formatting

57 commands

terraform init

Initialize working directory

terraform init -upgrade

Initialize and upgrade providers

terraform init -backend-config

Initialize with backend config

terraform init -migrate-state

Initialize with state migration

terraform init -reconfigure

Reconfigure backend during init

terraform providers

Show required providers

terraform providers lock

Update provider lock file

terraform version

Show Terraform version

terraform plan

Show execution plan

terraform plan -out

Save execution plan to file

terraform plan -var

Plan with variable

terraform plan -var-file

Plan with variable file

terraform plan -target

Plan for specific resource only

terraform plan -destroy

Show destroy plan

terraform apply

Apply changes

terraform apply -auto-approve

Apply without confirmation

terraform apply tfplan

Apply saved plan

terraform destroy

Destroy all managed resources

terraform destroy -target

Destroy specific resource

terraform refresh

Sync state with actual resources

terraform state list

List resources in state

terraform state show

Show resource details in state

terraform state mv

Move/rename resource in state

terraform state rm

Remove resource from state

terraform state pull

Pull remote state

terraform state push

Push local state to remote

terraform state replace-provider

Replace provider in state

terraform force-unlock

Force unlock state

terraform workspace list

List workspaces

terraform workspace new

Create new workspace

terraform workspace select

Switch workspace

terraform workspace show

Show current workspace

terraform workspace delete

Delete workspace

terraform import

Import existing resource to state

terraform import (module)

Import resource into module

terraform import (for_each)

Import for_each resource

terraform import (count)

Import count resource

terraform plan -generate-config-out

Generate config during import

terraform output

Show all output values

terraform output (name)

Show specific output value

terraform output -json

Show outputs in JSON format

terraform output -raw

Show raw output value

terraform console

Start interactive console

terraform graph

Generate resource dependency graph

terraform show

Show state or plan in readable format

terraform show -json

Show state in JSON format

terraform get

Download modules

terraform get -update

Update modules to latest

terraform init (module source)

Get module from Git repository

terraform test

Run Terraform tests

terraform providers mirror

Mirror providers to local directory

terraform fmt

Format configuration files

terraform fmt -check

Check formatting without changes

terraform fmt -recursive

Format recursively

terraform validate

Validate configuration syntax

terraform fmt -diff

Show format diff

terraform login

Log in to Terraform Cloud