28 August 2025

Master Terraform Fast - Guide + Cheat Sheet

by Dan.C

Cover Image

Terraform From zero to Hero + Complete Commands Cheat Sheet

If you’ve ever manually clicked through a cloud console to create servers, databases, or networks, you know it can get messy fast. What if you need to replicate the same environment tomorrow—or share it with your team? That’s where Terraform comes in.

Table of Contents

  1. Terraform From Zero to Hero + Complete Commands Cheat Sheet
  2. What is Terraform (and why should you care)?
  3. How Terraform Works (The 4-Step Workflow)
  4. Getting Started with Terraform
  5. Going Deeper: Key Terraform Concepts
  6. Terraform Commands Cheat Sheet
  7. Final Thoughts
  8. You may also like
  9. Conclusion

This post is your from zero to hero guide:


🌍 What is Terraform (and why should you care)?

Terraform is an Infrastructure as Code (IaC) tool. Instead of manually creating resources in AWS, Azure, GCP, or other providers, you describe your infrastructure in declarative configuration files.

Example Analogy

Imagine you’re telling a builder:


🏗️ How Terraform Works (The 4-Step Workflow)

Terraform’s workflow always revolves around four core commands:

  1. Write – You write configuration files (.tf) describing resources.
  2. Init – Terraform downloads the right provider plugins.
  3. Plan – Terraform shows you what will change.
  4. Apply – Terraform makes those changes.

At the end, you can destroy everything with a single command.


🚀 Getting Started with Terraform

Step 1. Install Terraform

Download Terraform from HashiCorp’s official site.

Check installation:

terraform -v

Step 2. Set Up Your First Project

Create a new folder and a file called main.tf.

Inside main.tf, write:

provider "aws" {
  region = "us-east-1"
}

resource "aws_s3_bucket" "demo" {
  bucket = "my-terraform-demo-bucket-12345"
  acl    = "private"
}

What this does:


Step 3. Initialize Terraform

terraform init

This downloads the provider plugin (AWS in this case) into a hidden folder .terraform/.

Without init, Terraform doesn’t know how to talk to AWS.


Step 4. Validate Configuration

terraform validate

Checks for typos and syntax errors. Think of it as a compiler for your infra.


Step 5. Preview the Execution Plan

terraform plan

Shows what Terraform would do:


Step 6. Apply the Plan

terraform apply

Terraform now creates your resources. You’ll be asked to confirm with yes.

Behind the scenes, Terraform also updates its state file (terraform.tfstate). This file keeps track of all resources Terraform manages.


Step 7. Destroy Infrastructure

When you’re done testing:

terraform destroy

Terraform removes everything it created. This is super useful for keeping cloud costs down!


🧠 Going Deeper: Key Terraform Concepts

1. Variables

Instead of hardcoding values, make them dynamic:

variable "region" {
  default = "us-east-1"
}
provider "aws" {
  region = var.region
}

Run with custom variables:

terraform apply -var="region=eu-west-1"

2. Outputs

Show useful information after deployment:

output "bucket_name" {
  value = aws_s3_bucket.demo.bucket
}

View outputs:

terraform output

3. State Management

Terraform keeps track of what it manages in terraform.tfstate.


4. Modules

Think of modules like functions in programming. They package resources into reusable blocks.

Example:

module "network" {
  source     = "./modules/network"
  cidr_block = "10.0.0.0/16"
}

This lets you structure large projects cleanly.


5. Workspaces

Workspaces let you separate environments (dev, staging, prod) while reusing the same configs.

terraform workspace new dev
terraform workspace select dev
terraform apply

🛠️ Terraform Commands Cheat Sheet

Here’s your quick reference. Bookmark this!

Initialization & Setup

terraform init          # Initialize directory (downloads providers)  
terraform validate      # Validate configuration files  
terraform fmt           # Auto-format .tf files  
terraform providers     # Show required providers  

Core Workflow

terraform plan          # Preview changes (dry run)  
terraform apply         # Apply changes  
terraform destroy       # Destroy all managed infrastructure  

State Management

terraform state list                    # List resources in state  
terraform state show <resource>         # Show details of a resource  
terraform state rm <resource>           # Remove a resource from state  
terraform refresh                       # Refresh local state from provider  

Variables & Outputs

terraform output                        # Show outputs  
terraform apply -var="key=value"        # Pass variable at runtime  

Workspaces

terraform workspace list                # List workspaces  
terraform workspace new staging         # Create new workspace  
terraform workspace select staging      # Switch to workspace  

Debugging & Logs

TF_LOG=DEBUG terraform plan             # Debug logs  
TF_LOG=TRACE terraform apply            # Very detailed logs  

🎯 Final Thoughts

Terraform is a powerful tool for managing infrastructure consistently and safely. The learning curve may feel steep at first, but once you understand the workflow (init → plan → apply → destroy) and how state files work, it becomes second nature.

Start small (like creating a single bucket or VM), then explore variables, modules, and remote state as you grow more confident. And whenever you forget a command—come back to the cheat sheet above.

You may also like:


Keep learning, stay inovative. — Dan.C

tags: terraform - infrastructure-as-code - iac - devops - cloud - aws - automation - infrastructure - cloud-computing - cheat-sheet - tutorial - beginners-guide