A demonstration of Infrastructure as Code (IaC) using Terraform to provision and manage AWS cloud resources efficiently and consistently.
This project showcases best practices for managing AWS infrastructure using Terraform. It includes VPC setup, EKS cluster provisioning, RDS database, S3 storage, and comprehensive security configurations.
- Infrastructure as Code: Terraform
- Cloud Provider: AWS
- Container Orchestration: Amazon EKS
- Database: Amazon RDS (PostgreSQL)
- Storage: Amazon S3
- Monitoring: CloudWatch
terraform-aws-infra-demo/
βββ main.tf # Main Terraform configuration
βββ variables.tf # Input variables definition
βββ outputs.tf # Output values
βββ terraform.tfvars.example # Environment variables template
βββ modules/ # Reusable Terraform modules
β βββ vpc/
β βββ eks/
β βββ rds/
β βββ s3/
βββ environments/ # Environment-specific configs
β βββ dev/
β βββ staging/
β βββ prod/
βββ README.md
- VPC: Custom VPC with public/private subnets
- Internet Gateway: Public internet access
- NAT Gateway: Outbound internet for private subnets
- Route Tables: Proper routing configuration
- Security Groups: Controlled access rules
- EKS Cluster: Managed Kubernetes cluster
- Worker Nodes: Auto-scaling node groups
- Load Balancer: Application Load Balancer (ALB)
- Auto Scaling: Dynamic scaling based on demand
- RDS PostgreSQL: Managed database service
- Multi-AZ: High availability setup
- Backup: Automated backup configuration
- Encryption: Data encryption at rest and in transit
- S3 Buckets: Object storage with versioning
- Lifecycle Policies: Cost optimization
- Encryption: Server-side encryption
- Access Logging: Audit trail
# Install Terraform
brew install terraform
# Install AWS CLI
brew install awscli
# Configure AWS credentials
aws configure-
Clone the repository:
git clone https://github.com/hamelin123/terraform-aws-infra-demo.git cd terraform-aws-infra-demo -
Initialize Terraform:
terraform init
-
Plan the deployment:
terraform plan -var-file="environments/dev/terraform.tfvars" -
Apply the configuration:
terraform apply -var-file="environments/dev/terraform.tfvars" -
Verify deployment:
terraform output
# terraform.tfvars example
aws_region = "ap-southeast-1"
environment = "dev"
project_name = "demo-infra"
# VPC Configuration
vpc_cidr = "10.0.0.0/16"
availability_zones = ["ap-southeast-1a", "ap-southeast-1b"]
# EKS Configuration
kubernetes_version = "1.28"
node_instance_type = "t3.medium"
node_min_size = 1
node_max_size = 3
# RDS Configuration
db_instance_class = "db.t3.micro"
db_name = "demo_db"
db_username = "admin"# Example module usage
module "vpc" {
source = "./modules/vpc"
vpc_cidr = var.vpc_cidr
availability_zones = var.availability_zones
environment = var.environment
}
module "eks" {
source = "./modules/eks"
cluster_name = "${var.project_name}-${var.environment}"
vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.private_subnet_ids
node_groups = var.node_groups
}- VPC + NAT Gateway: ~$45
- EKS Cluster: ~$73
- RDS (t3.micro): ~$15
- S3 Storage (100GB): ~$2.3
- Total Estimated: ~$135/month
- EKS Nodes: 1-3 t3.medium instances
- Database: PostgreSQL 14, 20GB storage
- Network: Multi-AZ deployment
- Monitoring: CloudWatch integration
- Private Subnets: Database and worker nodes isolation
- Security Groups: Least privilege access
- NACLs: Additional network layer protection
- VPN Gateway: Secure remote access (optional)
- Encryption: All data encrypted at rest and in transit
- KMS: AWS Key Management Service integration
- IAM Roles: Fine-grained permissions
- S3 Bucket Policies: Secure object access
- AWS Config: Resource compliance monitoring
- CloudTrail: API call logging
- GuardDuty: Threat detection (optional)
- Backup: Automated backup strategies
- Multi-Environment: Dev, Staging, Production ready
- Modular Design: Reusable infrastructure components
- Auto Scaling: Dynamic resource scaling
- High Availability: Multi-AZ deployment
- Cost Optimized: Right-sized resources
- Monitoring Ready: CloudWatch integration
terraform {
backend "s3" {
bucket = "terraform-state-demo-bucket"
key = "dev/terraform.tfstate"
region = "ap-southeast-1"
encrypt = true
dynamodb_table = "terraform-state-lock"
}
}- Remote State: S3 backend with DynamoDB locking
- Workspace: Environment isolation
- Versioning: State file versioning enabled
- Encryption: State encryption at rest
# Format Terraform files
terraform fmt -recursive
# Validate configuration
terraform validate
# Show current state
terraform show
# Import existing resources
terraform import aws_instance.example i-1234567890abcdef0
# Destroy infrastructure
terraform destroy -var-file="environments/dev/terraform.tfvars"- Fork the repository
- Create a feature branch
- Test with
terraform plan - Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
ποΈ Infrastructure as Code Made Simple
Built with π for Cloud Engineers