Skip to content

CloudFormation: a failed resource does not roll the stack back #520

Closed

Description

@scttfrdmn

Summary

When a resource in a stack fails, substrate records the failure on that resource
and carries on deploying the rest of the template. The stack reaches
CREATE_COMPLETE. Real CloudFormation rolls the stack back and reports
ROLLBACK_COMPLETE, leaving none of the template's resources behind.

aws cloudformation create-stack --stack-name partial \
  --template-body '{"Resources":{
      "Refused":{"Type":"AWS::S3::Bucket","Properties":{"BucketName":"no"}},
      "After":{"Type":"AWS::SQS::Queue","Properties":{"QueueName":"still-here"}}}}'
aws cloudformation describe-stacks --stack-name partial
# StackStatus: CREATE_COMPLETE          (real CFN: ROLLBACK_COMPLETE)
aws sqs get-queue-url --queue-name still-here
# found                                  (real CFN: rolled back, absent)

This became observable for the first time in v0.87.1, which is what makes it worth
filing: before #519, a refused S3 or IAM resource recorded no failure at all, so
there was nothing for a rollback to key off.

Why it was deliberately left out of v0.87.1

Rollback is a much larger behaviour than the status check that exposed it. It needs
the delete dispatcher from #518 (a rollback deletes what was created so far, in
reverse order, honouring DeletionPolicy), a stack-level decision about
OnFailure (DO_NOTHING / ROLLBACK / DELETE), the ROLLBACK_IN_PROGRESS and
ROLLBACK_FAILED states, and DisableRollback. Bundling it into a patch release
that fixes tag expansion would have been unrelated scope creep.

Acceptance criteria

  • A resource failure during CreateStack rolls back the resources already
    created, in reverse order, and the stack reports ROLLBACK_COMPLETE.
  • OnFailure=DO_NOTHING leaves the stack in CREATE_FAILED with the
    resources in place — the current behaviour, now selectable rather than
    implicit.
  • OnFailure=DELETE deletes the stack entirely.
  • DisableRollback=true is honoured, and --no-disable-rollback likewise.
  • An UpdateStack failure rolls back to the previous template
    (UPDATE_ROLLBACK_COMPLETE), which is a distinct path from create rollback.
  • A rollback that cannot delete a resource reports ROLLBACK_FAILED rather
    than claiming success.
  • docs/services.md replaces the "substrate does not roll back" paragraph.
  • Depends on CloudFormation: DeleteStack does not delete the stack's resources #518 for the delete dispatcher.

Provenance

Current behaviour is pinned by TestCFN_FailedResourceDoesNotStopTheStack in
emulator/betty_cfn_failure_test.go, added in v0.87.1 so the difference from real
CloudFormation is a recorded decision rather than an oversight. Rollback semantics
and the OnFailure values are from the CloudFormation CreateStack API reference
and the stack-failure-options documentation.

Activity

  1. added
    type: bug
    area: cloudformation
    priority: medium
    status: blocked
    on Aug 3, 2026
  2. added this to the v0.89.0 milestone on Aug 3, 2026
  3. scttfrdmn commented on Aug 3, 2026

    @scttfrdmn
    OwnerAuthor

    Milestoned to v0.89.0, where its blocker #518 also lands. Keeping the status: blocked label until that dispatcher exists.

    Why it cannot come earlier. Rollback is deletion, in reverse: ROLLBACK_IN_PROGRESS means deleting the resources created so far, in reverse creation order. Substrate cannot delete a stack's resources at all today (#518), so there is nothing to roll back with. The two share the same machinery, and #518 supplies the ordering for free — typePriority reversed.

    What v0.87.1 changed here — it made this issue reachable, which it was not before. #519 fixed the deployer swallowing every S3 and IAM resource failure: those plugins return a 4xx response with a nil error, and only the *AWSError convention was inspected, so a refused bucket or role was recorded as CREATE_COMPLETE. A resource that genuinely fails now reports CREATE_FAILED. That means the precondition for a rollback — a visibly failed resource in a stack — now actually occurs, where before v0.87.1 it was invisible for two of the most commonly-declared services. The v0.87.1 changelog says this explicitly: substrate still does not roll back, and points here.

    So the consumer-visible situation today is the worst intermediate state: a stack reports CREATE_FAILED on a resource, keeps the resources it already created, and reports a stack status that does not reflect the failure. Half-built stacks are now observable and there is no way to unwind them.

    Design decisions to settle when it lands (recording them now so they are not rediscovered): OnFailure (DO_NOTHING/ROLLBACK/DELETE) and DisableRollback on CreateStack, which are mutually exclusive; ROLLBACK_IN_PROGRESS → ROLLBACK_COMPLETE/ROLLBACK_FAILED; and the distinct update path, where a failed UpdateStack goes UPDATE_ROLLBACK_IN_PROGRESS → UPDATE_ROLLBACK_COMPLETE and must restore the previous property values rather than delete the resource — a different operation from create-rollback, and the one most likely to be missed. DeletionPolicy: Retain (added to cfnResource as part of #518) must be honoured during rollback too.

  4. scttfrdmn commented on Aug 3, 2026

    @scttfrdmn
    OwnerAuthor

    Shipped in v0.89.0 via #547. Every acceptance criterion is met and verified end to end against a live server; each is pinned by a test.

    • Rollback in reverse order → ROLLBACK_COMPLETE, reusing CloudFormation: DeleteStack does not delete the stack's resources #518's sweep. OnFailure=DO_NOTHING → CREATE_FAILED with resources in place; OnFailure=DELETE removes the stack; DisableRollback=true honoured and reported back by DescribeStacks.
    • OnFailure and DisableRollback together is a ValidationError, tested by presence rather than value — the CLI's --no-disable-rollback sends an explicit false, so a value test would accept a combination the API rejects. Measured against the CLI.
    • A sweep that cannot delete → ROLLBACK_FAILED, and the stack keeps its record so the undeleted resource is discoverable.
    • A failed UpdateStack → UPDATE_ROLLBACK_COMPLETE, documented as an approximation: UpdateStack is a re-Deploy, so the rollback re-deploys the stored previous template and converges on its declared state rather than restoring properties field by field.
    • docs/services.md's "the stack itself still reaches a terminal CREATE_COMPLETE … rollback is not modelled" paragraph is replaced.

    Two things worth recording beyond the issue as filed.

    A second defect, found while building this. UpdateStack is a re-Deploy of 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 that was merely invisible (the refusal landed on the resource's error field and the stack still said UPDATE_COMPLETE); with rollback added it becomes data loss, since every update would see failures and 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. A rename into another stack's name, a resource that failed previously, and a record from another account or Region all remain real failures.

    Ordering. The export-conflict checks run before the failure branch, because a duplicate export name is a refusal of the request — a request substrate declines outright never became a stack whose resources could roll back — so it reads the same whether or not a resource beside it also failed. A failed stack's resolved outputs are then discarded: it publishes none and therefore exports none.

    Mutation testing: 11 applied, 11 caught. Two survived on the first pass (a stack record from another account/Region read as the previous deployment; a resource that failed previously read as one this stack owns) and each is now pinned by a test written for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: cloudformationpriority: mediumstatus: blockedtype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions