Repository navigation
fix(cfn): a failed create rolls the stack back (#520) - #547
Merged
Merged
Conversation
A stack holding a resource a plugin refused reported a terminal CREATE_COMPLETE with every resource beside it left in place, so a consumer's failure-handling path could not be tested at all — substrate never produced the failure that path exists to handle. The default is ROLLBACK, as the API's is: the resources the create had already made are swept through #518's dispatcher in the inverse of the deploy order, and the stack reaches ROLLBACK_COMPLETE naming the failed resource and the plugin's own error code. CreateStack's OnFailure and DisableRollback are read and honoured for the first time, and are mutually exclusive as the reference makes them — tested by presence, not value, since --no-disable-rollback sends an explicit false. While building it, a second defect: UpdateStack is a re-Deploy, so every unchanged resource's create is re-issued and its plugin refuses it as already existing. Invisible before rollback; with rollback it would make every update sweep the resources it was asked to keep. An already-exists refusal is now cleared only when the previous deployment created that logical ID successfully and the template still declares it identically. Closes #520
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
8 tasks
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 #520
The defect
A stack holding a resource a plugin refused reported a terminal
CREATE_COMPLETE, with every resource beside it left in place. A consumer's failure-handling path could not be tested at all, because substrate never produced the failure that path exists to handle — the teardown-side twin of the v0.88.0 cluster: HTTP 200 while the observable a caller parses is wrong.What changed
ROLLBACKis the default, as the API's is. The resources the create had already made are swept through #518's dispatcher in the inverse of the deploy order, and the stack reachesROLLBACK_COMPLETEnaming the failed resource and the plugin's own error code. The record stays, because aROLLBACK_COMPLETEstack still blocks a create of the same name — the one thing that makes the failure impossible to miss.CreateStack's two failure parameters are read and honoured for the first time, and they are mutually exclusive — "you can specify eitherDisableRollbackorOnFailure, but not both" — so giving both is aValidationErrorrather than a precedence rule. The test is presence, not value: the CLI's--no-disable-rollbacksendsDisableRollback=falseexplicitly, so a rule that ignored a false would accept a combination the API rejects. This was measured against the CLI rather than assumed.OnFailure=ROLLBACK/DisableRollback=falseROLLBACK_COMPLETEOnFailure=DO_NOTHING/DisableRollback=trueCREATE_FAILED— what substrate used to do unconditionallyOnFailure=DELETEDescribeStacksreports the option it was given rather than emittingDisableRollback: falsefor every stack. A sweep that cannot delete givesROLLBACK_FAILEDand keeps the record so the undeleted resource is discoverable. All of these answer 200 on the wire: realCreateStackreturns itsStackIdbefore any rollback happens, so a rolled-back stack is not a failed call, and a 5xx would make an SDK retry a create that already ran.A failed stack publishes no outputs, and therefore exports none. A duplicate export name is still answered as an error rather than as a rolled-back stack, because it is a refusal of the request: a request substrate declines outright never became a stack whose resources could roll back. That ordering — resource loop, then the redeploy guard, then export checks, then the failure branch — is the fix for eight tests that collided when the failure branch ran first.
A second defect, found rather than reported
UpdateStackis a re-Deployof the whole template, so every unchanged resource's create is re-issued and its plugin refuses it as already existing — where real CloudFormation issues no call at all for a resource it is not changing. Before rollback this was merely invisible: the refusal landed on the resource's error field and the stack still saidUPDATE_COMPLETE. With rollback added it becomes data loss, since everyUpdateStackwould see failures and sweep the resources it was asked to keep.So an already-exists refusal is cleared when — and only when — the stack's previous deployment created that logical ID successfully and the template still declares it identically (canonically marshalled JSON, since Go's encoder sorts map keys). Each condition is load-bearing and each has a test: a rename into a name another stack owns, a resource that failed the previous time (so this stack never owned the name), and a record belonging to another account or Region all remain real failures. The refusal cannot be keyed on the physical ID — a refused create returns an empty one, measured on
AWS::EC2::LaunchTemplate.The error-code set was harvested by deploying twice against the default registry, the same way
cfnDeleteAbsentCodeswas. Ambiguous codes (ConflictException,AlreadyExistsException) are deliberately absent: clearing one would hide a real failure, whereas a missing entry only preserves the pre-existing behaviour.Update rollback is an approximation, stated as one
A failed
UpdateStackreportsUPDATE_ROLLBACK_COMPLETEby re-deploying the stored previous template, since that is the only description of the previous state substrate holds. It converges on that template's declared state rather than restoring properties field by field, so a resource the failed update replaced may keep a new physical ID. Recorded in the doc comment and indocs/services.md— an undocumented approximation is the defect shape this release is about. A previous record that cannot be read leaves the stack atUPDATE_FAILEDwith the reason logged (//nolint:nilerr, explained at the site) rather than a rollback attempted against nothing.Tests
15 new (11 deployer-level, 4 on the wire), plus three existing contracts updated with their reasoning recorded.
TestCFN_FailedResourceDoesNotStopTheStackwas rewritten rather than deleted, per the plan: the behaviour it pinned did not go away, it stopped being unconditional, so it is now theDO_NOTHINGcase. Every failure is a real refusal —"no"is under S3's three-character minimum — never an injected one or a missing plugin, sinceServiceNotAvailableis substrate's own condition rather than one a caller hits against AWS.Mutation testing: 11 applied, 11 caught. Two survived on first pass and each is now pinned by a test written for it — a stack record from another account/Region being read as the previous deployment, and a resource that failed previously being read as one this stack owns. Others covered:
OnFailuredefaulting toDO_NOTHING, sweeping the refused resource,cfnDeleteStackOpfor a create rollback, the redeploy guard removed entirely, the declaration check dropped, the presence test weakened to a value test, the error-code prefix split dropped, and theROLLBACK_FAILEDbranch made unreachable.Verification
gofmt -l .,go build ./...,go vet ./...,golangci-lint run ./...→ 0 issues,make test(race),make docs-reference docs-reference-check docs-versions,npm --prefix docs run build,go vet -C test/e2e ./...,go test -C test/e2e ./....End to end against a live server: the plan's own reproduction, all four option outcomes, both mutual-exclusion errors, an unchanged-resource update reaching
UPDATE_COMPLETEwith its bucket alive, and a failed update reachingUPDATE_ROLLBACK_COMPLETE.Compatibility
A test asserting that a partial stack reaches
CREATE_COMPLETE, or that a resource beside a failed one survives, will go red. That is the fix. PassOnFailure=DO_NOTHING(orDisableRollback=true) to keep the old outcome deliberately.