From a9cc1ac8e28227985405942320493528056dbed8 Mon Sep 17 00:00:00 2001 From: Kevin DeJong Date: Thu, 12 Dec 2024 10:20:31 -0800 Subject: [PATCH] Dont guess at mappings when values are static --- .../template/transforms/_language_extensions.py | 13 ++++++++----- .../template/transforms/test_language_extensions.py | 9 ++++++++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/cfnlint/template/transforms/_language_extensions.py b/src/cfnlint/template/transforms/_language_extensions.py index 5263cf6868..3f1e38a86a 100644 --- a/src/cfnlint/template/transforms/_language_extensions.py +++ b/src/cfnlint/template/transforms/_language_extensions.py @@ -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 diff --git a/test/unit/module/template/transforms/test_language_extensions.py b/test/unit/module/template/transforms/test_language_extensions.py index f992f88cd6..fabfb52798 100644 --- a/test/unit/module/template/transforms/test_language_extensions.py +++ b/test/unit/module/template/transforms/test_language_extensions.py @@ -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"])