Terraform ELB Target Group Migration with create_before_destroy: Controlling Traffic Shift Order
22K reputation · 22 Jun 2020, 08:50 UTC
Terraform ELB Target Group Migration with create_before_destroy
The goal is to migrate a small application behind an AWS Elastic Load Balancer (ELB) target group without downtime by using Terraform's lifecycle { create_before_destroy = true } to provision a replacement target group before destroying the original.
However, Terraform does not control the order in which the ELB registers targets or deregisters the old group, and the health-check timing is external to the plan. This creates uncertainty about whether the new target group will be healthy and receiving traffic before the old one is drained, which could cause a brief request gap.
We need to decide whether to rely on Terraform's depends_on to enforce ordering, to adjust ELB health-check grace periods, or to introduce external automation (e.g., AWS CodeDeploy, Lambda) that verifies the new target group's health before allowing the destroy step.
Should we add an explicit depends_on on the ELB listener rule or target group attachment to guarantee the new group is created first?
Is adjusting the ELB health-check interval and timeout sufficient to ensure the new group is considered healthy before traffic is shifted?
Do we require external tooling to poll the target group health and only then proceed with the destroy step?