Skip to content

cloudformation: process every StackInstances.update() target independently - #10184

Open
Sohel2309 wants to merge 1 commit into
getmoto:masterfrom
Sohel2309:fix-10173-update-stack-instances-partial-batch
Open

cloudformation: process every StackInstances.update() target independently#10184
Sohel2309 wants to merge 1 commit into
getmoto:masterfrom
Sohel2309:fix-10173-update-stack-instances-partial-batch

Conversation

@Sohel2309

Copy link
Copy Markdown

Summary

StackInstances.update() raised StackInstanceNotFound as soon as it encountered the first missing account/region target, causing valid targets later in the same request to be skipped.

This made the result depend on the ordering of the requested targets.

Root cause

StackInstances.update() iterated through the requested account/region combinations and raised StackInstanceNotFound immediately when a matching stack instance was not found.

Because the exception was raised inside the loop, the remaining targets were never processed.

Fix

Update all existing targets first while tracking whether any requested target was missing.

After all targets have been processed, raise StackInstanceNotFound if at least one target was missing.

This preserves the existing error behavior while ensuring valid targets are not silently skipped.

Regression test

Added a regression test covering the ordering-sensitive case where:

  1. The first requested target does not exist.
  2. A later target does exist.
  3. The operation still raises StackInstanceNotFoundException.
  4. The existing later target is nevertheless updated correctly.

The test fails against the original implementation and passes with the fix.

Validation

  • Regression test verified to fail before the fix and pass after the fix.
  • CloudFormation test suite: 222 passed, 1 skipped; 2 Docker-dependent tests excluded due to the local environment.
  • ruff format --check: passed.
  • mypy on the modified production file: passed.
  • No unrelated files were changed.

Fixes #10173

…ently

StackInstances.update() (used by UpdateStackInstances) iterated the
requested (account, region) targets and raised StackInstanceNotFound
as soon as it hit the first target with no existing instance. This
abandoned the rest of the batch, so any target listed after the
missing one never got updated even though it had an existing
instance and should have been - the outcome depended entirely on
request-list ordering, which isn't how AWS documents this operation
(each account/Region target is modeled as succeeding or failing
independently within a single operation).

Update every existing target first, then raise
StackInstanceNotFoundException for the operation as a whole if any
target was missing, so the exception is still surfaced but no longer
at the cost of silently dropping updates to other, valid targets.

Fixes getmoto#10173

Regression test added that updates two targets where the first one
listed is missing and the second one has an existing instance, and
asserts the existing instance is still updated despite the exception.
Verified the new test fails with the old code (existing instance's
ParameterOverrides stays unset) and passes with the fix.
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.

CloudFormation: update_stack_instances aborts the whole batch instead of processing each account/region independently

1 participant