Skip to content

Commit

Permalink
fix: Remove str type constrain in Fn:FindInMap to avoid the issue of …
Browse files Browse the repository at this point in the history
…lookup int value
  • Loading branch information
dkphm committed Aug 6, 2024
1 parent fe5649d commit 545d915
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ def handle_find_in_map(self, intrinsic_value, ignore_errors):
)

second_level_value = top_level_value.get(second_level_key)
verify_intrinsic_type_str(
verify_non_null(
second_level_value,
IntrinsicResolver.FN_FIND_IN_MAP,
message="The SecondLevelKey is missing in the Mappings dictionary in Fn::FindInMap "
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/lib/intrinsic_resolver/test_intrinsic_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ def setUp(self):
"Basic": {"Test": {"key": "value"}},
"value": {"anotherkey": {"key": "result"}},
"result": {"value": {"key": "final"}},
"IntegerValue": {"Test": {"key": 0}},
}
}
self.resolver = IntrinsicResolver(symbol_resolver=IntrinsicsSymbolTable(), template=template)
Expand All @@ -218,6 +219,11 @@ def test_basic_find_in_map(self):
result = self.resolver.intrinsic_property_resolver(intrinsic, True)
self.assertEqual(result, "value")

def test_basic_find_in_map_with_non_string_value(self):
intrinsic = {"Fn::FindInMap": ["Basic", "Test", "key"]}
result = self.resolver.intrinsic_property_resolver(intrinsic, True)
self.assertEqual(result, 0)

def test_nested_find_in_map(self):
intrinsic_base_1 = {"Fn::FindInMap": ["Basic", "Test", "key"]}
intrinsic_base_2 = {"Fn::FindInMap": [intrinsic_base_1, "anotherkey", "key"]}
Expand Down

0 comments on commit 545d915

Please sign in to comment.