Terraform Cheat Sheet

HCL syntax reference, resource configurations, and state management commands. Complete reference guide with copy-paste ready commands.

Core Commands

terraform init

Initialize working directory

terraform plan

Preview changes

terraform apply

Apply changes

terraform destroy

Destroy infrastructure

terraform validate

Validate configuration

terraform fmt

Format configuration files

State Management

terraform state list

List resources in state

terraform state show <resource>

Show resource details

terraform state rm <resource>

Remove resource from state

terraform import <addr> <id>

Import existing resource

terraform refresh

Update state with real infrastructure

Workspaces

terraform workspace list

List workspaces

terraform workspace new <name>

Create new workspace

terraform workspace select <name>

Switch workspace

terraform workspace delete <name>

Delete a workspace