09-Auto Scaling
Module creating Auto Scaling Group and Launch Template for API tier
Stage Modulemodules/09-autoscaling
Purpose
Creates ASG for API tier with auto-scaling capability and rolling refresh when Launch Template changes.
Created Resources
| Resource | Description |
|---|---|
| aws_launch_template.api | Launch Template for API instances |
| aws_autoscaling_group.api | Auto Scaling Group for API |
Configuration
ASG Configuration
# terraform.tfvars
asg_min_size = 2 # Minimum instances
asg_max_size = 4 # Maximum instances
asg_desired_capacity = 2 # Desired count
# Rolling refresh settings
asg_refresh_min_healthy_percentage = 50 # Keep 50% healthy during refresh
asg_refresh_instance_warmup = 300 # 5 min warmupInfo
Set asg_min_size = 0 to not launch instances (infra only).
Rolling Refresh
When Launch Template changes (user_data, AMI), ASG automatically performs rolling refresh:
- Launch new instance with new template
- Wait for instance to be healthy (warmup period)
- Terminate old instance
- Repeat until all instances are refreshed
Force Refresh
# Force immediate refresh
terraform apply -replace='module.autoscaling.aws_launch_template.api'