Production Ready Terraform Configuration for AWS
Multi-environment infrastructure as code for AWS with modular, reusable Terraform configurations supporting development, staging, and production workloads.
terraform/
├── environments/
│ ├── dev/ # Development environment
│ ├── staging/ # Staging environment
│ └── prod/ # Production environment
└── modules/
├── common/ # Shared resources
├── ec2/ # EC2 instances & security groups
├── ecr/ # Elastic Container Registry
├── eks/ # Elastic Kubernetes Service
├── iam/ # IAM roles & policies
├── keypair/ # SSH key management
├── s3/ # S3 storage buckets
└── vpc/ # Network infrastructure
Terraform v1.0+
AWS CLI configured with appropriate credentials
AWS account with necessary permissions
Module
Description
common
Shared resources and configurations
ec2
Instance and security group management
ecr
Elastic Container Registry for Docker images
eks
Elastic Kubernetes Service cluster management
iam
Identity and Access Management roles/policies
keypair
SSH key pair management
s3
Storage bucket with security features
vpc
Network infrastructure and routing
🌍 Environment Specifications
Environment
Instance Type
CIDR Block
Purpose
dev
t2.micro
10.0.0.0/16
Feature development & testing
staging
t2.small
10.1.0.0/16
Pre-production testing
prod
t2.medium
10.2.0.0/16
Live workloads
# 1. Navigate to environment
cd environments/< env> # dev, staging, or prod
# 2. Initialize Terraform
terraform init
# 3. Review changes
terraform plan
# 4. Apply infrastructure
terraform apply
Infrastructure Components
VPC with public/private subnets
EC2 instances for web and application servers
EKS clusters for container orchestration
ECR repositories for Docker images
S3 buckets for storage
IAM roles and policies
Network isolation with security groups
IAM role-based access control
Encryption at rest
Public access blocking
Least privilege principle
Environment-specific resource sizing
Modular, reusable design
Expandable CIDR ranges
Command
Description
terraform init
Initialize working directory
terraform plan
Preview infrastructure changes
terraform apply
Create/update infrastructure
terraform destroy
Destroy all resources
terraform destroy -target=TYPE.NAME
Destroy specific resource
⚠️ Warning : Avoid using terraform destroy --auto-approve in production environments.
Modular structure with DRY principles
Clear separation of concerns
Environment isolation
Network segmentation
Resource isolation
Access controls with encryption
Consistent naming conventions
Environment-specific state files
Remote backend for production