-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.tf
106 lines (93 loc) · 2.1 KB
/
main.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
provider "aws" {}
resource "aws_iam_role" "iterator" {
name = "hfl-iterator"
assume_role_policy = file("${path.module}/assume_role_policy.json")
}
resource "aws_lambda_function" "iterator" {
function_name = "hfl-iterator"
role = aws_iam_role.iterator.arn
s3_bucket = var.s3_bucket
s3_key = var.s3_key
handler = "bootstrap"
runtime = "provided.al2"
timeout = 5
environment {
variables = {
"LAMBDA" = var.target_lambda
"REGION" = "us-west-2"
}
}
}
resource "aws_sfn_state_machine" "hfl" {
name = "hfl-state-machine"
role_arn = aws_iam_role.hfl-sfn.arn
definition = templatefile("${path.module}/definition.json", {
iterator_arn = aws_lambda_function.iterator.arn
})
depends_on = [
aws_lambda_function.iterator]
}
resource "aws_iam_role_policy" "hfl" {
name = "hfl-iterator"
role = aws_iam_role.iterator.id
policy = <<EOP
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "arn:aws:logs:*:*:*"
},
{
"Effect": "Allow",
"Action": [
"lambda:InvokeFunction"
],
"Resource": "${var.target_lambda}"
}
]
}
EOP
}
resource "aws_iam_role" "hfl-sfn" {
name = "hfl-sfn"
assume_role_policy = data.aws_iam_policy_document.sfn_assume_role_policy_document.json
}
data "aws_iam_policy_document" "sfn_assume_role_policy_document" {
statement {
actions = [
"sts:AssumeRole"
]
principals {
type = "Service"
identifiers = [
"states.us-west-2.amazonaws.com",
"events.amazonaws.com"
]
}
}
}
resource "aws_iam_role_policy" "hfl-lambda-execution" {
name = "hfl-lambda-execution"
role = aws_iam_role.hfl-sfn.id
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"lambda:InvokeFunction",
"states:StartExecution"
],
"Effect": "Allow",
"Resource": "*"
}
]
}
EOF
}