Skip to content

Commit

Permalink
Skip getatt validation with custom resources (#3346)
Browse files Browse the repository at this point in the history
* Add exceptions for getatt format type
  • Loading branch information
kddejong authored Jun 20, 2024
1 parent 4c3a445 commit 41a17e3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/cfnlint/rules/functions/GetAttFormat.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ def __init__(self):
"AWS::EC2::SecurityGroup.GroupId",
"AWS::EC2::SecurityGroup.GroupIds",
]
self._resource_type_exceptions = [
"AWS::CloudFormation::CustomResource",
"AWS::CloudFormation::Stack",
]

def validate(
self, validator: Validator, _, instance: Any, schema: Any
Expand All @@ -40,6 +44,9 @@ def validate(
getatt_ptr = validator.context.resources[resource].get_atts[attr]
t = validator.context.resources[resource].type

if t in self._resource_type_exceptions:
return

for (
_,
resource_schema,
Expand Down
14 changes: 14 additions & 0 deletions test/unit/rules/functions/test_getatt_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ def template():
"MyBucket": {"Type": "AWS::S3::Bucket"},
"MyVpc": {"Type": "AWS::EC2::VPC"},
"MySecurityGroup": {"Type": "AWS::EC2::SecurityGroup"},
"MyCustomResource": {"Type": "Custom::CustomResource"},
"MySubTemplate": {"Type": "AWS::CloudFormation::Stack"},
},
}

Expand All @@ -35,6 +37,18 @@ def template():
{"format": "AWS::EC2::VPC.Id"},
[],
),
(
"Valid GetAtt to a custom resource",
["MyCustomResource", "ImageId"],
{"format": "AWS::EC2::VPC.Id"},
[],
),
(
"Valid GetAtt to a sub template ",
["MySubTemplate", "Outputs.ImageId"],
{"format": "AWS::EC2::VPC.Id"},
[],
),
(
"Valid GetAtt because of exception",
["MyBucket", "Arn"],
Expand Down

0 comments on commit 41a17e3

Please sign in to comment.