-
Notifications
You must be signed in to change notification settings - Fork 0
/
step_functions.tf
71 lines (61 loc) · 2.57 KB
/
step_functions.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
locals {
composition_state_done = { "Done" : { "Type" : "Succeed" } }
start_composition_states_resources = {
for index, resource in var.resource_composition : "Step${index + 1}" => [{
"Type" : "Wait",
"Seconds" : resource.type == "wait" ? tonumber(resource.params["seconds"]) : 0,
"Next" : "Step${index + 2}"
}, {
"Type" : "Task",
"Resource" : module.scheduler_lambda.arn,
"Parameters" : {
"action" : "start",
"resource_type" : resource.type,
"${resource.type}_params" : resource.params
},
"Next" : ((index + 1) == length(var.resource_composition)) ? "Done" : "Step${index + 2}"
}][resource.type == "wait" ? 0 : 1]
}
start_composition_states = merge(local.start_composition_states_resources, local.composition_state_done)
stop_composition_states_resources = {
for index, resource in reverse(var.resource_composition) : "Step${index + 1}" => [{
"Type" : "Wait",
"Seconds" : resource.type == "wait" ? tonumber(resource.params["seconds"]) : 0,
"Next" : "Step${index + 2}"
}, {
"Type" : "Task",
"Resource" : module.scheduler_lambda.arn,
"Parameters" : {
"action" : "stop",
"resource_type" : resource.type,
"${resource.type}_params" : resource.params
},
"Next" : ((index + 1) == length(var.resource_composition)) ? "Done" : "Step${index + 2}"
}][resource.type == "wait" ? 0 : 1]
}
stop_composition_states = merge(local.stop_composition_states_resources, local.composition_state_done)
}
data "aws_caller_identity" "current" {}
data "aws_region" "current" {}
resource "aws_sfn_state_machine" "composition_start" {
#checkov:skip=CKV_AWS_284
#checkov:skip=CKV_AWS_285:Logging is only valid for express workflows
name = "composition-scheduler-start-${var.composition_name}"
role_arn = module.step_functions_role.arn
tags = var.tags
definition = templatefile("${path.module}/templates/sfn_start_composition.json.tpl", {
composition_name = var.composition_name
states = jsonencode(local.start_composition_states)
})
}
resource "aws_sfn_state_machine" "composition_stop" {
#checkov:skip=CKV_AWS_284
#checkov:skip=CKV_AWS_285:Logging is only valid for express workflows
name = "composition-scheduler-stop-${var.composition_name}"
role_arn = module.step_functions_role.arn
tags = var.tags
definition = templatefile("${path.module}/templates/sfn_stop_composition.json.tpl", {
composition_name = var.composition_name
states = jsonencode(local.stop_composition_states)
})
}