Terraform | Simple 2-Tier AWS architecture


Project summary:
IAM Role:
- create IAM role with access to s3 and ec2
Networking and security:
Create 1 VPC
Create 4 subnet
Create 1 public subnet (app-tier) in az1
Create 1 public subnet (app-tier) in az2
Create 1 private subnet (db-tier) in az1
Create 1 private subnet (db-tier) in az2
Create 1 Internet Gateway attach to VPC
Create 1 Route table in VPC
Create 1 route table and attach to igw
Associate to app-tier public subnet (az1, az2)
Create 3 security group in VPC
sg-1 for load balancer with inbound rule http→80, my laptop IP
sg-2 in public subnet for app tier with inbound rule http→80, my laptop IP and http→80, sg-1
sg-3 in private subnet for db tier with inbound rule tcp→3306, sg-2
Database Deployment:
Create subnet group in RDS add 2 private subnet for db tier
Create aws RDS instance
Load Balancing and Auto scaling deployment:
Create AMI create AMI from running app tier instance
Create target group
Create LB
Create launch template
Create auto scaling
The complete terraform code for this project is available in my GitHub repo.
Subscribe to my newsletter
Read articles from Ilayaraja Veerakalai directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Ilayaraja Veerakalai
Ilayaraja Veerakalai
DevOps Engineer with a strong background in Configuration Management and support roles, skilled in tools like AWS, Docker, Kubernetes, Terraform, and Ansible. I focus on automating processes, improving system performance, and making networks scalable and secure in cloud environments.