ELBV2 describe_target_health on deregistered target should return a state of "unused" instead of "unavailable"
As per this documentation - https://docs.aws.amazon.com/elasticloadbalancing/latest/application/target-group-health-checks.html
The unavailable state is related to Target.HealthCheckDisabled when health check is disabled and unsed is related to Target.NotRegistered.
However, here - https://github.com/getmoto/moto/blob/7a8a113a2030e0b9679d92c6fdc583ef63f3ef54/moto/elbv2/models.py#L176
unavailable is returned with Target.NotRegistered.
This causes the waiter target_deregistered to always fail after a deregistration since we never reach the unsed state or the InvalidTarget error (https://github.com/boto/botocore/blob/fdfb8b03fb9cebccbbef4cce732901baa073b376/botocore/data/elbv2/2015-12-01/waiters-2.json#L81).
Hi @yairsappir, thanks for raising this. We currently just delete targets when deregistering them, but it sounds like we should still keep track of them. Marking it as a bug to improve this area.
Hi and thanks for the response!
Just wanted to add that when calling describe_target_health on a target that doesn't exist using the regular boto3 api results in a unused state with reason Target.NotRegistered.
So I believe that unused should be returned rather than unavailable in this scenario.
Hi @yairsappir, moto >= 5.0.10.dev18 now returns the correct state for deregistered instances.
when calling describe_target_health on a target that doesn't exist using the regular boto3 api results in a unused state with reason Target.NotRegistered.
When I try to register an unknown EC2 instance, boto3 already throws an error that the instance doesn't exist. Or are you using different targets, like ALB's or Lambda Functions?
Hi @bblommers ,
Thank you for looking at this!
I used this code:
import boto3
elbv2_client = boto3.client('elbv2','us-east-1')
elbv2_client.describe_target_health(TargetGroupArn=target_group_arn,Targets=[{'Id':'i-12345678901234567'}])
Where target_group_arn is a real target group for ec2, and i-12345678901234567 is used as-is.
This also returns State: unused with Reason: Target.NotRegistered
Not sure if that is a bug on AWS side or not though..
Thanks for the explanation @yairsappir! moto >= 5.0.10.dev23 now also returns the Target.NotRegistered in that scenario, so as far as I can tell it behaves exactly like AWS.
I've closes this for now, but feel free to open a new issue if you run into any (other) problems.