Repository navigation
feat(ec2): CreateLaunchTemplate reports an invalid mapping through its warning (#693) - #702
Merged
Merged
Conversation
…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 Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
Closes #693.
v0.105.0 taught
RunInstancesto refuse a block device mapping real EC2 rejects and deliberately leftCreateLaunchTemplateaccepting one, because the reference documents awarningmember of typeValidationWarning"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 (validationWarningsappears nowhere in AWS's model or in this repo), holdingerrorSet>itemof{code, message}. It goes on each operation's function-local response struct rather than on the sharedec2LaunchTemplateXML, whichModifyLaunchTemplateandDescribeLaunchTemplatesalso render and which must not grow a member they never emit. It is a pointer field:encoding/xmlignoresomitemptyon 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.
ec2CollectBlockDeviceMappingsis now the primitive andec2CheckBlockDeviceMappingsis a three-line wrapper returningproblems[0]. Traversal order is unchanged, so the refusal refuses with exactly what it refused with before — and the code and message a caller reads fromCreateLaunchTemplateare byte-identical to whatRunInstanceswould have refused with.TestEC2_CreateLaunchTemplate_WarnsAboutAnInvalidMappingasserts 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
### Fixedline:DescribeLaunchTemplateVersionsis 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>itemnow carriesdeviceName,virtualName,noDeviceand the fullebsstructure.noDeviceis a*stringso it renders as the present-and-empty element AWS documents ("specify an empty string"), anddeleteOnTermination/encryptedare*boolso an unstated value stays absent instead of becomingfalse.ec2OverlayTemplateDatacopied every member exceptBlockDeviceMappingsandVolumeTagSpecifications, so aSourceVersion-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[]*AWSErrorinstead, converted to the wire shape byec2ValidationWarningForat 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: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
blockDeviceMappingSetstill emits its container element, becauseencoding/xmlwrites the parent of ana>bpath unconditionally andomitemptyon 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 liveRunInstancesrefusal; two problems producing twoerrorSet>items; a snapshot rule (#689'sInvalidSnapshot.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<warninganywhere in the raw body; aSourceVersion-inherited mapping warned about; the fullebsround trip including the three-statedeleteOnTermination, 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 noSourceVersioninherits 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
warningrather 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.Nas ValidationWarning's sole member,BlockDeviceMappingSet.N→blockDeviceMappingSet>item,noDevicebeing a String ("specify an empty string") andLaunchTemplateEbsBlockDevice'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 -lclean,go build,go vet,golangci-lint run ./...→0 issues,make test(race) green,make docs-reference docs-reference-check docs-versionsclean,npm --prefix docs run buildgreen,go vet -C test/e2e ./... && go test -C test/e2e ./...green.