This project creates a fully automated 3-tier architecture in AWS using Terraform. It includes a Virtual Private Cloud (VPC) that spans two Availability Zones (AZs), public and private subnets, a database subnet, two NAT Gateways, an Application Load Balancer (ALB), and a database. The infrastructure is built in a single AWS region, following best practices for high availability and fault tolerance.
- VPC: A custom Virtual Private Cloud that spans across two Availability Zones.
- Subnets:
- Public Subnets: For internet-facing resources like the ALB.
- Private Subnets: For backend application servers.
- DB Subnets: For the RDS instance, isolated for security.
- NAT Gateways: One per AZ, to allow private subnets to access the internet for updates.
- Application Load Balancer (ALB): Distributes traffic to application servers across multiple AZs.
- Database (RDS): A managed database in the isolated DB subnet for secure access.
- Security Groups: For controlling inbound and outbound traffic to resources.
- Route Tables: For routing traffic between subnets and to the internet.
- AWS Account: To create resources in AWS.
- Terraform: To define and provision the infrastructure.
- AWS CLI: To configure AWS credentials for Terraform. or you can use AWS IAM Role to provide access to Terraform.
3-tier-architecture/
├── modules/
│ ├── alb/
│ ├── asg/
│ ├── key/
│ ├── nat/
│ ├── rds/
│ ├── sg/
│ └── vpc/
├── terraform/
│ ├── main.tf
│ ├── backend.tf
│ ├── variables.tf
│ ├── provider.tf
│ ├── terraform.tfvars
│ └── outputs.tf
└── README.md
- Clone the repository:
git clone "https://github.com/dhanu0510/terraform_aws_3_tier.git"
cd terraform_aws_3_tier
- Initialize the Terraform configuration:
cd terraform
terraform init
- Setup AWS CLI or add AWS credentials to
provider.tf
:
provider "aws" {
region = "us-east
access_key
secret_key
}
-
Modify the
terraform.tfvars
file with your settings or leave it as default: -
Plan and Apply the Terraform configuration:
terraform plan
terraform apply
- Get the ALB DNS name from the Terraform output:
terraform output alb_dns_name
- Open the ALB DNS name in a web browser to access the application.
- Destroy the Terraform resources:
terraform destroy