in samtranslator/model/stepfunctions/generators.py [0:0]
def to_cloudformation(self):
"""
Constructs and returns the State Machine resource and any additional resources associated with it.
:returns: a list of resources including the State Machine resource.
:rtype: list
"""
resources = [self.state_machine]
# Defaulting to {} will add the DefinitionSubstitutions field on the transform output even when it is not relevant
if self.definition_substitutions:
self.state_machine.DefinitionSubstitutions = self.definition_substitutions
if self.definition and self.definition_uri:
raise InvalidResourceException(
self.logical_id, "Specify either 'Definition' or 'DefinitionUri' property and not both."
)
elif self.definition:
processed_definition = deepcopy(self.definition)
substitutions = self._replace_dynamic_values_with_substitutions(processed_definition)
if len(substitutions) > 0:
if self.state_machine.DefinitionSubstitutions:
self.state_machine.DefinitionSubstitutions.update(substitutions)
else:
self.state_machine.DefinitionSubstitutions = substitutions
self.state_machine.DefinitionString = self._build_definition_string(processed_definition)
elif self.definition_uri:
self.state_machine.DefinitionS3Location = self._construct_definition_uri()
else:
raise InvalidResourceException(
self.logical_id, "Either 'Definition' or 'DefinitionUri' property must be specified."
)
if self.role and self.policies:
raise InvalidResourceException(
self.logical_id, "Specify either 'Role' or 'Policies' property and not both."
)
elif self.role:
self.state_machine.RoleArn = self.role
elif self.policies:
if not self.managed_policy_map:
raise Exception("Managed policy map is empty, but should not be.")
execution_role = self._construct_role()
self.state_machine.RoleArn = execution_role.get_runtime_attr("arn")
resources.append(execution_role)
else:
raise InvalidResourceException(self.logical_id, "Either 'Role' or 'Policies' property must be specified.")
self.state_machine.StateMachineName = self.name
self.state_machine.StateMachineType = self.type
self.state_machine.LoggingConfiguration = self.logging
self.state_machine.TracingConfiguration = self.tracing
self.state_machine.Tags = self._construct_tag_list()
event_resources = self._generate_event_resources()
resources.extend(event_resources)
return resources