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

Add more exceptions E1040 #3636

Merged
merged 2 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/cfnlint/rules/functions/GetAttFormat.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def __init__(self):
"AWS::ServiceCatalog::CloudFormationProvisionedProduct",
]

self._resource_type_attribute_exceptions = [("AWS::SSM::Parameter", "Value")]

def validate(
self, validator: Validator, _, instance: Any, schema: Any
) -> ValidationResult:
Expand All @@ -50,11 +52,15 @@ def validate(
t, validator.context.regions
):
region = regions[0]
getatt_ptr = validator.context.resources[resource].get_atts(region)[attr]

if t in self._resource_type_exceptions:
return

if (t, attr) in self._resource_type_attribute_exceptions:
return

getatt_ptr = validator.context.resources[resource].get_atts(region)[attr]

getatt_schema = resource_schema.resolver.resolve_cfn_pointer(getatt_ptr)
getatt_fmt = getatt_schema.get("format")
if getatt_fmt != fmt:
Expand Down
7 changes: 7 additions & 0 deletions test/unit/rules/functions/test_getatt_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def template():
"MyProvisionedProduct": {
"Type": "AWS::ServiceCatalog::CloudFormationProvisionedProduct"
},
"MySSMParameter": {"Type": "AWS::SSM::Parameter"},
},
}

Expand Down Expand Up @@ -64,6 +65,12 @@ def template():
{"format": "AWS::EC2::SecurityGroup.GroupId"},
[],
),
(
"Valid GetAtt because of exception with attribute",
["MySSMParameter", "Value"],
{"format": "AWS::EC2::Image.Id"},
[],
),
(
"Invalid GetAtt with a bad format",
["MyBucket", "Arn"],
Expand Down
Loading