π₯ Spinning Up EC2 Behind an ALB β All with Terraform
π The Problem
Sometimes you just need to test a high-availability setup β EC2 instances behind a load balancer β and donβt want to click through 7 AWS console screens to do it.
I wanted a Terraform module that could:
- β
Launch EC2s (with custom scripts)
- β
Place them behind an Application Load Balancer
- β
Output the public ALB URL instantly
And I wanted it to be reusable, fast, and cloud-ready.
π οΈ The Fix: Simple Terraform + Scalable ALB Setup
I built a Terraform project that:
- π‘ Lets you control the number of EC2 instances with a single variable
- π Lets you pass in your own
user_data
script
- π Sets up security groups and health checks automatically
- π Outputs the ALB DNS for immediate access
The whole thing deploys in minutes and works great for both demos and production prototypes.
π¬ GitHub Link
Code is available here:
π
github.com/chinmaya-chhatre/terraform-alb-project
π What Changed
- βοΈ Cut deploy time for load-balanced EC2s to under 2 minutes
- π§ͺ Used this as a testbed for fault tolerance and config drift experiments
- πΌ Became a personal template for future multi-instance app setups
βοΈ Tradeoffs I Made
- No Auto Scaling (Yet): This setup creates a fixed number of instances β but could evolve into ASG-backed ALB
- Single AZ Default: Starts in one availability zone to keep it simple for testing
- No Remote Backend: Uses local state to stay portable β great for testing, not for teams
π§ What I'd Add Next
- π Add optional Auto Scaling Group integration
- π Enable multi-AZ deployments with one flag
- π¦ Turn this into a reusable Terraform module with versioning
π§΅ Why Iβm Sharing This
Because good infra doesnβt need to be complicated.
Because Terraform should be fun, not frustrating.
And because spinning up load-balanced EC2s should be a one-liner, not a one-day task.
π Bonus Links