Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EC2: launch templates created by CloudFormation have a generated name if not provided #7135

Merged
merged 3 commits into from
Dec 18, 2023

Conversation

skinitimski
Copy link
Contributor

Purpose

Fixes a bug in the creation of launch templates via CloudFormation. If your template has more than one unnamed launch template, creation will fail with

botocore.exceptions.ClientError: An error occurred (InvalidLaunchTemplateName.AlreadyExistsException) when calling the CreateStack operation: Launch template name already in use.

This is because moto's implementation expects that the resource have a LaunchTemplateName property even though it is optional.

@@ -233,6 +233,10 @@ def random_launch_template_id() -> str:
return random_id(prefix=EC2_RESOURCE_TO_PREFIX["launch-template"], size=17)


def random_launch_template_name() -> str:
return f"LaunchTemplate_{random_resource_id(size=12)}"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not quite right, it is closer to what is produced by cloudformation.utils.random_suffix -- but importing random_suffix is circular.

This is probably close enough.

Copy link

codecov bot commented Dec 18, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (d44d05c) 95.87% compared to head (d36d311) 95.88%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #7135   +/-   ##
=======================================
  Coverage   95.87%   95.88%           
=======================================
  Files         834      834           
  Lines       82233    82237    +4     
=======================================
+ Hits        78844    78850    +6     
+ Misses       3389     3387    -2     
Flag Coverage Δ
servertests 35.79% <25.00%> (-0.01%) ⬇️
unittests 95.82% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@bblommers bblommers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thanks for the fix @skinitimski!

@bblommers bblommers added this to the 4.2.13 milestone Dec 18, 2023
@bblommers bblommers changed the title Assign names to all launch templates created by CloudFormation EC2: launch templates created by CloudFormation have a generated name if not provided Dec 18, 2023
@bblommers bblommers merged commit 40891c6 into getmoto:master Dec 18, 2023
32 checks passed
@skinitimski skinitimski deleted the feature/timski-lt-names branch December 18, 2023 22:11
Copy link
Contributor

This is now part of moto >= 4.2.13.dev3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants