I have already implemented SFn in Terraform (JSON) file:
data "template_file" "sfn-definition" {
template = file("step-function-definition.json")
}
resource "aws_sfn_state_machine" "sfn_state_machine" {
name = "integration-step-function"
role_arn = aws_iam_role.step_function_role.arn
definition = data.template_file.sfn-definition.rendered
}
It's working fine, but instead of JSON, I would like to use YAML definition. I created the same SFn definition in YAML. I did it in AWS Toolkit (VS Code) and the graph is rendered correctly. I change JSON file to YAML:
template = file("step-function-definition.yaml")
And unfortunately it not works:
08:58:39 Error: Error creating Step Function State Machine: InvalidDefinition:
Invalid State Machine Definition: 'INVALID_JSON_DESCRIPTION:
Unrecognized token 'StartAt': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false')
I suppose that definition
in aws_sfn_state_machine
expect JSON file, but is there any option to define SFn in YAML and use Terraform?
Amazon States Language is JSON-based. So you have to convert your yaml to json first. You can try the following:
template = jsonencode(yamldecode(file("step-function-definition.yaml")))