-
Notifications
You must be signed in to change notification settings - Fork 0
/
state-machine.tf
81 lines (67 loc) · 2.02 KB
/
state-machine.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
72
73
74
75
76
77
78
79
80
81
variable project_name {}
variable detect_faces_function_arn {}
variable add_to_collection_function_arn {}
variable no_face_detected_function_arn {}
variable thumbnail_function_arn {}
data template_file state_machine {
template = file("${path.module}/state-machine.json")
vars = {
detect_faces_function_arn = var.detect_faces_function_arn
no_face_detected_function_arn = var.no_face_detected_function_arn
add_to_collection_function_arn = var.add_to_collection_function_arn
thumbnail_function_arn = var.thumbnail_function_arn
}
}
#
# state-machine assume role policy
#
data aws_iam_policy_document state_machine_assume_role_policy {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = [
"events.amazonaws.com",
"states.amazonaws.com"
]
}
}
}
resource aws_iam_role state_machine_role {
name = "${var.project_name}-state-machine-role"
assume_role_policy = data.aws_iam_policy_document.state_machine_assume_role_policy.json
}
resource aws_sfn_state_machine state_machine {
definition = data.template_file.state_machine.rendered
name = "${var.project_name}-state-machine"
role_arn = aws_iam_role.state_machine_role.arn
}
#
# state-machine policy
#
data aws_iam_policy_document state_machine_policy {
statement {
actions = ["lambda:InvokeFunction"]
resources = ["*"]
}
statement {
actions = ["states:StartExecution"]
resources = ["*"]
}
statement {
actions = ["logs:*"]
resources = ["*"]
}
}
resource aws_iam_policy state_machine_policy {
name = "${var.project_name}-state-machine-policy"
policy = data.aws_iam_policy_document.state_machine_policy.json
}
// TODO : remove aws_iam_role_policy_attachment
resource aws_iam_role_policy_attachment state_machine_role_attached_policy {
role = aws_iam_role.state_machine_role.name
policy_arn = aws_iam_policy.state_machine_policy.arn
}
output state_machine_arn {
value = aws_sfn_state_machine.state_machine.id
}