Skip to content
New issue

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

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

Already on GitHub? # to your account

Allow Fn::Transform alongside keys in mappings #3920

Merged
merged 1 commit into from
Jan 17, 2025
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
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)
Loading