Skip to main content

Module: step-functions

Terraform module to provision AWS Step Functions.

Usage

For a complete example, see examples/complete

For automated tests of the complete example using bats and Terratest (which tests and deploys the example on AWS), see test.

  locals {
enabled = module.this.enabled

logging_configuration = {
include_execution_data = true
level = "ALL"
}

# https://docs.aws.amazon.com/step-functions/latest/dg/concepts-amazon-states-language.html
# https://docs.aws.amazon.com/step-functions/latest/dg/connect-parameters.html
definition = {
"Comment" = "Test Step Function"
"StartAt" = "Hello"
"States" = {
"Hello" = {
"Type" = "Pass"
"Result" = "Hello"
"Next" = "World"
},
"World" = {
"Type" = "Pass"
"Result" = "World"
"Next" = "Send message to SQS"
},
# https://docs.aws.amazon.com/step-functions/latest/dg/connect-sqs.html
"Send message to SQS" = {
"Type" = "Task"
"Resource" = "arn:aws:states:::sqs:sendMessage"
"Parameters" = {
"QueueUrl" = local.enabled ? aws_sqs_queue.default[0].url : ""
"MessageBody" = "Hello World"
}
"Next" = "Publish to SNS"
}
# https://docs.aws.amazon.com/step-functions/latest/dg/connect-sns.html
"Publish to SNS" = {
"Type" = "Task",
"Resource" = "arn:aws:states:::sns:publish"
"Parameters" = {
"TopicArn" = module.sns.sns_topic_arn
"Message" = "Hello World"
}
"End" = true
}
}
}

iam_policies = {
# https://docs.aws.amazon.com/step-functions/latest/dg/sns-iam.html
"SnsAllowPublish" = {
effect = "Allow"
actions = [
"sns:Publish"
]
resources = [
module.sns.sns_topic_arn
]
}

# https://docs.aws.amazon.com/step-functions/latest/dg/sqs-iam.html
"SqsAllowSendMessage" = {
effect = "Allow"
actions = [
"sqs:SendMessage"
]
resources = [
local.enabled ? aws_sqs_queue.default[0].arn : ""
]
}
}
}

module "step_function" {
source = "cloudposse/step-functions/aws"
# Cloud Posse recommends pinning every module to a specific version
version = "x.x.x"

type = "EXPRESS"
tracing_enabled = true
logging_configuration = local.logging_configuration
definition = local.definition
iam_policies = local.iam_policies

context = module.this.context
}

module "sns" {
source = "cloudposse/sns-topic/aws"
version = "0.20.2"

sqs_dlq_enabled = true
fifo_topic = true
fifo_queue_enabled = true

context = module.this.context
}

resource "aws_sqs_queue" "default" {
count = local.enabled ? 1 : 0

name = module.this.id
fifo_queue = false
visibility_timeout_seconds = 30
message_retention_seconds = 86400
max_message_size = 2048
delay_seconds = 90
receive_wait_time_seconds = 10

tags = module.this.tags
}