Module Architecture
Start with a flat module structure. One module per environment (dev, staging, prod) with shared modules for VPC, ECS, and RDS. Avoid deep nesting — it creates cognitive overhead that slows down your team.
State Management
Always use remote state with S3 backend and DynamoDB locking. Never commit state files to git. Use workspaces for environment isolation. This prevents the most common Terraform disasters: state conflicts and accidental resource deletion.
CI/CD Integration
Run terraform plan on every PR and post the output as a comment. Require manual approval before terraform apply. Use GitHub Actions withOIDC authentication to AWS — no more long-lived access keys in your secrets.