How do you replace an Auto Scaling group's launch template without downtime?
AdvancedProductionRefactoring, Migration and Drift
Answer
Use create_before_destroy with a name that changes per version (or name_prefix), and an instance_refresh block on the ASG so instances roll gradually with min_healthy_percentage.
instance_refresh {
strategy = "Rolling"
preferences { min_healthy_percentage = 90 }
}
Pair with health checks on the load balancer, and test in staging with realistic traffic.
More on Refactoring, Migration and Drift
What is your workflow for refactoring Terraform safely?IntermediateHow do you rename a resource inside a shared module without breaking consumers?AdvancedHow do you split one state into two without downtime?AdvancedHow do you merge two states?IntermediateHow do you import a large existing environment efficiently?IntermediateHow do you upgrade a major version of the AWS provider?Advanced