A robust, scalable AWS infrastructure project demonstrating multi-availability zone deployment with Application Load Balancer, Auto Scaling, and Route 53 integration using Terraform.
This project showcases enterprise-grade AWS infrastructure automation using Infrastructure as Code (IaC) principles. It deploys a highly available web application across multiple availability zones with automatic scaling capabilities and load balancing.
- High Availability: Deployed across 3 availability zones (us-east-1a, us-east-1b, us-east-1c)
- Auto Scaling: Automatically scales based on CPU utilization (target: 50%)
- Load Balancing: Application Load Balancer distributes traffic across healthy instances
- Custom Domain: Route 53 integration for custom domain mapping
- Security: Proper security groups with minimal required access
- Monitoring: Health checks and target tracking for optimal performance
- Infrastructure as Code: Terraform
- Cloud Provider: AWS
- Compute: EC2 instances (Amazon Linux 2023)
- Load Balancing: Application Load Balancer (ALB)
- Auto Scaling: Auto Scaling Groups with target tracking
- Networking: VPC with public/private subnets across 3 AZs
- DNS: Route 53 for domain management
- Web Server: Python HTTP server serving static content
.
βββ .github/
β βββ workflows/
β βββ deploy-infra.yml # GitHub Actions deployment workflow
β βββ destroy-infra.yml # GitHub Actions destruction workflow
βββ application-load-balancer.tf # ALB configuration and target groups
βββ auto-scaling-group.tf # ASG, launch template, and scaling policies
βββ backend.tf # Terraform backend configuration
βββ hosted-record.tf # Route 53 DNS records
βββ locals.tf # Local variables and common tags
βββ outputs.tf # Output values
βββ security-groups.tf # Security group definitions
βββ variables.tf # Input variables
βββ vpc.tf # VPC and subnet configuration
βββ user_data.sh # EC2 instance initialization script
βββ stress-instance.sh # CPU stress testing utility
βββ README.md # Project documentation
- AWS CLI configured with appropriate credentials
- Terraform installed (version 1.7.0+)
- Domain registered in Route 53 (or hosted zone available)
- GitHub repository with proper secrets and variables configured (for CI/CD deployment)
-
Clone the repository
git clone <repository-url> cd multi-az-load-balancer
-
Initialize Terraform
terraform init
-
Configure variables Create a
terraform.tfvarsfile:hosted_zone_id = "Z1D633PJN98FT9" # Your Route 53 hosted zone ID record_name = "app.yourdomain.com" # Your desired FQDN
-
Plan and apply
terraform plan terraform apply
-
Access your application After deployment, access your application using the provided ALB DNS name or your custom domain.
This project includes automated deployment workflows using GitHub Actions for streamlined DevOps practices.
Repository Secrets:
AWS_ROLE_TO_ASSUME = arn:aws:iam::ACCOUNT-ID:role/GitHubActionsRole
HOSTED_ZONE_ID = Z1D633PJN98FT9
Repository Variables:
AWS_REGION = us-east-1
STATE_BUCKET = your-terraform-state-bucket
RECORD_NAME = app.yourdomain.com
Deploy Infrastructure (deploy-infra.yml)
- Trigger: Manual workflow dispatch
- Purpose: Deploy the complete infrastructure
- Features:
- Terraform formatting validation
- Infrastructure validation
- Plan generation
- Automated deployment
- Uses OpenID Connect (OIDC) for secure AWS authentication
Destroy Infrastructure (destroy-infra.yml)
- Trigger: Manual workflow dispatch
- Purpose: Safely destroy all deployed resources
- Features:
- Validation checks before destruction
- Complete resource cleanup
- Cost optimization
-
Deploy Infrastructure:
- Go to Actions tab in your GitHub repository
- Select Deploy Infrastructure workflow
- Click Run workflow
- Monitor the deployment progress
-
Destroy Infrastructure:
- Go to Actions tab in your GitHub repository
- Select Destroy Infrastructure workflow
- Click Run workflow
- Confirm resource destruction
- Automated Deployment: No need for local Terraform setup
- Consistent Environment: Same deployment process across all environments
- Security: Uses AWS IAM roles with temporary credentials
- Audit Trail: Complete deployment history and logs
- Collaboration: Team members can deploy without local AWS credentials
- Desired Capacity: 2 instances
- Minimum: 1 instance
- Maximum: 3 instances
- Scaling Trigger: CPU utilization β₯ 50%
- VPC CIDR: 10.0.0.0/16
- Public Subnets: 10.0.101.0/24, 10.0.102.0/24, 10.0.103.0/24
- Private Subnets: 10.0.1.0/24, 10.0.2.0/24, 10.0.3.0/24
- ALB Security Group: Allows HTTP (port 80) from internet
- ASG Security Group: Allows HTTP (port 80) from ALB only
Use the included stress testing script to simulate high CPU usage:
# SSH into an EC2 instance and run:
chmod +x stress-instance.sh
./stress-instance.shThis will trigger the auto scaling policy and demonstrate horizontal scaling.
The ALB performs health checks every 15 seconds on the root path ("/") with the following configuration:
- Healthy threshold: 2 consecutive successful checks
- Unhealthy threshold: 3 consecutive failed checks
- Timeout: 5 seconds
After deployment, you'll receive:
- ALB DNS Name: Public endpoint for your application
- Route 53 Record: Custom domain pointing to the ALB
Each EC2 instance serves a simple webpage displaying:
- Confirmation message ("It works! β¨")
- Instance ID for load balancing verification
- Infrastructure as Code: Complete infrastructure defined in version-controlled Terraform files
- High Availability: Multi-AZ deployment ensuring resilience
- Auto Scaling: Responsive to demand changes
- Security: Least privilege access with proper security groups
- Modularity: Clean separation of concerns across multiple files
- Documentation: Comprehensive project documentation
- Testing: Included tools for testing auto-scaling behavior
- CI/CD Integration: Automated deployment pipelines with GitHub Actions
- GitOps: Infrastructure changes managed through Git workflows
Deploy Infrastructure Workflow (deploy-infra.yml)
- Authentication: Uses AWS IAM roles with OpenID Connect (OIDC) for secure, temporary credentials
- Validation: Terraform format checking and configuration validation
- Planning: Generates and reviews execution plans before deployment
- State Management: Remote state storage in S3 with proper backend configuration
- Error Handling: Graceful handling of deployment failures
- Manual Trigger: Workflow dispatch for controlled deployments
Destroy Infrastructure Workflow (destroy-infra.yml)
- Safety Checks: Validation before resource destruction
- Complete Cleanup: Removes all deployed AWS resources
- Cost Control: Prevents unnecessary cloud spending
- Manual Trigger: Prevents accidental infrastructure destruction
- No Long-lived Credentials: Uses temporary AWS credentials via OIDC
- Least Privilege: IAM roles with minimal required permissions
- Secret Management: Sensitive data stored in GitHub Secrets
- Audit Trail: Complete deployment history in GitHub Actions logs
- Environment Isolation: Separate workflows for different environments
To destroy the infrastructure and avoid charges:
terraform destroyUse the Destroy Infrastructure GitHub Actions workflow:
- Navigate to Actions β Destroy Infrastructure
- Click Run workflow
- Monitor the destruction process in the workflow logs
| Variable | Description | Type | Required |
|---|---|---|---|
hosted_zone_id |
Route 53 hosted zone ID for your domain | string | Yes |
record_name |
FQDN to publish as an ALIAS (e.g., app.example.com) | string | Yes |
This project demonstrates proficiency in:
- AWS core services (EC2, ALB, ASG, VPC, Route 53)
- Terraform infrastructure automation and state management
- High availability architecture design across multiple AZs
- Auto scaling and load balancing concepts
- Security best practices with least privilege access
- GitHub Actions Workflows: Automated infrastructure deployment pipelines
- Infrastructure as Code (IaC): Version-controlled infrastructure definitions
- GitOps: Git-based workflow for infrastructure changes
- Security: OIDC integration for secure cloud authentication without long-lived credentials
- Pipeline Design: Multi-stage deployment with validation, planning, and execution phases
- Environment Management: Consistent deployment across different environments
- Monitoring & Validation: Automated health checks and deployment verification
- Rollback Strategies: Safe infrastructure destruction and cleanup procedures
- State Management: Remote Terraform state with S3 backend
- Secret Management: Secure handling of sensitive configuration via GitHub Secrets
- Automation: Fully automated deployment without manual intervention
- Audit & Compliance: Complete deployment history and change tracking
- Cost Optimization: Automated resource cleanup to prevent unnecessary charges
Author: Fredy Lemus
Project Type: DevOps Infrastructure Automation
Technology Focus: AWS, Terraform, Infrastructure as Code
