From 867cf078de23e95876c7fc14ba37b37e1e83b5f1 Mon Sep 17 00:00:00 2001 From: Giovanni Torres Date: Tue, 18 May 2021 02:52:39 -0400 Subject: [PATCH] feat: transition elbv2 state to `active` on first describe (#3937) * refactor: parameterize state in elbv2 template response * feat: transition load balancer to active on first describe Closes #3936 --- moto/elbv2/models.py | 13 +++++++++++++ moto/elbv2/responses.py | 4 ++-- tests/test_elbv2/test_elbv2.py | 2 ++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/moto/elbv2/models.py b/moto/elbv2/models.py index 799ba6e96..70951c502 100644 --- a/moto/elbv2/models.py +++ b/moto/elbv2/models.py @@ -381,6 +381,7 @@ class FakeLoadBalancer(CloudFormationModel): vpc_id, arn, dns_name, + state, scheme="internet-facing", ): self.name = name @@ -393,6 +394,7 @@ class FakeLoadBalancer(CloudFormationModel): self.tags = {} self.arn = arn self.dns_name = dns_name + self.state = state self.stack = "ipv4" self.attrs = { @@ -419,6 +421,10 @@ class FakeLoadBalancer(CloudFormationModel): if key in self.tags: del self.tags[key] + def activate(self): + if self.state == "provisioning": + self.state = "active" + def delete(self, region): """ Not exposed as part of the ELB API - used for CloudFormation. """ elbv2_backends[region].delete_load_balancer(self.arn) @@ -517,6 +523,8 @@ class ELBv2Backend(BaseBackend): ): vpc_id = None subnets = [] + state = "provisioning" + if not subnet_ids: raise SubnetNotFoundError() for subnet_id in subnet_ids: @@ -542,6 +550,7 @@ class ELBv2Backend(BaseBackend): subnets=subnets, vpc_id=vpc_id, dns_name=dns_name, + state=state, ) self.load_balancers[arn] = new_load_balancer return new_load_balancer @@ -740,6 +749,8 @@ Member must satisfy regular expression pattern: {}".format( arns = arns or [] names = names or [] if not arns and not names: + for balancer in balancers: + balancer.activate() return balancers matched_balancers = [] @@ -747,6 +758,7 @@ Member must satisfy regular expression pattern: {}".format( for arn in arns: for balancer in balancers: + balancer.activate() if balancer.arn == arn: matched_balancer = balancer if matched_balancer is None: @@ -756,6 +768,7 @@ Member must satisfy regular expression pattern: {}".format( for name in names: for balancer in balancers: + balancer.activate() if balancer.name == name: matched_balancer = balancer if matched_balancer is None: diff --git a/moto/elbv2/responses.py b/moto/elbv2/responses.py index 68fbc8816..235f9bf8d 100644 --- a/moto/elbv2/responses.py +++ b/moto/elbv2/responses.py @@ -706,7 +706,7 @@ CREATE_LOAD_BALANCER_TEMPLATE = """