Terragrunt AWS Infrastructure This repository contains Terragrunt configurations for managing AWS infrastructure across multiple environments (dev and prod).
The infrastructure includes:
VPC : Multi-AZ VPC with public and private subnetsEKS Cluster : Kubernetes 1.28 with ARM64 (Graviton) node groupsBastion Host : Secure SSH access point with SSM supportS3 Buckets : Separate buckets for static content and user uploadsCloudFront : CDN distribution for static content deliveryRoute53 : DNS management with custom recordsterragrunt/├── terragrunt.hcl # Root configuration with S3 backend├── modules/ # Reusable Terraform modules│ ├── vpc/│ ├── eks/│ ├── bastion/│ ├── s3/│ ├── cloudfront/│ └── route53/├── dev/ # Development environment│ ├── terragrunt.hcl│ ├── vpc/│ ├── eks/│ ├── bastion/│ ├── s3/│ ├── cloudfront/│ └── route53/└── prod/ # Production environment ├── terragrunt.hcl ├── vpc/ ├── eks/ ├── bastion/ ├── s3/ ├── cloudfront/ └── route53/AWS CLI : Configure with appropriate credentials
Terraform : Version >= 1.5
Terragrunt : Latest version
Environment Variables : Set your AWS account ID
export AWS_ACCOUNT_ID=" 123456789012" Update Root Configuration Editterragrunt.hcl to set:
AWS region Account ID Backend bucket name Update Environment Variables For each environment (dev/prod):
VPC CIDR : Updatevpc_cidr in{env}/vpc/terragrunt.hclDomain Names : Update domain names in{env}/route53/terragrunt.hclSSH Access : Add your SSH public key in{env}/bastion/terragrunt.hclIP Restrictions : Configureallowed_cidr_blocks for bastion accessFirst deployment creates the S3 bucket and DynamoDB table automatically:
cd dev/vpcterragrunt initDeploy all resources in dependency order:
# Deploy VPC firstcd dev/vpcterragrunt apply# Deploy EKS clustercd ../eksterragrunt apply# Deploy remaining resourcescd ../bastion&& terragrunt applycd ../s3&& terragrunt applycd ../cloudfront&& terragrunt applycd ../route53&& terragrunt applyDeploy All Resources at Once Userun-all to deploy everything:
cd devterragrunt run-all applyCreates VPC with configurable CIDR 3 public and 3 private subnets across AZs NAT gateways (single for dev, multi-AZ for prod) Internet gateway and route tables Tagged for EKS integration Kubernetes version 1.28 ARM64 (Graviton) node groups OIDC provider for IRSA Essential add-ons (VPC CNI, CoreDNS, kube-proxy) CloudWatch logging Environment-specific scaling Dev Configuration:
SPOT instances 2 min, 3 max nodes t4g.medium instances Prod Configuration:
ON_DEMAND instances 3 min, 10 max nodes t4g.large/xlarge instances Private API endpoint ARM-based Amazon Linux 2 Elastic IP for consistent access SSM Session Manager support Security group with SSH access Optional SSH key authentication Access via SSM:
aws ssm start-session --target< instance-id> Access via SSH:
ssh -i~ /.ssh/id_rsa ec2-user@< bastion-ip> Two buckets created:
Static Content Bucket
Server-side encryption CORS configuration CloudFront OAI access Public access blocked User Content Bucket
Versioning (prod only) Lifecycle rules (prod only) Multipart upload cleanup Glacier archival after 180 days HTTPS-only distribution Custom caching behaviors CORS support Custom error pages Optional custom domains Geo-restriction support Cache Behaviors:
Default: 1 hour TTL Static assets: 1 day TTL Images: 1 day TTL Hosted zone management CloudFront A/AAAA records Bastion host record Custom DNS records Domain verification TXT records CAA records for SSL Accessing the EKS Cluster Update kubeconfig:
aws eks update-kubeconfig --name dev-eks-cluster --region us-west-2kubectl get nodes Single NAT gateway SPOT instances for EKS nodes Smaller instance types Reduced log retention (7 days) Versioning disabled Lifecycle rules disabled Multi-AZ NAT gateways for HA ON_DEMAND instances Larger instance types Extended log retention (30 days) Versioning enabled Lifecycle rules enabled cd dev/vpcterragrunt init -upgradeterragrunt applyEditkubernetes_version in{env}/eks/terragrunt.hcl and apply:
cd dev/eksterragrunt applyDestroy in reverse dependency order:
cd devterragrunt run-all destroyBastion Access : Restrictallowed_cidr_blocks to known IPsSSH Keys : Use SSH keys instead of passwordsEKS API : Use private endpoint for productionS3 Encryption : Server-side encryption enabled by defaultCloudFront : HTTPS-only with modern TLS versionsIAM Roles : Use IRSA for pod-level permissionsVPC : Private subnets for EKS nodesIf S3 bucket exists:
terragrunt init -reconfigure Ensure dependencies are deployed first:
terragrunt graph-dependencies Release DynamoDB lock:
terragrunt force-unlock< lock-id> Check node status:
kubectl get nodeskubectl describe node< node-name> Environment-Specific Configurations Single NAT gateway SPOT instances Smaller resources Public EKS endpoint Minimal log retention Multi-AZ NAT gateways ON_DEMAND instances Larger resources Private EKS endpoint Extended log retention Versioning enabled For issues or questions:
Check Terragrunt logs:terragrunt apply --terragrunt-log-level debug Review AWS CloudWatch logs Consult AWS documentation This infrastructure code is provided as-is for reference and customization.