This project creates a complete AWS infrastructure using Terraform, including:
- VPC with public and private subnets across 2 availability zones
- Internet Gateway and NAT Gateways for internet access
- Auto Scaling Group with Launch Template
- Application Load Balancer
- Bastion host for secure access
- Security Groups with appropriate rules
-
Clone this repository
git clone <your-repo-url>
-
Initialize Terraform
terraform init
-
Plan the deployment
terraform plan
-
Apply the configuration
terraform apply
Type
yeswhen prompted.
- SSH into the bastion host using its public IP:
ssh -i /path/to/your/key.pem ubuntu@<bastion-public-ip>
- From the bastion host, SSH into private instances:
ssh -i /path/to/your/key.pem ubuntu@<private-instance-ip>
- Create the web content:
vim index.html
- Start the Python web server:
python3 -m http.server 8000
-
The web application is accessible through the Application Load Balancer
-
Get the Load Balancer DNS name from the Terraform output
-
Access your application at:
http://<load-balancer-dns-name> -
The load balancer forwards traffic to the private instances running the web server on port 8000
- VPC: 10.0.0.0/16 CIDR block
- Public Subnets: 10.0.1.0/24, 10.0.2.0/24
- Private Subnets: 10.0.3.0/24, 10.0.4.0/24
- NAT Gateways: One in each availability zone for private subnet internet access
- Bastion SG: Allows SSH (port 22) from anywhere
- Private SG: Allows SSH from bastion and HTTP (port 8000) from load balancer
- ALB SG: Allows HTTP (port 80) from anywhere
- Min Size: 1 instance
- Max Size: 3 instances
- Desired: 2 instances
- Instance Type: t2.micro
- Infrastructure Deployment: Terraform creates the complete AWS infrastructure
- Bastion Access: Use bastion host to securely access private instances
- Web Server Setup: Create index.html and start Python HTTP server on port 8000
- Load Balancer Integration: ALB automatically detects and routes traffic to healthy instances
- Public Access: Users can access the web application through the load balancer's public endpoint
To destroy all created resources:
terraform destroyType yes when prompted.
