This project provisions a scalable NGINX web server environment on AWS using Terraform. It demonstrates real-world Infrastructure as Code (IaC) practices including custom networking, security configuration, auto-scaling, load balancing and automated server provisioning without manual intervention.
The infrastructure deployed via Terraform includes:
- Custom VPC – 10.0.0.0/16
- Public Subnet in multiple Availability Zones (for ALB)
- Private Subnet in multiple Availability Zones (for ASG instances)
- Internet Gateway for outbound traffic to the internet
- Route Table for proper network routing
- Security Group allowing:
- ALB Security Group – allows HTTP (80) and HTTPS (443) from the internet
- ASG Instances Security Group – allows HTTP from ALB and SSH from admin IP
- Launch Template to provision EC2 instances with NGINX
- Auto Scaling Group (ASG) to manage EC2 instances
- Application Load Balancer (ALB) to distribute traffic across ASG instances
- Target Group for ALB to route traffic to ASG instances
Once deployed, Terraform provisions:
- NGINX web server instances running in private subnets
- Fully functional Application Load Balancer with public access
- Auto Scaling to maintain desired instance count The page served displays:
Hello from Terraform via NGINX ASG!
Terraform outputs the ALB URL for easy access
| Concept | Description |
|---|---|
| Terraform | Infrastructure as Code |
| Providers | ProvidersConfigures AWS as the target cloud platform |
| Resources | Defines VPC, subnets, EC2 instances, security groups, ALB, ASG |
| Variables | Parameterizes inputs like SSH IP or instance types |
| Outputs | Exposes ALB URL and other useful info |
| User Data | Automates server setup (NGINX) on instance boot |
| Modules | Infrastructure can be modularized for reuse |
| Dependencies | Terraform ensures resources are created in the correct order |
terraform-aws-nginx-asg-alb/
│
├── main.tf # Core infrastructure resources (VPC, ALB, ASG, Launch Template)
├── variables.tf # Input variables
├── provider.tf # AWS provider configuration
├── outputs.tf # Output values (ALB URL, Subnet IDs, Security Group IDs)
├── README.md # Project documentation
└── .gitignore # Files excluded from Git
git clone https://github.com/thomasasamba-bot/terraform-aws-nginx-asg-alb.git
cd terraform-aws-nginx-asg-albterraform initexport TF_VAR_my_ip="YOUR_PUBLIC_IP/32"Example:
export TF_VAR_my_ip="41.90.162.115/32"terraform applyType yes when prompted.
After deployment, Terraform will output:
load_balancer_url = http://<ALB-DNS-NAME>
Paste the URL into your browser to see the hosted NGINX page.
- SSH access is restricted to a single admin IP address
- ALB handles public traffic; EC2 instances remain in private subnets
- No credentials or private keys are stored in the repository
- Infrastructure changes are fully managed by Terraform – no manual steps
terraform destroy --auto-approveThis project demonstrates ability to:
- Building AWS infrastructure fully via Terraform
- Automating server setup using user_data
- Implementing Auto Scaling and Load Balancing
- Managing networking and security with Terraform resources
- Following IaC best practices for reproducible deployments
Thomas
Cloud & DevOps Engineer ☁️🚀
