diff --git a/src/cfnlint/rules/functions/GetAttFormat.py b/src/cfnlint/rules/functions/GetAttFormat.py index b7c1a382a6..a7fd660855 100644 --- a/src/cfnlint/rules/functions/GetAttFormat.py +++ b/src/cfnlint/rules/functions/GetAttFormat.py @@ -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 @@ -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, diff --git a/test/unit/rules/functions/test_getatt_format.py b/test/unit/rules/functions/test_getatt_format.py index 3ab385aa94..33e6f7c931 100644 --- a/test/unit/rules/functions/test_getatt_format.py +++ b/test/unit/rules/functions/test_getatt_format.py @@ -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"}, }, } @@ -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"],