Explaining deregistration delay parameter of aws_lb_target_group resource in Terraform
The aim of this page📝 is to explain the deregistration_delay
parameter in Terraform based on the particular example of a Terraform plan.
2 min readAug 18, 2023
- The
deregistration_delay
parameter is an optional argument for theaws_lb_target_group
resource in Terraform. - It specifies the amount of time, in seconds, for Elastic Load Balancing to wait before changing the state of a deregistering target from draining to unused.
- The range of values for this parameter is 0–3600 seconds, and the default value is 300 seconds.
- When you remove a target from a target group, Elastic Load Balancing waits for the
deregistration_delay
timeout to elapse before completing the deregistration process. - During this time, the target is in the
draining
state and does not receive any new requests. - However, it continues to process any requests that were already in flight when the deregistration process began.
- Once the timeout elapses, the target is moved to the
unused
state and is no longer considered a member of the target group. - A longer
deregistration_delay
can be useful if you want to give in-flight requests more time to complete before the target is deregistered. - This can help to minimize disruption to your users and ensure a smoother transition when you remove targets from the target group.
- On the other hand, a shorter
deregistration_delay
(or a value of 0) can be useful if you want to quickly remove targets from the target group. - This can help to webappmize downtime and ensure that your users are quickly routed to healthy targets.
- The choice of value for this parameter depends on your specific use case and requirements.
CODE
Here is a particular example I have experienced with Terraform:
Terraform will perform the following actions:
### module.ec2.module.webapp_alb.aws_alb_target_group.alb_tg will be updated in-place
~ resource "aws_alb_target_group" "alb_tg" {
~ deregistration_delay = 300 -> 0
id = "arn:aws:elasticloadbalancing:eu-west-1:000000000000:targetgroup/foo-xxx/000000000000"
name = "foo-000000000000"
tags = {
"Name" = "foo-com-example-prod1-webapp-alb"
"tf_module" = "aws_ec2_public_alb"
"tf_module_version" = "1.0.0"
}
# (13 unchanged attributes hidden)
# (2 unchanged blocks hidden)
}
Plan: 0 to add, 1 to change, 0 to destroy.
In this specific plan, it appears that the module.ec2.module.webapp_alb.aws_alb_target_group.alb_tg
resource will be updated in-place. This means that Terraform will modify the existing resource rather than creating a new one. The only change that will be made is that the deregistration_delay
attribute will be changed from 300
to 0
. All other attributes and blocks will remain unchanged.