Repository navigation
fix(ec2): carry a launch template's network interface to the launch (#444) - #448
Merged
Merged
Conversation
…444) CreateLaunchTemplate accepted LaunchTemplateData.NetworkInterface.1.* and stored none of it, so an instance launched from such a template landed in a substrate-chosen subnet — a wrong answer returned confidently, with a 200 and a plausible-looking instance rather than an error. This hit exactly the templates configured the way AWS requires. AWS's RequestLaunchTemplateData has no top-level SubnetId member, so a network interface is the only place a template can name a subnet, and the only place AssociatePublicIpAddress exists at all. It also produced a confusing asymmetry: a CreateFleet override's subnet was honored while the same subnet named in the template was not, so the feature looked half-working rather than absent. The fix is an ordering change as much as a parsing one. The call-level NetworkInterface.1.SubnetId fallback used to run *before* the launch template resolved, where there was nothing yet to fall back to. Template networking is now consulted after the template resolves and only when the call did not supply it, which is AWS's precedence: request > template > default VPC. A fleet override still wins over both, because launchFleetPool passes it as a request-level SubnetId. AssociatePublicIPAddress is stored as a string, not a bool: absent ("use the subnet default"), "true" and "false" are three observable states and a bool collapses the first two. The interface's group list is read from SecurityGroupId.N, which is what real SDKs send — the AWS model gives the Groups member the locationName "SecurityGroupId", correcting the .Groups.N the issue suggested — with Groups.N accepted as a secondary spelling for hand-built requests. Only interface index 1 is modeled, matching runInstances; that limit is now documented rather than surprising. Two small helpers fall out: indexedParams collects a 1-based indexed param list under several spellings (replacing two hand-rolled loops), and parseLaunchTemplateData moves the template parsing out of createLaunchTemplate so the network-interface rules are stated once. Deliberately out of scope: a call that passes both an explicit ImageId and a launch template still ignores the template entirely, because the resolution block is gated on imageID == "". Real AWS merges per field. That predates this change, affects InstanceType/KeyName/groups equally, and needs its own per-field precedence matrix. Filed as a follow-up. Tests are a new ec2_launchtemplate_test.go reproducing the issue's own four-case table: A (template NI via RunInstances) and D (template NI via CreateFleet with no override) flip from failing to passing, while B (call-level SubnetId) and C (fleet override) are regression guards for the reordering. Plus explicit precedence, both group spellings, the three-valued public-IP preference, and the no-interface fall-through to the default VPC. Mutation-tested: dropping the subnet fallback fails exactly A and D; dropping the public-IP fallback fails only the "true" row. The template's group list is asserted through RunInstances' cross-VPC InvalidGroup.NotFound validation rather than a read of the instance, because instances do not echo a groupSet at all yet — that is the other half of #444 and lands next. Refs #444
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This was referenced Aug 1, 2026
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.
Problem
CreateLaunchTemplateacceptedLaunchTemplateData.NetworkInterface.1.*and stored none of it, so an instance launched from such a template landed in a substrate-chosen subnet — a wrong answer returned confidently, with a 200 and a plausible-looking instance rather than an error.This hit exactly the templates configured the way AWS requires. Verified against the EC2 model:
RequestLaunchTemplateDatahas no top-levelSubnetIdmember, so a network interface is the only place a template can name a subnet, and the only placeAssociatePublicIpAddressexists at all.It also produced a confusing asymmetry — a
CreateFleetoverride's subnet was honored while the same subnet named in the template was not, so the feature looked half-working rather than absent.The fix is an ordering change as much as a parsing one
The call-level
NetworkInterface.1.SubnetIdfallback ran before the launch template resolved, where there was nothing yet to fall back to. Template networking is now consulted after the template resolves and only when the call did not supply it:SubnetIdorNetworkInterface.1.SubnetIdCreateFleetoverride'sSubnetIdrunInstancesas a request-level value)AssociatePublicIPAddressis stored as a string, not a bool: absent ("use the subnet default"),"true"and"false"are three observable states, and a bool collapses the first two.Correction to the issue's suggested parameter name
#444 proposes parsing
.Groups.N. The AWS model gives that member thelocationNameSecurityGroupId, so real SDKs sendSecurityGroupId.N— that is the primary spelling here, withGroups.Naccepted as a secondary form for hand-built requests (mirroring whatrunInstancesalready does).Deliberately out of scope
A call passing both an explicit
ImageIdand a launch template still ignores the template entirely, because the resolution block is gated onimageID == "". Real AWS merges per field. That predates this change, affectsInstanceType/KeyName/groups equally, and needs its own per-field precedence matrix. Filed as a follow-up.Tests
New
emulator/ec2_launchtemplate_test.go(there was no launch-template test file), reproducing the issue's own four-case table:RunInstancesSubnetIdCreateFleetoverrideCreateFleet, no overridePlus explicit precedence assertions, both group spellings, the three-valued public-IP preference, the no-interface fall-through to the default VPC, and a launch-twice check that the template round-trips through state.
Mutation-tested: dropping the subnet fallback fails exactly A and D and leaves B and C green — the issue's table reproduced. Dropping the public-IP fallback fails only the
"true"row.The template's group list is asserted through
runInstances' cross-VPCInvalidGroup.NotFoundvalidation rather than a read of the instance, because instances do not echo agroupSetat all yet — that is the other half of #444 and lands in the next PR.Note on closing
This PR does not close #444. It ships the network-interface half; the
groupSethalf follows immediately, and that PR carries theCloses.Verification
gofmt,go build,go vet,golangci-lint run ./...(0 issues),make test(race),test/e2e,make docs-reference-check docs-versions— all clean, re-run after rebasing onto the merged #443.Refs #444