Repository navigation
feat(ec2): version launch templates (#456) - #477
Merged
Merged
Conversation
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 Report❌ Patch coverage is
📢 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.
What
EC2 launch templates are now versioned. Adds the four version operations —
CreateLaunchTemplateVersion,ModifyLaunchTemplate,DescribeLaunchTemplateVersions,DeleteLaunchTemplateVersions— and makes alaunch resolve which version supplies its parameters instead of always
reading the template's latest data.
Why
DescribeLaunchTemplatesreturns only summary fields (createTime,createdBy,defaultVersionNumber,latestVersionNumber,launchTemplateId,launchTemplateName) — nolaunchTemplateDataatall.
DescribeLaunchTemplateVersionsis the only operation that returns atemplate's parameters, so without it a consumer cannot assert what a template
actually stored.
Behaviour worth reviewing
An absent
LaunchTemplate.Versionmeans the default version, not thelatest. From
LaunchTemplateSpecification: "Default: The default version ofthe 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, whichsets up default 1 against latest 3 so an inverted resolution fails loudly.
$Latest/$Defaultare matched case-insensitively.SourceVersionis asymmetric. Named: the new version inherits thesource'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.
fleetPoolshas always parsedLaunchTemplateConfig's version; nothing consumed it, so a fleet pinned toversion 1 silently launched whatever the template held latest.
Two deviations from the plan
1. The default-version rejection ships as
unexpectedError, not an inventedcode. 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
DeleteLaunchTemplateVersionsat all; LocalStack doesnot either; issue-tracker searches found nothing. Two facts settled it —
ResponseError.codeis a closed six-value enum in three independent AWSSDKs (
launchTemplateIdDoesNotExist | launchTemplateIdMalformed | launchTemplateNameDoesNotExist | launchTemplateNameMalformed | launchTemplateVersionDoesNotExist | unexpectedError) with no default-versionmember, and the operation's whole response is built for per-item partial
failure. So the item carries
unexpectedError— the modeled catch-all — withthe reference's own sentence as the message, both labelled inferred in the
code, the CHANGELOG and
docs/services.md. Another emulator inventsInvalidLaunchTemplateVersion.NotAllowed, which a typed SDK would deserializeas an unknown enum variant; that was the trap avoided.
2. The account-wide
DescribeLaunchTemplateVersionsform is included, notscoped out. The plan deferred it to a follow-up issue.
describeLaunchTemplatesalready walks the
lt_ids:index, so the form was a reuse rather than a newquery — no issue needs filing.
Migration
A template stored before this change unmarshals with
Versions == nilandsynthesizes version 1 from
LatestDataon read(
EC2LaunchTemplate.TemplateVersions). That is the entire migration — noevent rewriting.
LatestDatais deliberately retained and kept in sync;its doc comment says why, so a reader does not delete it as redundant.
TestEC2_LaunchTemplate_PreVersioningStateStillWorkswrites pre-#456 JSONdirectly 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-versionspass,go test -C test/e2e ./...ok.Mutation-tested, three mutants, all killed:
AbsentVersionMeansDefault,VersionSpecifiers/absent_means_the_default,Fleet_HonorsLaunchTemplateVersion/absent_means_the_defaultDeleteLaunchTemplateVersionssubtestsTemplateVersions()synthesisAlso walked end-to-end against a live server as a consumer would: create →
CreateLaunchTemplateVersion(SourceVersion=1, ImageId=…)returning version 2with inherited instance type and key name →
ModifyLaunchTemplate→DescribeLaunchTemplateVersions(defaultVersiontrue only on 2) →RunInstanceswith no version launching v2's AMI →DeleteLaunchTemplateVersions(2,1)returning 200 with one entry in each set.Closes #456