Background:
I'm creating a Terraform module that provisions an AWS Step Function machine. The Step Function definition consists of a Map state that iterates over the dynamic array input via a CodeBuild Task state. Within the EnvironmentVariablesOverride parameter of the CodeBuild task, I'm passing the respective Map iteration of the array input.
Problem:
I haven't figure out the syntax for providing the EnvironmentVariablesOverride attribute within the CodeBuild Task Parameter field.
Here's the state machine definition:
resource "aws_sfn_state_machine" "this" {
name = <name>
role_arn = <role_arn>
definition = <<EOF
{
"StartAt": "Parallelize Stack",
"States": {
"Parallelize Stack": {
"Type": "Map",
"End": true,
"Iterator": {
"StartAt": "Deploy",
"States": {
"Deploy": {
"Type": "Map",
"Parameters": {
"Path.$": "$$.Map.Item.Value"
},
"End": true,
"Iterator": {
"StartAt": "Plan",
"States": {
"Plan": {
"Type": "Task",
"Resource": "arn:aws:states:::codebuild:startBuild",
"Parameters": {
"ProjectName": "${var.build_name}",
"EnvironmentVariablesOverride.$": "[
{
"name": "PATH",
"type": "PLAINTEXT",
"value": "$.Path"
},
{
"name": "COMMAND",
"type": "PLAINTEXT",
"value": "plan"
}
]"
},
"Next": "Approval"
},
"Approval": {
"Type": "Task",
"Resource": "${aws_sfn_activity.manual_approval.id}",
"End": true
}
}
}
}
}
}
}
}
}
EOF
}
Attempts:
- Using the
EnvironmentVariablesOverridevalue specified above:
"EnvironmentVariablesOverride.$": "[
{
"name": "PATH",
"type": "PLAINTEXT",
"value": "$.Path"
},
{
"name": "COMMAND",
"type": "PLAINTEXT",
"value": "plan"
}
]"
InvalidDefinition: Invalid State Machine Definition: 'INVALID_JSON_DESCRIPTION: Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value
"EnvironmentVariablesOverride.$": States.Format('[
{
"name": "PATH",
"type": "PLAINTEXT",
"value.$": {}
},
{
"name": "COMMAND",
"type": "PLAINTEXT",
"value": "plan"
}
]', "$.Path")
InvalidDefinition: Invalid State Machine Definition: 'INVALID_JSON_DESCRIPTION: Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value
"EnvironmentVariablesOverride.$": [
{
"name": "PATH",
"type": "PLAINTEXT",
"value": "$.Path"
},
{
"name": "COMMAND",
"type": "PLAINTEXT",
"value": "plan"
}
]
InvalidDefinition: Invalid State Machine Definition: 'SCHEMA_VALIDATION_FAILED: The value for the field 'EnvironmentVariablesOverride.$' must be a STRING that contains a JSONPath but was an ARRAY at /States/Parallelize Stack/Iterator/States/Deploy/Iterator/States/Plan/Parameters'
"EnvironmentVariablesOverride.$": "States.JsonToString([
{
"name": "PATH",
"type": "PLAINTEXT",
"value": "$.Path"
},
{
"name": "COMMAND",
"type": "PLAINTEXT",
"value": "plan"
}
])"
InvalidDefinition: Invalid State Machine Definition: 'INVALID_JSON_DESCRIPTION: Illegal unquoted character ((CTRL-CHAR, code 10)): has to be escaped using backslash to be included in string value
"EnvironmentVariablesOverride.$": [
{
"name": "PATH",
"type": "PLAINTEXT",
"value.$": "$.Path"
},
{
"name": "COMMAND",
"type": "PLAINTEXT",
"value": "plan"
}
]
InvalidDefinition: Invalid State Machine Definition: 'SCHEMA_VALIDATION_FAILED: The value for the field 'EnvironmentVariablesOverride.$' must be a STRING that contains a JSONPath but was an ARRAY at /States/Parallelize Stack/Iterator/States/Deploy/Iterator/States/Plan/Parameters'