Skip to content

Commit 6385ba9

Browse files
authored
E1018 Split doesn't support dynamic references (#2786)
1 parent b7bc622 commit 6385ba9

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

src/cfnlint/helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@
7777
re.I | re.S,
7878
)
7979
REGEX_DYN_REF = re.compile(r"^.*{{resolve:.+}}.*$")
80-
REGEX_DYN_REF_SSM = re.compile(r"^.*{{resolve:ssm:[a-zA-Z0-9_\.\-/]+:\d+}}.*$")
80+
REGEX_DYN_REF_SSM = re.compile(r"^.*{{resolve:ssm:[a-zA-Z0-9_\.\-/]+(:\d+)?}}.*$")
8181
REGEX_DYN_REF_SSM_SECURE = re.compile(
82-
r"^.*{{resolve:ssm-secure:[a-zA-Z0-9_\.\-/]+:\d+}}.*$"
82+
r"^.*{{resolve:ssm-secure:[a-zA-Z0-9_\.\-/]+(:\d+)?}}.*$"
8383
)
8484

8585

src/cfnlint/rules/functions/Split.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
SPDX-License-Identifier: MIT-0
44
"""
5+
import json
6+
7+
import regex as re
8+
9+
from cfnlint.helpers import REGEX_DYN_REF_SSM
510
from cfnlint.rules import CloudFormationLintRule, RuleMatch
611

712

@@ -34,8 +39,19 @@ def _test_delimiter(self, delimiter, path):
3439
matches.append(RuleMatch(path, message.format("/".join(map(str, path)))))
3540
return matches
3641

42+
def _check_dyn_ref_value(self, value, path):
43+
"""Chec item type"""
44+
matches = []
45+
if isinstance(value, str):
46+
if re.match(REGEX_DYN_REF_SSM, value):
47+
message = f'Fn::Split does not support dynamic references at {"/".join(map(str, path[:]))}'
48+
matches.append(RuleMatch(path[:], message))
49+
50+
return matches
51+
3752
def _test_string(self, s, path):
3853
matches = []
54+
matches.extend(self._check_dyn_ref_value(json.dumps(s), path[:]))
3955
if isinstance(s, dict):
4056
if len(s) == 1:
4157
for key, _ in s.items():

test/fixtures/templates/bad/functions_split.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,10 @@ Resources:
3131
AvailabilityZone: !Select
3232
- 0
3333
- Fn::Split: {Ref: AWS::Region}
34+
myInstance4:
35+
Type: AWS::EC2::Instance
36+
Properties:
37+
ImageId: String
38+
AvailabilityZone: !Select
39+
- 0
40+
- !Split [":", "{{resolve:ssm:/vpc/subnets/private}}"]

test/unit/rules/functions/test_split.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def test_file_positive(self):
2121

2222
def test_file_negative(self):
2323
"""Test failure"""
24-
self.helper_file_negative("test/fixtures/templates/bad/functions_split.yaml", 3)
24+
self.helper_file_negative("test/fixtures/templates/bad/functions_split.yaml", 4)
2525

2626
def test_split_parts(self):
2727
rule = Split()

0 commit comments

Comments
 (0)