From 83fd95a3899ed3f76002b40267924603f45d27b2 Mon Sep 17 00:00:00 2001 From: Kevin DeJong Date: Fri, 17 Jan 2025 10:31:47 -0800 Subject: [PATCH] Allow Fn::Transform alongside keys in mappings (#3920) --- src/cfnlint/jsonschema/_resolvers_cfn.py | 4 +++ .../module/jsonschema/test_resolvers_cfn.py | 28 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/cfnlint/jsonschema/_resolvers_cfn.py b/src/cfnlint/jsonschema/_resolvers_cfn.py index 5fff8b6b34..58ea7da293 100644 --- a/src/cfnlint/jsonschema/_resolvers_cfn.py +++ b/src/cfnlint/jsonschema/_resolvers_cfn.py @@ -85,6 +85,10 @@ def find_in_map(validator: Validator, instance: Any) -> ResolutionResult: if all(not (equal(map_name, each)) for each in mappings): if not default_value_found: + # Validated again as Fn::Transform can be used along side + # other key/values + if validator.context.mappings.is_transform: + continue results.append( ( None, diff --git a/test/unit/module/jsonschema/test_resolvers_cfn.py b/test/unit/module/jsonschema/test_resolvers_cfn.py index bc3a755497..a64ff6dd08 100644 --- a/test/unit/module/jsonschema/test_resolvers_cfn.py +++ b/test/unit/module/jsonschema/test_resolvers_cfn.py @@ -849,3 +849,31 @@ def test_valid_functions(name, instance, response): ) def test_no_mapping(name, instance, response): _resolve(name, instance, response) + + +@pytest.mark.parametrize( + "name,instance,response", + [ + ( + "Valid FindInMap using transform key (maybe) with fn", + {"Fn::FindInMap": [{"Ref": "AWS::Region"}, "B", "C"]}, + [], + ), + ( + "Valid FindInMap using transform key (maybe)", + {"Fn::FindInMap": ["A", "B", "C"]}, + [], + ), + ], +) +def test_find_in_map_with_transform(name, instance, response): + context = Context( + mappings=Mappings.create_from_dict( + { + "foo": {"first": {"second": "bar"}}, + "Fn::Transform": "foobar", + } + ), + resources={}, + ) + _resolve(name, instance, response, context=context)