From e517a006a55ff31859f06d284e66bf2491cd97d2 Mon Sep 17 00:00:00 2001 From: Kevin DeJong Date: Fri, 31 May 2024 07:09:25 -0700 Subject: [PATCH] Fix an issue with W1011 to allow integers in the FindInMap (#3272) --- src/cfnlint/rules/functions/FindInMapKeys.py | 2 ++ .../templates/good/functions/findinmap_keys.yaml | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/cfnlint/rules/functions/FindInMapKeys.py b/src/cfnlint/rules/functions/FindInMapKeys.py index 5a4e19d601..6cc68a03c4 100644 --- a/src/cfnlint/rules/functions/FindInMapKeys.py +++ b/src/cfnlint/rules/functions/FindInMapKeys.py @@ -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}' @@ -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( diff --git a/test/fixtures/templates/good/functions/findinmap_keys.yaml b/test/fixtures/templates/good/functions/findinmap_keys.yaml index 6b5a113579..95fb0e9dc7 100644 --- a/test/fixtures/templates/good/functions/findinmap_keys.yaml +++ b/test/fixtures/templates/good/functions/findinmap_keys.yaml @@ -4,8 +4,10 @@ Mappings: CertificateMap: us-east-1: Arn: arn:aws:acm:us-east-1::certificate/ - 2: + "2": Arn: "" # Empty string is a valid value + key: + 3: "" # Empty string is a valid value Resources: AppAlbListener: Type: AWS::ElasticLoadBalancingV2::Listener @@ -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]