09-Auto Scaling
Module tạo Auto Scaling Group và Launch Template cho API tier
Stage Modulemodules/09-autoscaling
Mục đích
Tạo ASG cho API tier với khả năng auto-scale và rolling refresh khi thay đổi Launch Template.
Resources được tạo
| Resource | Mô tả |
|---|---|
| aws_launch_template.api | Launch Template cho API instances |
| aws_autoscaling_group.api | Auto Scaling Group cho 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 warmupThông tin
Đặt asg_min_size = 0 để không launch instances (chỉ tạo infra).
Rolling Refresh
Khi thay đổi Launch Template (user_data, AMI), ASG tự động thực hiện rolling refresh:
- Launch instance mới với template mới
- Chờ instance healthy (warmup period)
- Terminate instance cũ
- Lặp lại cho đến khi tất cả instance được refresh
Force Refresh
# Force immediate refresh
terraform apply -replace='module.autoscaling.aws_launch_template.api'