Skip to content

Commit 8164ed9

Browse files
authored
Support step fn Definition in E1029 (#3792)
1 parent 223132c commit 8164ed9

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

src/cfnlint/rules/functions/SubNeeded.py

+26-18
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,30 @@ def _variable_custom_excluded(self, value):
7878
return re.match(custom_search, value)
7979
return False
8080

81+
def _validate_step_functions(self, var, parameter_string_path, cfn) -> bool:
82+
# Step Function State Machine has a Definition Substitution
83+
# that allows usage of special variables outside of a !Sub
84+
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-stepfunctions-statemachine-definitionsubstitutions.html
85+
86+
for key in ["DefinitionString", "Definition"]:
87+
if key in parameter_string_path:
88+
modified_parameter_string_path = copy.copy(parameter_string_path)
89+
index = parameter_string_path.index(key)
90+
modified_parameter_string_path[index] = "DefinitionSubstitutions"
91+
modified_parameter_string_path = modified_parameter_string_path[
92+
: index + 1
93+
]
94+
modified_parameter_string_path.append(var[2:-1])
95+
96+
if reduce(
97+
lambda c, k: c.get(k, {}),
98+
modified_parameter_string_path,
99+
cfn.template,
100+
):
101+
return True
102+
103+
return False
104+
81105
def match(self, cfn: Template) -> RuleMatches:
82106
matches = []
83107

@@ -93,24 +117,8 @@ def match(self, cfn: Template) -> RuleMatches:
93117
# Get variable
94118
var = parameter_string_path[-1]
95119

96-
# Step Function State Machine has a Definition Substitution
97-
# that allows usage of special variables outside of a !Sub
98-
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-stepfunctions-statemachine-definitionsubstitutions.html
99-
100-
if "DefinitionString" in parameter_string_path:
101-
modified_parameter_string_path = copy.copy(parameter_string_path)
102-
index = parameter_string_path.index("DefinitionString")
103-
modified_parameter_string_path[index] = "DefinitionSubstitutions"
104-
modified_parameter_string_path = modified_parameter_string_path[
105-
: index + 1
106-
]
107-
modified_parameter_string_path.append(var[2:-1])
108-
if reduce(
109-
lambda c, k: c.get(k, {}),
110-
modified_parameter_string_path,
111-
cfn.template,
112-
):
113-
continue
120+
if self._validate_step_functions(var, parameter_string_path, cfn):
121+
continue
114122

115123
# Exclude variables that match custom exclude filters, if configured
116124
# (for third-party tools that pre-process templates

0 commit comments

Comments
 (0)