This project implements a three-tier architecture on AWS using Terraform for infrastructure as code and Packer for creating custom AMIs. The architecture follows best practices for high availability, scalability, and security.
The application is deployed across three tiers:
-
Web Tier (Frontend)
- Application Load Balancer (ALB)
- Auto Scaling Group (ASG)
- EC2 instances running Nginx
- Public subnets
-
Application Tier (Backend)
- Internal Application Load Balancer (ALB)
- Auto Scaling Group (ASG)
- EC2 instances running PHP/Apache
- Private subnets
-
Database Tier
- Amazon RDS MySQL instance
- Private subnets
- Multi-AZ deployment
- VPC with CIDR 10.0.0.0/16
- Public and private subnets across three availability zones
- Internet Gateway for public internet access
- NAT Gateways for private subnet internet access
- Route tables and associations
- Security groups for each tier
- Custom AMIs built with Packer
- Auto Scaling Groups for both frontend and backend
- Application Load Balancers
- Launch Templates with user data scripts
- RDS MySQL instance
- DB subnet group
- Security group for database access
- AWS CLI configured with appropriate credentials
- Terraform >= 1.0.0
- Packer
- Git
- SSH key pairs for EC2 instances
.
├── packer/
│ ├── frontend/ # Frontend AMI build configuration
│ └── backend/ # Backend AMI build configuration
├── terraform/
│ ├── network/ # VPC, subnets, security groups
│ ├── compute/ # ALBs, ASGs, EC2 instances
│ └── database/ # RDS instance and configuration
├── setup.sh # Setup script
└── cleanup.sh # Cleanup script
-
Clone the repository
git clone https://github.com/ajitinamdar-tech/three-tier-architecture-aws-terraform.git cd three-tier-architecture-aws-terraform
-
Run the setup script
chmod +x setup.sh ./setup.sh
The setup script will:
- Create an S3 bucket for Terraform state
- Build custom AMIs using Packer
- Deploy the infrastructure using Terraform
- Configure the application
To destroy all resources:
chmod +x cleanup.sh
./cleanup.sh
- Security groups restrict access between tiers
- Private subnets for application and database tiers
- Regular security updates through AMI builds
- Auto Scaling based on CPU utilization
- Regular AMI updates through Packer builds
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- AWS Documentation
- HashiCorp Terraform Documentation
- HashiCorp Packer Documentation