An enterprise SaaS architecture cannot survive in a single AWS account. We decouple infrastructure using AWS Organizations into isolated accounts:
Every environment and service layer maintains its own state file. Never share a single terraform.tfstate across environments.
# backend.tf - Secured with KMS, versioning, and DynamoDB state locking
terraform {
backend "s3" {
bucket = "acme-corp-prod-tfstate-347166961665"
key = "compute/eks-cluster/terraform.tfstate"
region = "us-east-1"
dynamodb_table = "acme-corp-prod-tflocks"
encrypt = true
kms_key_id = "arn:aws:kms:us-east-1:347166961665:key/tfstate-key"
}
}
Mandatory S3 Bucket Policy: Deny all non-TLS traffic (aws:SecureTransport: false) and enforce server-side encryption with AWS KMS.
Infrastructure components have vastly different lifecycles. A VPC changes twice a year; an EKS nodegroup or Helm release changes daily. Grouping them together is dangerous.
environments/
โโโ live/
โ โโโ prod/
โ โ โโโ 00-bootstrap/ # IAM roles, KMS keys, baseline policies
โ โ โโโ 10-network/ # VPC, Transit Gateway, NAT Gateways
โ โ โโโ 20-database/ # Aurora PostgreSQL, ElastiCache Redis
โ โ โโโ 30-compute/ # EKS cluster, Karpenter provisioners
โ โ โโโ 40-addons/ # ArgoCD, ExternalDNS, Cert-Manager
โ โโโ staging/
โโโ modules/
โโโ vpc/
โโโ aurora-postgresql/
โโโ eks-cluster/
Every pull request triggers an automated validation pipeline before any engineer can apply changes:
tflint, checkov, and tfsec to catch open security groups (0.0.0.0/0 on port 22) and unencrypted EBS volumes before review.infracost on PRs to provide exact monthly dollar deltas for infrastructure additions.terraform plan via GitHub Actions with AWS OIDC, posting structured diff outputs directly into the GitHub pull request comment.terraform plan -detailed-exitcode -no-color || exit_code=$?
if [ $exit_code -eq 2 ]; then
echo "CRITICAL: Infrastructure drift detected in production!"
# Dispatch alert to SRE webhook
fi
Whether you're planning a complex cloud migration, optimizing Kubernetes reliability, or designing autonomous AI workflows, I'm always open to discussing architecture and technical challenges with engineering teams.
Connect with Naveed on LinkedIn →Splitting Terraform state across multiple AWS accounts and directory layers minimizes the blast radius of any individual apply operation. Monolithic state files result in slow plan times (15+ minutes), dangerous concurrency locks, and catastrophic failure modes where an error in a shared resource damages unrelated production systems.
Never pass secrets directly through Terraform variables or resources if avoidable, because Terraform state files store sensitive values in unencrypted JSON. Instead, manage secrets via AWS Secrets Manager or HashiCorp Vault, inject secret ARNs into application manifests, and use tools like External Secrets Operator (ESO) inside Kubernetes to retrieve secrets at runtime.
Drift is detected by running automated scheduled CI/CD jobs (e.g. via GitHub Actions or Spacelift) executing terraform plan -detailed-exitcode daily. If exit code 2 is returned (indicating drift), an alert is dispatched to Slack/PagerDuty. Prevention is achieved by strictly revoking AWS console write access in production accounts.