Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

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

Closed
namireddy opened this issue Oct 21, 2024 · 0 comments · Fixed by #3785
Closed

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

namireddy opened this issue Oct 21, 2024 · 0 comments · Fixed by #3785

Comments

@namireddy
Copy link

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
- RegionMap
- !Ref 'AWS::Region'
- HVM150
InstanceType: t2.micro

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:
- InstanceMap
- Small
- "InstanceType12"

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
- RegionMap
- !Ref 'AWS::Region'
- HVM150
InstanceType: t2.micro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant