Skip to content

Commit

Permalink
Fix an issue with W1011 to allow integers in the FindInMap (#3272)
Browse files Browse the repository at this point in the history
  • Loading branch information
kddejong authored May 31, 2024
1 parent 600ee1f commit e517a00
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/cfnlint/rules/functions/FindInMapKeys.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def check_keys(self, map_name, keys, mappings, tree, cfn):
mapping = mappings.get(map_name)
if mapping:
if isinstance(first_key, (str, int)):
first_key = str(first_key)
if isinstance(map_name, (str)):
if mapping.get(first_key) is None:
message = 'FindInMap first key "{0}" doesn\'t exist in map "{1}" at {3}'
Expand All @@ -44,6 +45,7 @@ def check_keys(self, map_name, keys, mappings, tree, cfn):
)
if mapping.get(first_key):
# Don't double error if they first key doesn't exist
second_key = str(second_key)
if mapping.get(first_key, {}).get(second_key) is None:
message = 'FindInMap second key "{0}" doesn\'t exist in map "{1}" under "{2}" at {3}'
matches.append(
Expand Down
10 changes: 9 additions & 1 deletion test/fixtures/templates/good/functions/findinmap_keys.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ Mappings:
CertificateMap:
us-east-1:
Arn: arn:aws:acm:us-east-1:<account>:certificate/<id>
2:
"2":
Arn: "" # Empty string is a valid value
key:
3: "" # Empty string is a valid value
Resources:
AppAlbListener:
Type: AWS::ElasticLoadBalancingV2::Listener
Expand All @@ -32,3 +34,9 @@ Resources:
Certificates:
- CertificateArn: # Doesn't fail with integer
Fn::FindInMap: [!Ref 'AWS::Region', 2, id]
AppAlbListener4:
Type: AWS::ElasticLoadBalancingV2::Listener
Properties:
Certificates:
- CertificateArn: # Doesn't fail with integer
Fn::FindInMap: [!Ref 'AWS::Region', key, 3]

0 comments on commit e517a00

Please sign in to comment.