🏆 Team Leaderboard

Live Terraform progress across all teammates

↻ Loading…

🧠 Knowledge Quiz

Test your Terraform knowledge

☁ Firebase Cross-Device Sync

Sync Terraform lab progress across devices.

Quick setup:
1. console.firebase.google.com → Create project
2. Realtime Database → Create (test mode)
3. Project Settings → Web app → copy config

📄 Terraform Cheatsheet

Essential commands, HCL syntax & patterns — quick reference

⚡ Core CLI Commands

terraform initDownload providers & modules, init backend
terraform validateCheck HCL syntax (no API calls)
terraform fmtAuto-format HCL to canonical style
terraform plan -out=tfplanPreview changes, save plan file
terraform apply tfplanApply saved plan (no prompt)
terraform apply -auto-approveApply without confirmation (CI)
terraform destroy -target=resDestroy specific resource only
terraform output -jsonOutputs as machine-readable JSON
terraform refreshSync state with real cloud (deprecated)
terraform plan -refresh-onlyModern drift detection v1.1+

🗄 State Commands

terraform state listList all managed resource addresses
terraform state show <addr>Show attributes of a resource
terraform state mv A BRename/move resource in state
terraform state rm <addr>Remove resource from state (not cloud)
terraform import <addr> <id>Import existing cloud resource
terraform state pullDownload & print remote state
terraform state push <file>Upload state file Dangerous
terraform workspace new devCreate new workspace
terraform workspace select prodSwitch workspace

📝 HCL — Variables & Outputs

variable "instance_type" {
  type        = string
  default     = "t3.micro"
  description = "EC2 instance type"
  sensitive   = false
  validation {
    condition     = contains(["t3.micro","t3.small"], var.instance_type)
    error_message = "Invalid instance type."
  }
}

output "bucket_arn" {
  value     = aws_s3_bucket.demo.arn
  sensitive = false
}

locals {
  name_prefix = "${var.project}-${var.env}"
  common_tags = { Env = var.env, Owner = "ops" }
}

🔁 Meta-Arguments

# count — simple repetition
resource "aws_iam_user" "devs" {
  count = 3
  name  = "dev-${count.index}"
}

# for_each — named resources
resource "aws_iam_user" "team" {
  for_each = toset(["alice","bob"])
  name     = each.key
}

# lifecycle
lifecycle {
  create_before_destroy = true
  prevent_destroy       = true
  ignore_changes        = [tags]
}

🏗 Modules

# Local module
module "vpc" {
  source      = "./modules/vpc"
  vpc_cidr    = "10.0.0.0/16"
  environment = var.environment
}

# Registry module
module "vpc" {
  source  = "terraform-aws-modules/vpc/aws"
  version = "~> 5.0"
  cidr    = "10.0.0.0/16"
}

# Access output
resource ... { vpc_id = module.vpc.vpc_id }

🔧 Backends & Providers

# S3 backend with DynamoDB locking
terraform {
  required_version = ">= 1.5"
  required_providers {
    aws = { source = "hashicorp/aws", version = "~> 5.0" }
  }
  backend "s3" {
    bucket         = "my-tf-state"
    key            = "prod/terraform.tfstate"
    region         = "us-east-1"
    dynamodb_table = "tf-lock"
    encrypt        = true
  }
}

🧪 Built-in Functions

toset(list)Convert list → set (dedup)
tomap(obj)Convert object → map
flatten(list)Flatten nested lists
merge(m1,m2)Merge maps (m2 overrides)
lookup(map,key,def)Safe map key lookup
length(val)Count items in list/map/string
contains(list,val)Check list membership
format(fmt,args...)String formatting
file(path)Read file contents as string
jsonencode(val)Encode value as JSON string

🔒 CI/CD & Security

TF_VAR_name=valSet variable via env var
TF_LOG=DEBUGEnable verbose logging
checkov -d .Scan IaC for misconfigurations
tfsec .Security static analysis
terraform testRun .tftest.hcl tests v1.6+
terragrunt run-all planPlan across all modules
-var-file=prod.tfvarsLoad env-specific variables
🏆

Terraform Expert!

You've completed all Terraform labs!

0
Total Labs
0
Completed
0/0
Phase 1-3 Done
0/0
Phase 4-6 Done
Overall Terraform Progress0%