Skip to content

Commit 90ddbfe

Browse files
committed
Handle not setting template after execute_change_set
1 parent 023d791 commit 90ddbfe

File tree

4 files changed

+70
-7
lines changed

4 files changed

+70
-7
lines changed

localstack-core/localstack/services/cloudformation/v2/provider.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,11 @@ def _run(*args):
617617
result = change_set_executor.execute()
618618
change_set.stack.resolved_parameters = change_set.resolved_parameters
619619
change_set.stack.resolved_resources = result.resources
620+
change_set.stack.template = change_set.template
621+
change_set.stack.processed_template = change_set.processed_template
622+
change_set.stack.template_body = change_set.template_body
623+
change_set.stack.description = change_set.template.get("Description")
624+
620625
if not result.failure_message:
621626
new_stack_status = StackStatus.UPDATE_COMPLETE
622627
if change_set.change_set_type == ChangeSetType.CREATE:
@@ -631,13 +636,6 @@ def _run(*args):
631636
change_set.stack.resolved_exports[export_name] = output["OutputValue"]
632637

633638
change_set.stack.change_set_id = change_set.change_set_id
634-
635-
# if the deployment succeeded, update the stack's template representation to that
636-
# which was just deployed
637-
change_set.stack.template = change_set.template
638-
change_set.stack.description = change_set.template.get("Description")
639-
change_set.stack.processed_template = change_set.processed_template
640-
change_set.stack.template_body = change_set.template_body
641639
else:
642640
LOG.error(
643641
"Execute change set failed: %s",

tests/aws/services/cloudformation/api/test_templates.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from tests.aws.services.cloudformation.conftest import skip_if_legacy_engine
99

1010
from localstack.testing.pytest import markers
11+
from localstack.testing.pytest.fixtures import StackDeployError
1112
from localstack.utils.common import load_file
1213
from localstack.utils.strings import short_uid, to_bytes
1314

@@ -76,6 +77,34 @@ def test_get_template_summary_no_resources(aws_client, snapshot):
7677
snapshot.match("error", exc_info.value.response)
7778

7879

80+
@markers.aws.validated
81+
@markers.snapshot.skip_snapshot_verify(
82+
paths=["$..ResourceIdentifierSummaries..ResourceIdentifiers"]
83+
)
84+
@skip_if_legacy_engine()
85+
def test_get_template_summary_failed_stack(deploy_cfn_template, aws_client, snapshot):
86+
snapshot.add_transformer(snapshot.transform.cloudformation_api())
87+
88+
template = {
89+
"Resources": {
90+
"MyParameter": {
91+
"Type": "AWS::SSM::Parameter",
92+
"Properties": {
93+
"Type": "String",
94+
# Note: missing Value parameter so the resource provider should fail
95+
},
96+
},
97+
},
98+
}
99+
100+
stack_name = f"stack-{short_uid()}"
101+
with pytest.raises(StackDeployError):
102+
deploy_cfn_template(template=json.dumps(template), stack_name=stack_name)
103+
104+
summary = aws_client.cloudformation.get_template_summary(StackName=stack_name)
105+
snapshot.match("template-summary", summary)
106+
107+
79108
@markers.aws.validated
80109
@pytest.mark.parametrize("url_style", ["s3_url", "http_path", "http_host", "http_invalid"])
81110
def test_create_stack_from_s3_template_url(

tests/aws/services/cloudformation/api/test_templates.snapshot.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,5 +216,32 @@
216216
}
217217
}
218218
}
219+
},
220+
"tests/aws/services/cloudformation/api/test_templates.py::test_get_template_summary_failed_stack": {
221+
"recorded-date": "07-10-2025, 22:44:53",
222+
"recorded-content": {
223+
"template-summary": {
224+
"Parameters": [],
225+
"ResourceIdentifierSummaries": [
226+
{
227+
"LogicalResourceIds": [
228+
"MyParameter"
229+
],
230+
"ResourceIdentifiers": [
231+
"Name"
232+
],
233+
"ResourceType": "AWS::SSM::Parameter"
234+
}
235+
],
236+
"ResourceTypes": [
237+
"AWS::SSM::Parameter"
238+
],
239+
"Version": "2010-09-09",
240+
"ResponseMetadata": {
241+
"HTTPHeaders": {},
242+
"HTTPStatusCode": 200
243+
}
244+
}
245+
}
219246
}
220247
}

tests/aws/services/cloudformation/api/test_templates.validation.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@
5050
"tests/aws/services/cloudformation/api/test_templates.py::test_get_template_summary": {
5151
"last_validated_date": "2023-05-24T13:05:00+00:00"
5252
},
53+
"tests/aws/services/cloudformation/api/test_templates.py::test_get_template_summary_failed_stack": {
54+
"last_validated_date": "2025-10-07T22:44:53+00:00",
55+
"durations_in_seconds": {
56+
"setup": 1.0,
57+
"call": 134.39,
58+
"teardown": 0.0,
59+
"total": 135.39
60+
}
61+
},
5362
"tests/aws/services/cloudformation/api/test_templates.py::test_get_template_summary_no_resources": {
5463
"last_validated_date": "2025-10-07T22:28:52+00:00",
5564
"durations_in_seconds": {

0 commit comments

Comments
 (0)