Skip to content

Commit 5fdd18b

Browse files
authored
Don't resolve pseudoparams in findinmap (#3653)
1 parent 5a3b045 commit 5fdd18b

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/cfnlint/jsonschema/_resolvers_cfn.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111

1212
import regex as re
1313

14-
from cfnlint.helpers import AVAILABILITY_ZONES, REGEX_SUB_PARAMETERS
14+
from cfnlint.helpers import (
15+
AVAILABILITY_ZONES,
16+
PSEUDOPARAMS,
17+
REGEX_SUB_PARAMETERS,
18+
is_function,
19+
)
1520
from cfnlint.jsonschema import ValidationError, Validator
1621
from cfnlint.jsonschema._typing import ResolutionResult
1722
from cfnlint.jsonschema._utils import equal
@@ -69,6 +74,9 @@ def find_in_map(validator: Validator, instance: Any) -> ResolutionResult:
6974
mappings = list(validator.context.mappings.maps.keys())
7075
results = []
7176
found_valid_combination = False
77+
k, v = is_function(instance[0])
78+
if k == "Ref" and v in PSEUDOPARAMS:
79+
return
7280
for map_name, map_v, _ in validator.resolve_value(instance[0]):
7381
if not validator.is_type(map_name, "string"):
7482
continue
@@ -90,6 +98,9 @@ def find_in_map(validator: Validator, instance: Any) -> ResolutionResult:
9098
if validator.context.mappings.maps[map_name].is_transform:
9199
continue
92100

101+
k, v = is_function(instance[1])
102+
if k == "Ref" and v in PSEUDOPARAMS:
103+
continue
93104
for top_level_key, top_v, _ in validator.resolve_value(instance[1]):
94105
if validator.is_type(top_level_key, "integer"):
95106
top_level_key = str(top_level_key)
@@ -123,6 +134,9 @@ def find_in_map(validator: Validator, instance: Any) -> ResolutionResult:
123134
):
124135
continue
125136

137+
k, v = is_function(instance[2])
138+
if k == "Ref" and v in PSEUDOPARAMS:
139+
continue
126140
for second_level_key, second_v, err in validator.resolve_value(instance[2]):
127141
if validator.is_type(second_level_key, "integer"):
128142
second_level_key = str(second_level_key)

test/unit/module/jsonschema/test_resolvers_cfn.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,21 @@ def test_invalid_functions(name, instance, response):
290290
{"Fn::FindInMap": ["foo", "second", "first", {"DefaultValue": "default"}]},
291291
[("default", deque([4, "DefaultValue"]), None)],
292292
),
293+
(
294+
"Valid FindInMap with a map name that is a Ref to pseudo param",
295+
{"Fn::FindInMap": [{"Ref": "AWS::StackName"}, "first", "second"]},
296+
[],
297+
),
298+
(
299+
"Valid FindInMap with an top level key that is a Ref to pseudo param",
300+
{"Fn::FindInMap": ["foo", {"Ref": "AWS::AccountId"}, "second"]},
301+
[],
302+
),
303+
(
304+
"Valid FindInMap with a second level key that is a Ref to pseudo param",
305+
{"Fn::FindInMap": ["foo", "first", {"Ref": "AWS::AccountId"}]},
306+
[],
307+
),
293308
(
294309
"Valid FindInMap with a bad third key",
295310
{"Fn::FindInMap": ["foo", "first", "third"]},

0 commit comments

Comments
 (0)