Skip to content

feat(ec2): version launch templates (#456) - #477

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/456-launch-template-versions
Aug 2, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/456-launch-template-versions

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

What

EC2 launch templates are now versioned. Adds the four version operations —
CreateLaunchTemplateVersion, ModifyLaunchTemplate,
DescribeLaunchTemplateVersions, DeleteLaunchTemplateVersions — and makes a
launch resolve which version supplies its parameters instead of always
reading the template's latest data.

Why

DescribeLaunchTemplates returns only summary fields (createTime,
createdBy, defaultVersionNumber, latestVersionNumber,
launchTemplateId, launchTemplateName) — no launchTemplateData at
all
. DescribeLaunchTemplateVersions is the only operation that returns a
template's parameters, so without it a consumer cannot assert what a template
actually stored.

Behaviour worth reviewing

An absent LaunchTemplate.Version means the default version, not the
latest.
From LaunchTemplateSpecification: "Default: The default version of
the launch template." This was #456's own flagged open question. Getting it
backwards stays invisible until a consumer pins a default and keeps shipping
new versions — hence TestEC2_RunInstances_AbsentVersionMeansDefault, which
sets up default 1 against latest 3 so an inverted resolution fails loudly.
$Latest / $Default are matched case-insensitively.

SourceVersion is asymmetric. Named: the new version inherits the
source's parameters and the request's overwrite the corresponding ones.
Omitted: the version holds only what the request names. That asymmetry is
the one a consumer gets wrong, so it has its own subtest.

Deleting the default fails that item, at HTTP 200. The operation reports
per-version outcomes, so one request naming both the default and a
non-default produces one entry in each set with a 200 overall. A caller
checking only the HTTP status sees success.

The fleet path now forwards its version. fleetPools has always parsed
LaunchTemplateConfig's version; nothing consumed it, so a fleet pinned to
version 1 silently launched whatever the template held latest.

Two deviations from the plan

1. The default-version rejection ships as unexpectedError, not an invented
code.
The plan left the code open. It cannot be captured: the API reference
and the CLI help both state the prohibition but publish no code or message;
moto does not implement DeleteLaunchTemplateVersions at all; LocalStack does
not either; issue-tracker searches found nothing. Two facts settled it —
ResponseError.code is a closed six-value enum in three independent AWS
SDKs (launchTemplateIdDoesNotExist | launchTemplateIdMalformed | launchTemplateNameDoesNotExist | launchTemplateNameMalformed | launchTemplateVersionDoesNotExist | unexpectedError) with no default-version
member, and the operation's whole response is built for per-item partial
failure. So the item carries unexpectedError — the modeled catch-all — with
the reference's own sentence as the message, both labelled inferred in the
code, the CHANGELOG and docs/services.md. Another emulator invents
InvalidLaunchTemplateVersion.NotAllowed, which a typed SDK would deserialize
as an unknown enum variant; that was the trap avoided.

2. The account-wide DescribeLaunchTemplateVersions form is included, not
scoped out.
The plan deferred it to a follow-up issue. describeLaunchTemplates
already walks the lt_ids: index, so the form was a reuse rather than a new
query — no issue needs filing.

Migration

A template stored before this change unmarshals with Versions == nil and
synthesizes version 1 from LatestData on read
(EC2LaunchTemplate.TemplateVersions). That is the entire migration — no
event rewriting. LatestData is deliberately retained and kept in sync;
its doc comment says why, so a reader does not delete it as redundant.
TestEC2_LaunchTemplate_PreVersioningStateStillWorks writes pre-#456 JSON
directly into state as the gate.

Verification

From the repo root: gofmt -l . clean, go build ./..., go vet ./...,
golangci-lint run ./... → 0 issues, make test (race) all packages ok,
make docs-reference docs-reference-check docs-versions pass,
go test -C test/e2e ./... ok.

Mutation-tested, three mutants, all killed:

Mutation Killed by
absent version → latest instead of default AbsentVersionMeansDefault, VersionSpecifiers/absent_means_the_default, Fleet_HonorsLaunchTemplateVersion/absent_means_the_default
let the default version be deleted 3 DeleteLaunchTemplateVersions subtests
remove the TemplateVersions() synthesis all 4 migration subtests

Also walked end-to-end against a live server as a consumer would: create →
CreateLaunchTemplateVersion(SourceVersion=1, ImageId=…) returning version 2
with inherited instance type and key name → ModifyLaunchTemplate →
DescribeLaunchTemplateVersions (defaultVersion true only on 2) →
RunInstances with no version launching v2's AMI →
DeleteLaunchTemplateVersions(2,1) returning 200 with one entry in each set.

Closes #456

Add CreateLaunchTemplateVersion, ModifyLaunchTemplate,
DescribeLaunchTemplateVersions and DeleteLaunchTemplateVersions, and resolve
a launch's template version rather than always reading the latest data.

DescribeLaunchTemplates returns only summary fields — no launchTemplateData
at all — so DescribeLaunchTemplateVersions is the only operation through
which a consumer can read a template's parameters back.

An absent LaunchTemplate.Version resolves to the template's *default*
version, per LaunchTemplateSpecification ("Default: The default version of
the launch template"), not its latest. Getting that backwards stays
invisible until a consumer pins a default and keeps shipping new versions.
$Latest and $Default are accepted case-insensitively.

CreateLaunchTemplateVersion's SourceVersion is asymmetric: named, the new
version inherits the source's parameters and the request overwrites the
corresponding ones; omitted, the version holds only what the request names.

DeleteLaunchTemplateVersions reports per-item outcomes, so deleting the
default fails that item at HTTP 200 while others in the same request
succeed. ResponseError.code is a closed six-value enum with no
default-version member and no capture of AWS's actual rejection exists, so
the item carries unexpectedError — the modeled catch-all — with the API
reference's own sentence as the message. Both are inferred, not captured.

The fleet path now forwards its config's launch template version, which
fleetPools has always parsed but nothing consumed: a fleet naming version 1
previously launched whatever the template held latest.

A template stored before this change carries no versions array and
synthesizes version 1 from LatestData on read, so no event rewriting is
needed and existing templates keep working.

Closes #456
@codecov

codecov Bot commented Aug 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.87841% with 69 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/ec2_launchtemplate_versions.go 80.46% 42 Missing and 25 partials ⚠️
emulator/ec2_plugin.go 95.91% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 5b97fd6 into main Aug 2, 2026
16 checks passed
@scttfrdmn scttfrdmn mentioned this pull request Aug 2, 2026
@scttfrdmn
scttfrdmn deleted the fix/456-launch-template-versions branch August 2, 2026 22:02
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: CreateLaunchTemplateVersion and ModifyLaunchTemplate are unregistered

1 participant