Skip to content

Commit

Permalink
GetAtts to array returns a string (#3639)
Browse files Browse the repository at this point in the history
  • Loading branch information
kddejong committed Aug 29, 2024
1 parent eeb1208 commit 44b7aa1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
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

0 comments on commit 44b7aa1

Please sign in to comment.