Skip to content

fix(ec2): carry a launch template's network interface to the launch (#444) - #448

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/444-lt-network-interface
Aug 1, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/444-lt-network-interface

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Problem

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. Verified against the EC2 model: 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 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:

Source Wins over
The request — SubnetId or NetworkInterface.1.SubnetId everything below
A CreateFleet override's SubnetId the template (it reaches runInstances as a request-level value)
The template's network interface the default VPC

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.

Correction to the issue's suggested parameter name

#444 proposes parsing .Groups.N. The AWS model gives that member the locationName SecurityGroupId, so real SDKs send SecurityGroupId.N — that is the primary spelling here, with Groups.N accepted as a secondary form for hand-built requests (mirroring what runInstances already does).

Deliberately out of scope

A call passing 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

New emulator/ec2_launchtemplate_test.go (there was no launch-template test file), reproducing the issue's own four-case table:

Case Subnet from Before After
A template NI, via RunInstances ❌ ✅
B call-level SubnetId ✅ ✅ (regression guard)
C CreateFleet override ✅ ✅ (regression guard)
D template NI, via CreateFleet, no override ❌ ✅

Plus 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-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 in the next PR.

Note on closing

This PR does not close #444. It ships the network-interface half; the groupSet half follows immediately, and that PR carries the Closes.

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

…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

codecov Bot commented Aug 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.34884% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/ec2_types.go 50.00% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit ec7a413 into main Aug 1, 2026
16 checks passed
@scttfrdmn
scttfrdmn deleted the feat/444-lt-network-interface branch August 2, 2026 22:01
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.

EC2: launch template NetworkInterfaces is dropped, so template-specified subnets are ignored

1 participant