Handle edge case where you can end up with double dashes in target group names

This commit is contained in:
William Richard 2018-04-12 14:48:37 -04:00
parent 81381cd035
commit eb018c01a5
No known key found for this signature in database
GPG Key ID: F7F8BA4DDBE1ABED
2 changed files with 5 additions and 1 deletions

View File

@ -252,6 +252,10 @@ def generate_resource_name(resource_type, stack_name, logical_id):
name_prefix = '{0}-{1}'.format(stack_name, logical_id)
my_random_suffix = random_suffix()
truncated_name_prefix = name_prefix[0:32 - (len(my_random_suffix) + 1)]
# if the truncated name ends in a dash, we'll end up with a double dash in the final name, which is
# not allowed
if truncated_name_prefix.endswith('-'):
truncated_name_prefix = truncated_name_prefix[:-1]
return '{0}-{1}'.format(truncated_name_prefix, my_random_suffix)
else:
return '{0}-{1}-{2}'.format(stack_name, logical_id, random_suffix())

View File

@ -1584,5 +1584,5 @@ def test_create_target_groups_through_cloudformation():
# and one named MyTargetGroup
assert len([tg for tg in target_group_dicts if tg['TargetGroupName'] == 'MyTargetGroup']) == 1
assert len(
[tg for tg in target_group_dicts if tg['TargetGroupName'].startswith('test-stack-test')]
[tg for tg in target_group_dicts if tg['TargetGroupName'].startswith('test-stack')]
) == 2