Skip to content

feat(ec2): CreateLaunchTemplate reports an invalid mapping through its warning (#693) - #702

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/693-launchtemplate-warning
Aug 21, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/693-launchtemplate-warning

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #693.

v0.105.0 taught RunInstances to refuse a block device mapping real EC2 rejects and deliberately left CreateLaunchTemplate accepting one, because the reference documents a warning member of type ValidationWarning "for parameters or parameter combinations that are not valid" and lists no errors for the case. Rendering that member is what makes the decision honest rather than a silent swallow: until now the mapping vanished, and the caller learned about it only at launch — from a template it had already shipped to every consumer of that template.

What changed

Both create operations render warning. Singular, per the reference (validationWarnings appears nowhere in AWS's model or in this repo), holding errorSet>item of {code, message}. It goes on each operation's function-local response struct rather than on the shared ec2LaunchTemplateXML, which ModifyLaunchTemplate and DescribeLaunchTemplates also render and which must not grow a member they never emit. It is a pointer field: encoding/xml ignores omitempty on a struct value, so a value field would emit <warning></warning> on every valid template.

The warning and the refusal are the same diagnosis, by construction. ec2CollectBlockDeviceMappings is now the primitive and ec2CheckBlockDeviceMappings is a three-line wrapper returning problems[0]. Traversal order is unchanged, so the refusal refuses with exactly what it refused with before — and the code and message a caller reads from CreateLaunchTemplate are byte-identical to what RunInstances would have refused with. TestEC2_CreateLaunchTemplate_WarnsAboutAnInvalidMapping asserts that equality against the live refusal rather than against a literal, so the two cannot drift.

Where the warning differs it is wider: it reports every problem, because AWS documents one entry "for each issue that's found". A first-error function called once can only ever produce one entry, which is why the collector had to be the primitive and not the wrapper.

Two adjacent bugs the feature is hollow without, each its own ### Fixed line:

  • Nothing rendered a template's block device mappings. DescribeLaunchTemplateVersions is the only operation that returns a template's data at all, so v0.104.0's parse-and-store was write-only and a warned caller could not read back the mapping the warning was about. blockDeviceMappingSet>item now carries deviceName, virtualName, noDevice and the full ebs structure. noDevice is a *string so it renders as the present-and-empty element AWS documents ("specify an empty string"), and deleteOnTermination/encrypted are *bool so an unstated value stays absent instead of becoming false.
  • ec2OverlayTemplateData copied every member except BlockDeviceMappings and VolumeTagSpecifications, so a SourceVersion-derived version silently lost both. With nothing rendering either, the only way to see the loss was to launch from the derived version and inspect its volumes — which is how a consumer would find it in a deployed template, not in a test.

Deviation from the plan, deliberate

The plan said to restructure the per-mapping validator to return []ec2ValidationError. It returns []*AWSError instead, converted to the wire shape by ec2ValidationWarningFor at the response boundary. The reason is the equality above: with one problem type there is exactly one place codes and messages are written, and the refusal and the warning cannot describe the same mapping differently. A second warning-shaped type would have to be kept in step with the first by hand, and nothing would fail if it drifted.

Fail-before, recorded at main (ae23038)

The two test files copied into a throwaway worktree at main, so this is the fix's absence and nothing else:

--- FAIL: TestEC2_CreateLaunchTemplate_WarnsAboutAnInvalidMapping (0.00s)
        Error:      Expected value not to be nil.
        Messages:   an invalid mapping is reported through warning: <?xml version="1.0" ...
                    <CreateLaunchTemplateResponse ...><launchTemplate><launchTemplateId>lt-28f0072db7ad455e</launchTemplateId><launchTemplateName>warned</launchTemplateName>...<tagSet></tagSet></launchTemplate></CreateLaunchTemplateResponse>
--- FAIL: TestEC2_CreateLaunchTemplate_WarnsAboutEveryProblem (0.00s)
        Error:      Expected value not to be nil.
--- FAIL: TestEC2_CreateLaunchTemplate_WarnsAboutAnUnknownSnapshot (0.00s)
        Error:      Expected value not to be nil.
--- FAIL: TestEC2_CreateLaunchTemplateVersion_WarnsAboutAnInvalidMapping (0.00s)
        Error:      Expected value not to be nil.
        Messages:   version 1 carries the mapping and the warning
--- FAIL: TestEC2_LaunchTemplateVersion_ReadsBackItsBlockDeviceMappings (0.00s)
        Error:      "[]" should have 3 item(s), but has 0
--- FAIL: TestEC2_LaunchTemplateVersion_SourceVersionCarriesMappingsAndVolumeTags (0.00s)
        Error:      "[]" should have 1 item(s), but has 0
        Messages:   version 2 inherits version 1's mapping: ...<launchTemplateData><imageId>ami-11112222333344445</imageId><securityGroupIdSet></securityGroupIdSet><networkInterfaceSet></networkInterfaceSet><tagSpecificationSet></tagSpecificationSet></launchTemplateData>...
--- FAIL: TestEC2_LaunchTemplateVersion_NoSourceVersionInheritsNothing (0.00s)
        Error:      ... does not contain "<blockDeviceMappingSet></blockDeviceMappingSet>"

Note the sixth failure's body: version 2 carries no mapping element and no tag specification, which is the silent drop rather than an unrendered member.

One assertion in the new file was written wrong and corrected rather than driven into the code: an empty blockDeviceMappingSet still emits its container element, because encoding/xml writes the parent of an a>b path unconditionally and omitempty on the slice cannot suppress it. Its three siblings in the same struct (securityGroupIdSet, networkInterfaceSet, tagSpecificationSet) have always done the same, so matching them is right and being the one member that disappears would not be.

Tests

New emulator/ec2_launchtemplate_warning_test.go: the warning on both operations; the code and message equal to the live RunInstances refusal; two problems producing two errorSet>items; a snapshot rule (#689's InvalidSnapshot.NotFound) reported through the same member, since the two rule sets arrived a PR apart and share one collector; a valid template and a template with no mapping at all carrying no <warning anywhere in the raw body; a SourceVersion-inherited mapping warned about; the full ebs round trip including the three-state deleteOnTermination, an instance store device and a suppression; the inherited mapping and volume tags observed through a launch from the derived version; and the preserved asymmetry that a version naming no SourceVersion inherits nothing.

TestEC2_BlockDeviceMapping_TemplateMappingRefusedAtLaunch's doc comment said rendering the element was a follow-up. It now states what that test still pins — that the warning did not become a refusal: the template is created and the launch is still the operation that fails.

Provenance

That an invalid block device mapping lands in warning rather than in a 400 is substrate's reading. AWS documents the member's purpose but never says which validations use it, and neither operation's Errors section lists anything about block device mappings — so a 400 there would be substrate's invention in the other direction. warning/ValidationWarning/ValidationError, ErrorSet.N as ValidationWarning's sole member, BlockDeviceMappingSet.N → blockDeviceMappingSet>item, noDevice being a String ("specify an empty string") and LaunchTemplateEbsBlockDevice's ten members were each verified against the API reference. The codes are documented; the messages are substrate's own, so dispatch on the code.

Verification

gofmt -l clean, go build, go vet, golangci-lint run ./... → 0 issues, make test (race) green, make docs-reference docs-reference-check docs-versions clean, npm --prefix docs run build green, go vet -C test/e2e ./... && go test -C test/e2e ./... green.

…s warning (#693)

v0.105.0 taught RunInstances to refuse a block device mapping real EC2 rejects and
deliberately left both create operations accepting one, because neither documents an
error for it. The mapping was swallowed in silence and the caller learned about it
only at launch, from a template it had already shipped.

Both operations now render AWS's documented `warning` member of type
ValidationWarning. One collector produces the problems and the existing first-error
function is a thin wrapper over it, so the create-time diagnosis and the launch-time
refusal are byte-identical by construction — and the warning reports every problem
rather than the first, which is what a list-shaped member is for.

Two adjacent bugs the feature would be hollow without: nothing rendered a template's
block device mappings, so a warned caller could not read back the mapping the warning
was about; and SourceVersion inheritance silently dropped BlockDeviceMappings and
VolumeTagSpecifications, so a derived version launched an 8 GiB default root device.
@codecov

codecov Bot commented Aug 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.73684% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/ec2_launchtemplate_versions.go 90.69% 2 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 75fbf6d into main Aug 21, 2026
16 checks passed
@scttfrdmn
scttfrdmn deleted the feat/693-launchtemplate-warning branch August 21, 2026 06:58
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: render CreateLaunchTemplate's warning/ValidationWarning element

1 participant