Terraform Advanced — Real Project Structure

less than 1 minute read

A production-proven directory layout used by teams managing 50+ services across multiple environments.


The Three-Repo Pattern

Repo 1: infra-modules/          # Reusable modules (versioned via Git tags)
├── vpc/
├── eks/
├── rds/
├── s3/
└── iam/

Repo 2: infra-live/             # Environment-specific configs
├── prod/
│   ├── us-east-1/
│   │   ├── vpc/
│   │   │   ├── main.tf         # module "vpc" { source = "git::...?ref=v2.1.0" }
│   │   │   └── terraform.tfvars
│   │   ├── eks/
│   │   ├── rds/
│   │   └── dns/
│   └── eu-west-1/
│       ├── vpc/
│       └── eks/
├── staging/
│   └── us-east-1/
│       ├── vpc/
│       └── eks/
└── dev/
    └── us-east-1/
        └── vpc/

Repo 3: infra-config/           # Global config (account IDs, CIDR ranges)
└── config.yaml

State Key Convention

{account}/{region}/{service}/terraform.tfstate

Examples:
  prod-account/us-east-1/vpc/terraform.tfstate
  prod-account/us-east-1/eks/terraform.tfstate
  staging-account/us-east-1/vpc/terraform.tfstate

Apply Order (Dependency Graph)

1. vpc           (no dependencies)
2. security      (depends on vpc)
3. rds           (depends on vpc, security)
4. eks           (depends on vpc, security)
5. application   (depends on eks, rds)
6. dns           (depends on application)

💡 Production Tip: Terragrunt automates this dependency ordering with dependency blocks.


What’s Next?

Decide when to use each pattern.

← Hybrid Approach When to Use Each →

Updated: