Skip to content

Commit 58dc21c

Browse files
authored
Pass parameters to ForEachCollection processing (#3854)
1 parent 6d083eb commit 58dc21c

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/cfnlint/template/transforms/_language_extensions.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def _walk(self, item: Any, params: MutableMapping[str, Any], cfn: Any):
126126
# only translate the foreach if its valid
127127
foreach = _ForEach(k, v, self._collections)
128128
# get the values will flatten the foreach
129-
for collection_value in foreach.items(cfn):
129+
for collection_value in foreach.items(cfn, params):
130130
flattened = self._walk(
131131
v[2], {**params, **{v[0]: collection_value}}, cfn
132132
)
@@ -523,7 +523,10 @@ def __init__(self, obj: Any) -> None:
523523
raise _TypeError("Collection must be a list or an object", obj)
524524

525525
def values(
526-
self, cfn: Any, collection_cache: MutableMapping[str, Any]
526+
self,
527+
cfn: Any,
528+
collection_cache: MutableMapping[str, Any],
529+
params: MutableMapping[str, Any],
527530
) -> Iterator[str | dict[Any, Any]]:
528531
if self._collection:
529532
for item in self._collection:
@@ -536,7 +539,7 @@ def values(
536539
return
537540
if self._fn:
538541
try:
539-
values = self._fn.value(cfn, {}, False)
542+
values = self._fn.value(cfn, params, False)
540543
if values is not None:
541544
if isinstance(values, list):
542545
for value in values:
@@ -594,6 +597,8 @@ def __init__(
594597
self._collection = _ForEachCollection(value[1])
595598
self._output = _ForEachOutput(value[2])
596599

597-
def items(self, cfn: Any) -> Iterator[str | dict[str, str]]:
598-
items = self._collection.values(cfn, self._collection_cache)
600+
def items(
601+
self, cfn: Any, params: MutableMapping[str, Any]
602+
) -> Iterator[str | dict[str, str]]:
603+
items = self._collection.values(cfn, self._collection_cache, params)
599604
yield from iter(items)

test/unit/module/template/transforms/test_language_extensions.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,16 @@ def setUp(self) -> None:
7474
def test_valid(self):
7575
fec = _ForEachCollection({"Ref": "AccountIds"})
7676
self.assertListEqual(
77-
list(fec.values(self.cfn, {})),
77+
list(fec.values(self.cfn, {}, {})),
7878
[
7979
{"Fn::Select": [0, {"Ref": "AccountIds"}]},
8080
{"Fn::Select": [1, {"Ref": "AccountIds"}]},
8181
],
8282
)
83+
self.assertListEqual(
84+
list(fec.values(self.cfn, {}, {"AccountIds": ["A", "B"]})),
85+
["A", "B"],
86+
)
8387

8488

8589
class TestRef(TestCase):

0 commit comments

Comments
 (0)