Skip to content

Commit b303510

Browse files
authored
raise exception for undefined dependency in CFn template (#9521)
1 parent ebf3c2a commit b303510

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

localstack/services/cloudformation/engine/template_deployer.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,10 @@ def get_unsatisfied_dependencies_for_resources(
964964
):
965965
result = {}
966966
for resource_id, resource in resources.items():
967+
if not resource:
968+
raise Exception(
969+
f"Resource '{resource_id}' not found in stack {self.stack.stack_name}"
970+
)
967971
if not self.is_deployed(resource):
968972
LOG.debug(
969973
"Dependency for resource %s not yet deployed: %s %s",

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,21 @@ def test_sub_resolving(deploy_cfn_template, aws_client, snapshot):
8383
# Verify resource was created
8484
topic_arns = [t["TopicArn"] for t in aws_client.sns.list_topics()["Topics"]]
8585
assert topic_arn in topic_arns
86+
87+
88+
@markers.aws.only_localstack
89+
def test_unexisting_resource_dependency(deploy_cfn_template, aws_client):
90+
stack_name = f"s-{short_uid()}"
91+
92+
with pytest.raises(Exception):
93+
deploy_cfn_template(
94+
template_path=os.path.join(
95+
os.path.dirname(__file__),
96+
"../../../templates/cfn_unexisting_resource_dependency.yml",
97+
),
98+
stack_name=stack_name,
99+
)
100+
101+
description = aws_client.cloudformation.describe_stacks(StackName=stack_name)["Stacks"][0]
102+
assert description["StackStatus"] == "CREATE_FAILED"
103+
assert "Resource 'UnexistingResource' not found in stack" in description["StackStatusReason"]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Resources:
2+
Parameter:
3+
Type: AWS::SSM::Parameter::Value<String>
4+
Properties:
5+
Value: test
6+
Type: String
7+
DependsOn: UnexistingResource

0 commit comments

Comments
 (0)