Repository navigation
fix(ec2): carry a launch template's tags and instance profile to the launch (#471) - #481
Merged
Merged
Conversation
…launch (#471) A launch template's TagSpecifications and IamInstanceProfile were accepted by CreateLaunchTemplate and stored nowhere, so a template that tagged its instances produced untagged ones and a template naming a role produced an instance with none — with nothing failing to say so. The tag half is the more damaging: DescribeInstances --filters tag:Env,Values=prod is how IaC finds the resources it just created, and it returned nothing, so an assertion on the tags the template asked for could not pass however it was written. Neither field could even be read back before this release, because DescribeLaunchTemplates carries no launchTemplateData; #456's DescribeLaunchTemplateVersions is what makes the round-trip assertable. Template tags replace rather than merge. A request naming Env=req against a template naming Env=tmpl,Team=x yields Env=req alone — Team is not inherited. The reference gives no TagSpecifications-specific merge semantics, only the general "Any additional parameters that you specify for the new instance overwrite the corresponding parameters included in the launch template", and replacement is that rule applied to the whole specification. Substrate's own aws:ec2:fleet-id stamp does not count as the request naming tags. A fleet instance already carries that reserved key by the time the merge runs, so the fallback tests for a non-reserved key rather than for an empty set — had it tested emptiness, a fleet launched from a tagging template would have silently lost the template's tags, the very defect this closes, on the path #443 added. It is the same reserved-key exclusion #469's counter uses. A template's tags are subject to both tag rules, so a template is not a second unrestricted tagging path: a reserved key or more than 50 tags is rejected at CreateLaunchTemplate and at CreateLaunchTemplateVersion — the latter after any SourceVersion inheritance, so an inherited violation is caught rather than propagated. The launch checks again, deliberately: a template written straight into state by a replayed event log can predate these checks, and that launch is where the key would otherwise be applied. Two scope limits, stated rather than implied. Only the instance scope is stored: a template may also scope tags to volume, network-interface or spot-instances-request, none of which substrate models, so those specifications are recorded nowhere rather than misapplied. And the profile is stored as the one string the request supplied, so DescribeLaunchTemplateVersions echoes it in whichever member it arrived in — arn for an arn:-prefixed value, name otherwise. DescribeInstances still surfaces it as an ARN either way, because AWS's instance response shape has no name member; synthesizing the missing member for a template read-back would report the template as naming something the caller never wrote. ec2LaunchTagsForResource becomes a one-line wrapper over a prefix-taking ec2TagSpecificationTags rather than a fifth copy of the TagSpecification.N walk, so all five callers still share exactly one walk to check. All 19 mutations of the new logic are killed by the new tests, including the two overlay arms and the launch-path limit check.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #471
The defect
A launch template's
TagSpecificationsandIamInstanceProfilewere accepted byCreateLaunchTemplateand stored nowhere, so a template that tagged its instances produced untagged ones and a template naming a role produced an instance with none — with nothing failing to say so.The tag half is the more damaging.
DescribeInstances --filters tag:Env,Values=prodis how IaC finds the resources it just created, and it simply returned nothing, so an assertion on the tags the template asked for could not pass however it was written.Neither field could even be read back before this release:
DescribeLaunchTemplatescarries nolaunchTemplateData, so #456'sDescribeLaunchTemplateVersionsis what makes the round-trip assertable. That is why #456 came into this milestone rather than #471's acceptance criterion being weakened.Behaviour
Template tags replace rather than merge. A request naming
Env=reqagainst a template namingEnv=tmpl,Team=xyieldsEnv=reqalone —Teamis not inherited. The reference gives noTagSpecifications-specific merge semantics, only the general "Any additional parameters that you specify for the new instance overwrite the corresponding parameters included in the launch template", and replacement is that rule applied to the whole specification rather than a per-field citation.Substrate's own
aws:ec2:fleet-idstamp does not count as the request naming tags. A fleet instance already carries that reserved key by the time the merge runs, so the fallback tests for a non-reserved key (ec2HasUserTags) rather than for an empty set. Had it tested emptiness, a fleet launched from a tagging template would have silently lost the template's tags — the very defect this PR closes, on the path #443 added. It is the same reserved-key exclusion #469's counter uses, and it has its own test.A template's tags are subject to both tag rules, so a template is not a second unrestricted tagging path. A reserved key or more than 50 tags is rejected at
CreateLaunchTemplateand atCreateLaunchTemplateVersion— the latter after anySourceVersioninheritance, so an inherited violation is caught rather than propagated. The launch checks again, deliberately and not redundantly: a template written straight into state by a replayed event log can predate these checks, and that launch is where the key would otherwise be applied.Scope, stated rather than implied
volume,network-interfaceorspot-instances-request, none of which substrate models, so those specifications are recorded nowhere rather than misapplied to the instance.DescribeLaunchTemplateVersionsechoes it in whichever member it arrived in —arnfor anarn:-prefixed value,nameotherwise.DescribeInstancesstill surfaces it as an ARN either way, because AWS's instance response shape has no name member; synthesizing the missing member for a template read-back would report the template as naming something the caller never wrote.Sources
Verified against the AWS reference per CLAUDE.md:
ResponseLaunchTemplateDataspells the membersiamInstanceProfileandTagSpecificationSet.N, while the request spells themIamInstanceProfileandTagSpecification.N— so a round-trip test has to use both names. Noted in the code, because getting it backwards produces a template with no tags and nothing to say so.LaunchTemplateIamInstanceProfileSpecification(response) has exactlyarnandname.LaunchTemplateTagSpecification(response) hasresourceTypeandTagSet.N.Nameis preferred overArnwhen both are given. AWS documents neither as authoritative, so that choice is substrate's, made for consistency with the call-level path — said so in the field comment rather than implied to be a citation.DescribeLaunchTemplateVersions' two worked XML examples show onlyimageId/instanceTypeinsidelaunchTemplateData, so both new members' element shapes come from the member tables rather than a worked example.Refactor
ec2LaunchTagsForResourcebecomes a one-line wrapper over a prefix-takingec2TagSpecificationTags, rather than a fifth copy of theTagSpecification.Nwalk.LaunchTemplateData.TagSpecification.1.Tag.1.Keyis the same indexed list one level in, and the whole point of PR #468's shared parser is that there is exactly one walk to check. The six existing callers are untouched.Tests
New in
emulator/ec2_launchtemplate_test.go:CreateLaunchTemplate→DescribeLaunchTemplateVersionsround-trips both fields, in both theNameandArnforms.tag:Env,Values=prodfilter finds it — the half a consumer's IaC depends on.Teamis absent.SourceVersioninheritance does not outrank the new version's own tags or profile — one arm per overlay field.CreateLaunchTemplate; a reserved key is rejected atCreateLaunchTemplateVersionand the version is not appended; exactly 50 template tags launch.aws:ec2:fleet-id.Verification
From the repo root:
gofmt -l .,go build ./...,go vet ./...clean;golangci-lint run ./...→ 0 issues;make test(race) green;make docs-reference docs-reference-check docs-versionsclean;go test -C test/e2e ./...green.Mutation-tested: 19 mutations of the new logic, all 19 killed. Three survived the first pass and each bought a test — the two
ec2OverlayTemplateDataarms (now covered by theSourceVersioncase) and the launch-path tag-limit check (now covered by the stored-51-tag case).Docs
docs/services.md— the "not parsed at all" line is replaced; the per-field precedence table gains four rows; the instance-scope-only limit, the fleet-stamp interaction, the two tag rules and the profile echo direction are all stated. The reserved-key and 50-tag sections gain their launch-template halves.