Skip to content

Commit

Permalink
Dont guess at mappings when values are static
Browse files Browse the repository at this point in the history
  • Loading branch information
kddejong committed Dec 12, 2024
1 parent 8454bc9 commit a9cc1ac
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/cfnlint/template/transforms/_language_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,14 @@ def value(
return self._map[3].value(cfn, params, only_params)
# no default value and map 1 exists
try:
for _, v in mapping.get(
t_map[1].value(cfn, params, only_params), {}
).items():
if isinstance(v, list):
return v
if isinstance(
t_map[2], (_ForEachValueRef, _ForEachValueFnFindInMap)
):
for _, v in mapping.get(
t_map[1].value(cfn, params, only_params), {}
).items():
if isinstance(v, list):
return v
except _ResolveError:
pass
raise _ResolveError("Can't resolve Fn::FindInMap", self._obj) from e
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,14 @@ def test_find_in_map_values_not_found_with_default(self):
)

self.assertEqual(map.value(self.cfn, None, False, True), "bar")
self.assertEqual(map.value(self.cfn, None, False, False), ["foo", "bar"])
with self.assertRaises(_ResolveError):
map.value(self.cfn, None, False, False)

def test_find_in_map_values_strings_without_default(self):
map = _ForEachValueFnFindInMap("a", ["Bucket", "Production", "DNE"])

with self.assertRaises(_ResolveError):
map.value(self.cfn, None, False, True)

def test_find_in_map_values_without_default(self):
map = _ForEachValueFnFindInMap("a", ["Bucket", {"Ref": "Foo"}, "Key"])
Expand Down

0 comments on commit a9cc1ac

Please sign in to comment.