Skip to content

Commit

Permalink
Allow Fn::Transform alongside keys in mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
kddejong committed Jan 17, 2025
1 parent 3bdb648 commit 120d3dc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/cfnlint/jsonschema/_resolvers_cfn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
28 changes: 28 additions & 0 deletions test/unit/module/jsonschema/test_resolvers_cfn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 120d3dc

Please sign in to comment.