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

GetAtts to array returns a string #3639

Merged
merged 1 commit 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
7 changes: 5 additions & 2 deletions src/cfnlint/rules/functions/GetAtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from cfnlint.helpers import ensure_list, is_types_compatible
from cfnlint.jsonschema import ValidationError, ValidationResult, Validator
from cfnlint.rules.functions._BaseFn import BaseFn, all_types
from cfnlint.rules.functions._BaseFn import BaseFn
from cfnlint.schema import PROVIDER_SCHEMA_MANAGER


Expand All @@ -29,7 +29,7 @@ class GetAtt(BaseFn):
tags = ["functions", "getatt"]

def __init__(self) -> None:
super().__init__("Fn::GetAtt", all_types)
super().__init__("Fn::GetAtt", ("string", "boolean", "integer", "number"))

def schema(self, validator, instance) -> dict[str, Any]:
resource_functions = []
Expand Down Expand Up @@ -127,6 +127,9 @@ def _resolve_getatt(
continue

schema_types = ensure_list(getatt_schema.get("type"))
if "array" in schema_types:
schema_types.remove("array")
schema_types.append("string")

types = ensure_list(s.get("type"))

Expand Down
8 changes: 4 additions & 4 deletions test/unit/rules/functions/test_getatt.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ def validate(self, validator, s, instance, schema):
[
ValidationError(
"{'Fn::GetAtt': 'MyBucket.Arn'} is not of type 'array'",
path=deque(["Fn::GetAtt"]),
schema_path=deque(["type"]),
path=deque([]),
schema_path=deque([]),
validator="fn_getatt",
),
],
Expand All @@ -149,8 +149,8 @@ def validate(self, validator, s, instance, schema):
[
ValidationError(
"{'Fn::GetAtt': 'MyBucket.Arn'} is not of type 'array', 'object'",
path=deque(["Fn::GetAtt"]),
schema_path=deque(["type"]),
path=deque([]),
schema_path=deque([]),
validator="fn_getatt",
),
],
Expand Down
10 changes: 1 addition & 9 deletions test/unit/rules/functions/test_sub.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,15 +274,7 @@ def context(cfn):
"Invalid Fn::Sub with a GetAtt to an array of attributes",
{"Fn::Sub": "${MySimpleAd.DnsIpAddresses}"},
{"type": "string"},
[
ValidationError(
("'MySimpleAd.DnsIpAddresses' is not of type 'string'"),
instance="MySimpleAd.DnsIpAddresses",
path=deque(["Fn::Sub"]),
schema_path=deque([]),
validator="fn_sub",
),
],
[],
),
(
"Invalid Fn::Sub with a GetAtt to an integer",
Expand Down
Loading