Skip to content

Commit

Permalink
Ignore parameters when resolving dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
simonrw committed May 20, 2024
1 parent 9244c9c commit e483288
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions localstack/services/cloudformation/engine/template_deployer.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,10 @@ class ChangeConfig(TypedDict):


def order_resources(
resources: dict, resolved_conditions: dict[str, bool], reverse: bool = False
resources: dict,
resolved_parameters: dict[str, StackParameter],
resolved_conditions: dict[str, bool],
reverse: bool = False,
) -> OrderedDict:
"""
Given a dictionary of resources, topologically sort the resources based on
Expand All @@ -808,6 +811,9 @@ def order_resources(
nodes.setdefault(logical_resource_id, [])
deps = get_deps_for_resource(properties, resolved_conditions)
for dep in deps:
if dep in resolved_parameters:
# we only care about other resources
continue
nodes.setdefault(dep, [])
nodes[dep].append(logical_resource_id)

Expand Down Expand Up @@ -852,6 +858,7 @@ def order_resources(
def order_changes(
given_changes: list[ChangeConfig],
resources: dict,
resolved_parameters: dict[str, StackParameter],
# TODO: remove resolved conditions somehow
resolved_conditions: dict[str, bool],
reverse: bool = False,
Expand All @@ -861,7 +868,10 @@ def order_changes(
changes based on inter-resource dependencies (e.g. usages of intrinsic functions).
"""
ordered_resources = order_resources(
resources=resources, resolved_conditions=resolved_conditions, reverse=reverse
resources=resources,
resolved_parameters=resolved_parameters,
resolved_conditions=resolved_conditions,
reverse=reverse,
)
sorted_changes = []
for logical_resource_id in ordered_resources.keys():
Expand Down Expand Up @@ -973,7 +983,10 @@ def _safe_lookup_is_deleted(r_id):
return True # just an assumption

ordered_resources = order_resources(
resources=resources, resolved_conditions=self.stack.resolved_conditions, reverse=True
resources=resources,
resolved_conditions=self.stack.resolved_conditions,
resolved_parameters=self.stack.resolved_parameters,
reverse=True,
)
for i, (resource_id, resource) in enumerate(ordered_resources.items()):
try:
Expand Down Expand Up @@ -1310,6 +1323,7 @@ def do_apply_changes_in_loop(self, changes: list[ChangeConfig], stack: Stack):
given_changes=changes,
resources=new_resources,
resolved_conditions=stack.resolved_conditions,
resolved_parameters=stack.resolved_parameters,
)
for change_idx, change in enumerate(sorted_changes):
res_change = change["ResourceChange"]
Expand Down

0 comments on commit e483288

Please sign in to comment.