๐ Repo: github.com/Push/terraform-aws-labs/day06
๐ฏ Goal: Move from monolithic main.tf โ organized, maintainable, team-ready project layout.
๐ก Terraform merges all .tf files into one config โ but how you organize them determines:
- โ Readability (Can a new engineer understand it in 5 mins?)
- โ Maintainability (Can you update VPC without touching S3?)
- โ Collaboration (Can two people work on
networking/andcompute/safely?)- โ Git hygiene (No accidental state/secret commits!)
โ Bad: One main.tf with 2,000 lines
โ Good: Logical, consistent, documented structure
/day06/)day06/
โโโ backend.tf # ๐ Remote state config (S3 + locking)
โโโ provider.tf # ๐ AWS provider + default tags
โโโ variables.tf # ๐ฅ Input variables (with validation!)
โโโ locals.tf # ๐งฎ Computed values (DRY logic)
โโโ main.tf # ๐๏ธ *Only* top-level resources (or empty!)
โโโ vpc.tf # ๐ Networking (VPC, subnets, IGW)
โโโ storage.tf # ๐ชฃ S3, EBS, EFS
โโโ outputs.tf # ๐ค Exposed values (VPC ID, bucket ARN)
โโโ terraform.tfvars # ๐๏ธ Default values (dev)
โโโ .gitignore # ๐ซ Block sensitive files
โโโ README.md # ๐ Project docs
โ Key Principle:
โSeparation of Concernsโ โ group by function, not just resource type.
backend.tf โ Remote State (Isolated & Secure)# ๐ backend.tf
terraform {
required_version = ">= 1.5.0"
required_providers {
aws = { source = "hashicorp/aws", version = "~> 6.7.0" }
}
# โ
S3 backend (encrypted + locked)
backend "s3" {
bucket = "tech-tutorials-push-terraform-state-2025"
key = "dev/terraform.tfstate"
region = "us-east-1"
encrypt = true
use_lock_file = true # ๐ Native S3 locking (no DynamoDB!)
}
}
โ Why separate?
terraform {} blockterraform init -reconfigure