Skip to content

Comments

ec2: Add AWS-managed launch template tags to EC2 instances#116

Open
nik-localstack wants to merge 3 commits intolocalstack:localstackfrom
nik-localstack:fix/ec2/launch-template-tags-on-instance
Open

ec2: Add AWS-managed launch template tags to EC2 instances#116
nik-localstack wants to merge 3 commits intolocalstack:localstackfrom
nik-localstack:fix/ec2/launch-template-tags-on-instance

Conversation

@nik-localstack
Copy link

Motivation

The only way to verify that the correct launch template is used when creating an instance, is through the tags "aws:ec2launchtemplate:id" and "aws:ec2launchtemplate:version"

Changes

  • Adds "aws:ec2launchtemplate:id" and "aws:ec2launchtemplate:version" tags to an ec2 instance when created from a launch template
  • Fixes the version selection logic to select the $Default version instead of $Latest

@nik-localstack nik-localstack force-pushed the fix/ec2/launch-template-tags-on-instance branch from 5cb7d12 to 1696f9b Compare February 20, 2026 15:36
@nik-localstack nik-localstack self-assigned this Feb 20, 2026
@nik-localstack nik-localstack marked this pull request as ready for review February 20, 2026 16:54
@nik-localstack
Copy link
Author

@bentsku / @giograno any concerns here from the persistence perspective ?

Copy link
Member

@viren-nadkarni viren-nadkarni left a comment

Choose a reason for hiding this comment

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

Moto-Ext is frozen for all changes to backend, which this PR is doing. Until the state management work is ongoing though, we may be able to make some changes to Moto backends. That said, wherever possible, we want to prefer adding logic to LocalStack providers. We won't be able to accept any changes after that.

assert instance["Tags"] == [{"Key": "k", "Value": "v"}]
finally:
# Clean up launch template
ec2_client.delete_launch_template(LaunchTemplateId=template_id)
Copy link
Member

Choose a reason for hiding this comment

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

  • I think the test is trying to do too many things. It is hard for me to form a mental model of what's happening considering how many parameters there are. Please restructure this into separate tests per scenario.
  • Why not use fixture setup/teardown instead of try-finally blocks?

Copy link
Author

Choose a reason for hiding this comment

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

Good point, I split it in multiple tests.
Fixture with setup / teardown similar to localstack is not straightforward for aws validated tests in moto.
I would prefer to keep things simple here and invest in better testing in localstack side that we have a better setup for this kind of testing. WDYT ?

"aws:ec2launchtemplate:id": template_version.template.id,
"aws:ec2launchtemplate:version": str(template_version.number),
}
)
Copy link
Member

Choose a reason for hiding this comment

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

Can't this change be made in LS EC2 provider?

Copy link
Author

Choose a reason for hiding this comment

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

It can, but we won't have access to the template_version that moto actually picks for this instance creation.

Copy link
Member

@viren-nadkarni viren-nadkarni left a comment

Choose a reason for hiding this comment

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

Thanks for reorganising the tests. I was wondering whether we could get rid of the nested try-finally blocks...


finally:
# Clean up launch template
ec2_client.delete_launch_template(LaunchTemplateId=template_id)
Copy link
Member

Choose a reason for hiding this comment

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

It should be possible to add an equivalent of the cleanups fixture from LS to avoid this nesting, no?

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.

2 participants