Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dont guess at mappings when values are static #3875

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading