Skip to content

Commit eb7ec67

Browse files
committed
Implement get_template_summary
At least an initial version that matches one test
1 parent 7dffb23 commit eb7ec67

File tree

4 files changed

+40
-5
lines changed

4 files changed

+40
-5
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232

3333
class ResolvedResource(TypedDict):
34+
Type: str
3435
Properties: dict
3536

3637

@@ -190,6 +191,9 @@ def describe_details(self) -> ApiStack:
190191
result["Outputs"] = describe_outputs
191192
return result
192193

194+
def is_active(self) -> bool:
195+
return self.status != StackStatus.DELETE_COMPLETE
196+
193197

194198
class ChangeSetRequestPayload(TypedDict, total=False):
195199
ChangeSetName: str

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

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import copy
22
import logging
3+
from collections import defaultdict
34
from datetime import datetime, timezone
45
from typing import Any, Optional
56

@@ -23,6 +24,8 @@
2324
DisableRollback,
2425
ExecuteChangeSetOutput,
2526
ExecutionStatus,
27+
GetTemplateSummaryInput,
28+
GetTemplateSummaryOutput,
2629
IncludePropertyValues,
2730
InvalidChangeSetStatusException,
2831
LogicalResourceId,
@@ -208,9 +211,7 @@ def create_change_set(
208211
stack_candidates: list[Stack] = [
209212
s for stack_arn, s in state.stacks_v2.items() if s.stack_name == stack_name
210213
]
211-
active_stack_candidates = [
212-
s for s in stack_candidates if self._stack_status_is_active(s.status)
213-
]
214+
active_stack_candidates = [s for s in stack_candidates if s.is_active()]
214215

215216
# on a CREATE an empty Stack should be generated if we didn't find an active one
216217
if not active_stack_candidates and change_set_type == ChangeSetType.CREATE:
@@ -562,6 +563,38 @@ def describe_stack_events(
562563
raise StackNotFoundError(stack_name)
563564
return DescribeStackEventsOutput(StackEvents=stack.events)
564565

566+
@handler("GetTemplateSummary", expand=False)
567+
def get_template_summary(
568+
self,
569+
context: RequestContext,
570+
request: GetTemplateSummaryInput,
571+
) -> GetTemplateSummaryOutput:
572+
state = get_cloudformation_store(context.account_id, context.region)
573+
stack_name = request.get("StackName")
574+
if not stack_name:
575+
raise NotImplementedError("No stack name provided to get_template_summary")
576+
stack = find_stack_v2(state, stack_name)
577+
if not stack:
578+
raise StackNotFoundError(stack_name)
579+
580+
id_summaries = defaultdict(list)
581+
for resource_id, resource in stack.resolved_resources.items():
582+
res_type = resource["Type"]
583+
id_summaries[res_type].append(resource_id)
584+
585+
result = GetTemplateSummaryOutput(
586+
# TODO parameters
587+
Metadata=stack.template.get("Metadata"),
588+
ResourceIdentifierSummaries=[
589+
{"ResourceType": key, "LogicalResourceIds": values}
590+
for key, values in id_summaries.items()
591+
],
592+
ResourceTypes=list(id_summaries.keys()),
593+
Version=stack.template.get("AWSTemplateFormatVersion", "2010-09-09"),
594+
)
595+
596+
return result
597+
565598
@handler("DeleteStack")
566599
def delete_stack(
567600
self,

tests/aws/services/cloudformation/v2/ported_from_v1/api/test_changesets.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,6 @@ def test_create_and_then_remove_non_supported_resource_change_set(deploy_cfn_tem
645645
)
646646

647647

648-
@pytest.mark.skip("CFNV2:Other")
649648
@markers.aws.validated
650649
def test_create_and_then_update_refreshes_template_metadata(
651650
aws_client,

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
)
1818

1919

20-
@pytest.mark.skip(reason="CFNV2:Provider")
2120
@markers.aws.validated
2221
@markers.snapshot.skip_snapshot_verify(
2322
paths=["$..ResourceIdentifierSummaries..ResourceIdentifiers", "$..Parameters"]

0 commit comments

Comments
 (0)