fix(cloudformation): record REVIEW_IN_PROGRESS event on change-set creation (#1431)

* fix(cloudformation): record REVIEW_IN_PROGRESS event on change-set creation

A CREATE change set puts a brand-new stack into REVIEW_IN_PROGRESS, but
createChangeSet recorded no stack event, so DescribeStackEvents returned an
empty list for it. AWS and LocalStack return at least the REVIEW_IN_PROGRESS
stack event; tooling that reads StackEvents[0] right after change-set creation
(e.g. the AWS SAM CLI's get_last_event_time) therefore fails on floci with
"list index out of range" before any resources are deployed.

Record the REVIEW_IN_PROGRESS stack-level event when a CREATE change set
creates a new stack, scoped to that path (nested stacks and update change sets
are unaffected). Adds an integration test.

Fixes #1429

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Vishal Goyal <vishal.goyal@home24.de>

* fix(cloudformation): address review — atomic new-stack detection + CREATE gate

Detect first stack creation via the computeIfAbsent mapping function (runs at
most once per key, so it's atomic and won't double-record the event under
concurrent CreateChangeSet calls) instead of a non-atomic containsKey pre-check,
and only record the REVIEW_IN_PROGRESS event for CREATE-type change sets
(null defaults to CREATE, matching createChangeSet).
This commit is contained in:
Vishal Goyal authored and GitHub committed 2026-06-18 18:45:53 -05:00
1 parent 56706217d3
commit 9bb1db3a54
2 files changed
+57

No files matched your search

@@ -133,12 +133,27 @@ public class CloudFormationService {
Map<String, String> tags, String region) {
String resolvedTemplate = resolveTemplate(templateBody, templateUrl);
// Detect first creation atomically: the mapping function runs at most once per key, so the
// flag is only set for the thread that actually creates the stack (no double-recording under
// concurrent CreateChangeSet calls).
boolean[] stackCreated = {false};
Stack stack = stacks.computeIfAbsent(key(stackName, region), k -> {
stackCreated[0] = true;
Stack s = newStack(stackName, region);
if (tags != null) s.getTags().putAll(tags);
return s;
});
// A CREATE change set puts a brand-new stack into REVIEW_IN_PROGRESS. Record the matching
// stack-level event (as AWS and LocalStack do) so DescribeStackEvents is non-empty straight
// after change-set creation — tooling such as the AWS SAM CLI reads StackEvents[0] there and
// otherwise fails with an IndexError. (CreateChangeSet defaults a null type to CREATE.)
boolean isCreateType = changeSetType == null || "CREATE".equalsIgnoreCase(changeSetType);
if (stackCreated[0] && isCreateType) {
addEvent(stack, stack.getStackName(), stack.getStackId(),
"AWS::CloudFormation::Stack", "REVIEW_IN_PROGRESS", "User Initiated");
}
ChangeSet cs = new ChangeSet();
cs.setChangeSetId(AwsArnUtils.Arn.of("cloudformation", region, regionResolver.getAccountId(), "changeSet/" + changeSetName + "/" + UUID.randomUUID()).toString());
cs.setChangeSetName(changeSetName);