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

ResourceDescription
aws_launch_template.apiLaunch Template for API instances
aws_autoscaling_group.apiAuto 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 warmup

Info

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:

  1. Launch new instance with new template
  2. Wait for instance to be healthy (warmup period)
  3. Terminate old instance
  4. Repeat until all instances are refreshed
Force Refresh
# Force immediate refresh
terraform apply -replace='module.autoscaling.aws_launch_template.api'