This Terraform project implements a 3-Tier Architecture on AWS, dividing the application infrastructure into three logical layers:
- Presentation Layer (Public Subnet + ALB)
- Application Layer (EC2 Instances in Private Subnets with Auto Scaling)
- Data Layer (Amazon RDS in Private Subnets)
The infrastructure is deployed in a custom VPC, spans two Availability Zones, and uses modular Terraform design for scalability, reusability, and best practices.
Sets up the base networking layer, ensuring secure and isolated deployment.
Resources Created:
aws_vpc: Virtual Private Cloudaws_subnet: Public and Private subnets (across AZ1 and AZ2)aws_internet_gateway: Internet access for public subnetaws_nat_gateway: Allows private subnet instances to reach the internetaws_route_tableandaws_route_table_association: Routing rules
📌 Subnet Usage:
- Public Subnet: For Load Balancer, NAT Gateway
- Private Subnet: For EC2 (App Layer) and RDS (Data Layer)
Serves as the public-facing entry point for web traffic.
Resources Created:
aws_lb: Application Load Balanceraws_lb_listener: For HTTP/HTTPS ports (80/443)aws_lb_target_group: Routes requests to EC2 instancesaws_security_group: Controls access to the ALB
✅ ALB ensures traffic routing, health checks, and scaling integration.
Provisions and manages EC2 instances in the Application Layer.
Resources Created:
aws_launch_template: EC2 config (AMI, instance type, user data)aws_autoscaling_group: Automatically scales instancesaws_cloudwatch_metric_alarm: CPU or custom metric-based alarmsaws_autoscaling_policy: Scaling rules (e.g., CPU > 70%)
🚀 EC2 instances are deployed in private subnets and are registered with the ALB target group.
Deploys a secure and fault-tolerant Data Layer using Amazon RDS.
Resources Created:
aws_db_subnet_group: Deploys DB across private subnets in multiple AZsaws_db_instance: Managed relational DB (e.g., MySQL/PostgreSQL)
🔒 No public access is provided; only EC2s from the Application Layer can access RDS.
The root module orchestrates all other modules and wires the dependencies via Terraform inputs and outputs.
Example Integrations:
albmodule receivesvpc_idandpublic_subnet_idsfromnetworkingasgmodule receivestarget_group_arnfromalb, andsubnet_idsfromnetworkingdatabasemodule receivesprivate_subnet_idsfromnetworking
- User sends request via the internet.
- ALB in public subnet receives request.
- Request forwarded to EC2 instance in private subnet.
- EC2 processes request and, if needed, queries RDS in another private subnet.
- Response flows back via ALB.
- 🔒 Security: Private subnets, IAM roles, SGs, and no public DB access
- 📈 Scalability: Auto Scaling and Load Balancing
- 🧩 Modularity: Layered infrastructure via reusable modules
- 🔁 High Availability: Multi-AZ RDS and distributed subnets
.
├── modules/
│ ├── networking/
│ ├── alb/
│ ├── asg/
│ └── database/
├── main.tf
├── variables.tf
├── outputs.tf
└── README.md