aws-cloudformation / cfn-lint

CloudFormation Linter
MIT No Attribution
2.46k stars 596 forks source link

cfn-lint is not validating the FindInMap function for Mappings under RegionMap. #3784

Closed namireddy closed 1 month ago

namireddy commented 1 month ago

CloudFormation Lint Version

1.16.1

What operating system are you using?

Mac

Describe the bug

cfn-lint is not validating the FindInMap function for values under the Mappings section in RegionMap. In the example below, an invalid reference like 'HVM150' should throw an error since it is not defined in either the east or west regions. Sample Yaml file:

Mappings: RegionMap: us-east-1: HVM64: "ami-0ff8a91507f77f867" HVMG2: "ami-0a584ac55a7631c0c" us-west-1: HVM64: "ami-0bdb828fd58c52235" HVMG2: "ami-066ee5fd4a9ef77f1" Resources: myEC2Instance: Type: "AWS::EC2::Instance" Properties: ImageId: !FindInMap

Expected behavior

Validation should work similarly to non-RegionMap mappings.

Example of working validation yaml

Mappings: InstanceMap: Small: "InstanceType12": "t2.micro" "KeyName": "my-key-pair-small" Resources: MyEC2Instance: Type: "AWS::EC2::Instance" Properties: ImageId: "ami-0ff8a91507f77f867" InstanceType: Fn::FindInMap:

Reproduction template

AWSTemplateFormatVersion: '2010-09-09' Description: AWS CloudFormation Template with FindInMap for non-region section

Mappings: RegionMap: us-east-1: HVM64: "ami-0ff8a91507f77f867" HVMG2: "ami-0a584ac55a7631c0c" us-west-1: HVM64: "ami-0bdb828fd58c52235" HVMG2: "ami-066ee5fd4a9ef77f1" Resources: myEC2Instance: Type: "AWS::EC2::Instance" Properties: ImageId: !FindInMap