Skip to main content

Terraform Micro Cheatsheet

Daily Driver

  • terraform init → Initialize working directory
  • terraform plan → Preview changes before apply
  • terraform apply → Apply changes to infrastructure
  • terraform destroy → Tear down infrastructure
  • terraform fmt → Format code to standard style
  • terraform validate → Validate syntax and configs
  • terraform state list → Show tracked resources
  • terraform state show → Inspect resource details
  • terraform refresh → Sync state with real infrastructure
  • terraform taint <res> → Force resource recreation
  • TF_LOG=DEBUG terraform apply → Enable detailed logs
Mnemonic: Init → Plan → Apply → Destroy → Format → Validate → State → Refresh → Debug.

Basics & Workflow

Purpose: Quick reference for everyday Terraform commands and project setup.

  • 1.1 Commands Cheatsheet
    • Core commands: init, plan, apply, destroy, fmt, validate.
    • State commands: state list, state show, refresh, taint.
    • Debugging flag: TF_LOG.
    • Mnemonic: “Init → Plan → Apply → Destroy → Format → Validate → State → Refresh.”
  • 1.2 File Structure Cheatsheet
    • .tf files: main, variables, outputs.
    • terraform.tfstate and terraform.tfvars.
    • Module folder layout.
    • Mnemonic: “Main → Vars → Outputs → State → Modules.”
  • 1.3 State Management Cheatsheet
    • Local vs remote state.
    • Commands: state list, state rm, state mv.
    • Workspaces for environment separation.
    • Mnemonic: “List → Show → Refresh → Move → Remote.”

Core Constructs

Purpose: Syntax and usage of Terraform’s building blocks.

  • 2.1 Providers Cheatsheet
    • Provider block syntax.
    • Authentication methods (AWS, Azure, GCP).
    • Aliases for multi‑provider configs.
  • 2.2 Resources Cheatsheet
    • Resource block syntax.
    • Arguments, lifecycle rules (create_before_destroy, prevent_destroy).
    • Dependencies (depends_on).
  • 2.3 Variables & Outputs Cheatsheet
    • Variable types: string, number, bool, list, map.
    • Default values, sensitive variables.
    • Outputs with output blocks.
  • 2.4 Data Sources Cheatsheet
    • Syntax: data "aws_ami" "example" {}.
    • Fetching external info (AMI IDs, secrets).
    • Linking data sources to resources.

Advanced Features

Purpose: Tools for scaling and complex deployments.

  • 3.1 Modules Cheatsheet
    • Module syntax: source, version.
    • Input/output variables.
    • Best practices for reusability.
  • 3.2 Expressions Cheatsheet
    • Interpolation: ${var.name}.
    • Conditionals: count = var.enabled ? 1 : 0.
    • Loops: for_each, count.
  • 3.3 Provisioners Cheatsheet
    • local-exec and remote-exec.
    • When to use vs configuration management tools.
  • 3.4 Workspaces Cheatsheet
    • Commands: workspace new, workspace select, workspace list.
    • Use cases: dev, staging, prod separation.

Cloud‑Specific

Purpose: Quick reference for common resources in each cloud.

  • 4.1 AWS Cheatsheet
    • VPC, Subnets, Security Groups.
    • EC2, S3, RDS, ALB basics.
  • 4.2 Azure Cheatsheet
    • Resource Group, VNet, NSG.
    • VM, Blob Storage, SQL Database.
  • 4.3 GCP Cheatsheet
    • VPC, Firewall rules.
    • Compute Engine, Cloud Storage, Cloud SQL.

Multi‑Cloud & Collaboration

Purpose: Managing multiple providers and team workflows.

  • 5.1 Multi‑Cloud Providers Cheatsheet
    • AWS + Azure + GCP provider blocks.
    • Aliases for multiple regions/providers.
  • 5.2 Terraform Cloud Cheatsheet
    • Workspaces, remote state.
    • Sentinel policies.
    • Variable sets.
  • 5.3 CI/CD Cheatsheet
    • Pipeline stages: validate, plan, apply.
    • GitHub Actions config snippet.
    • Best practices for approvals.

Debugging & Governance

Purpose: Troubleshooting and enforcing compliance.

  • 6.1 Debugging Cheatsheet
    • Commands: plan, refresh, taint.
    • Logs: TF_LOG=DEBUG.
    • Drift detection.
  • 6.2 Governance Cheatsheet
    • Tagging standards.
    • Sentinel/OPA policy examples.
    • Cost optimization tips (Infracost, reserved instances).

The Hackers Notebook

This detailed plan ensures each cheatsheet is category‑focused, bite‑sized, and practical. Learners can use them as quick references during projects, interviews, or daily DevOps work.


Tips, Tricks, Roadmaps, Resources, Networking, Motivation, Guidance, and Cool Stuff ♥

Updated on Dec 24, 2025