Correctly generate resource name for target groups when using cloudformation

They need to have less than 32 character names, so when you don't specify a name
cloudformation generates a name that is less than 32 characters.

And make sure that flake8 passes
This commit is contained in:
William Richard 2018-04-11 18:16:56 -04:00
commit 81381cd035
No known key found for this signature in database
GPG key ID: F7F8BA4DDBE1ABED
3 changed files with 133 additions and 13 deletions

View file

@ -124,10 +124,7 @@ class FakeTargetGroup(BaseModel):
elbv2_backend = elbv2_backends[region_name]
# per cloudformation docs:
# The target group name should be shorter than 22 characters because
# AWS CloudFormation uses the target group name to create the name of the load balancer.
name = properties.get('Name', resource_name[:22])
name = properties.get('Name')
vpc_id = properties.get("VpcId")
protocol = properties.get('Protocol')
port = properties.get("Port")
@ -437,7 +434,7 @@ class ELBv2Backend(BaseBackend):
def create_target_group(self, name, **kwargs):
if len(name) > 32:
raise InvalidTargetGroupNameError(
"Target group name '%s' cannot be longer than '22' characters" % name
"Target group name '%s' cannot be longer than '32' characters" % name
)
if not re.match('^[a-zA-Z0-9\-]+$', name):
raise InvalidTargetGroupNameError(