-
Notifications
You must be signed in to change notification settings - Fork 0
/
iam.tf
113 lines (105 loc) · 2.73 KB
/
iam.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
107
108
109
110
111
112
113
resource "aws_iam_role" "sfn" {
name = "${var.project}-snf-exec"
path = "/"
# Terraform's "jsonencode" function converts a
# Terraform expression result to valid JSON syntax.
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Effect = "Allow"
Principal = {
Service = "states.amazonaws.com"
}
},
]
})
}
resource "aws_iam_role_policy_attachment" "policy_1" {
role = aws_iam_role.sfn.name
policy_arn = aws_iam_policy.snf_policy.arn
}
resource "aws_iam_policy" "snf_policy" {
name = "${var.project}-snf-policy"
path = "/"
description = "AWS Step Functions role to invoke lambda for batch logs ingestion."
# Terraform's "jsonencode" function converts a
# Terraform expression result to valid JSON syntax.
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
"Sid" = "InvokeLambda"
Action = [
"lambda:InvokeFunction",
]
Effect = "Allow"
Resource = "${module.lambda_batch_ingestion.lambda_function_arn}:*"
},
{
"Sid" = "ListObjectsProcess"
Action = [
"s3:ListBucket",
]
Effect = "Allow"
Resource = "arn:aws:s3:::${var.bucket_name}"
},
{
"Sid" = "StartStepFunctionsExec"
Action = [
"states:StartExecution",
"states:DescribeExecution",
"states:StopExecution",
"events:PutTargets",
"events:PutRule",
"events:DescribeRule"
]
Effect = "Allow"
Resource = "*"
},
{
"Sid" = "xray"
Action = [
"xray:PutTraceSegments",
"xray:PutTelemetryRecords",
"xray:GetSamplingRules",
"xray:GetSamplingTargets"
]
Effect = "Allow"
Resource = "*"
},
]
})
}
resource "aws_iam_policy" "lambda_exec" {
name = "${var.project}-lambda-exec"
path = "/service-role/"
description = "Lambda execution role to send Logs from S3 to Opensearch"
# Terraform's "jsonencode" function converts a
# Terraform expression result to valid JSON syntax.
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
"Sid" = "s3"
Action = [
"s3:GetObject",
"s3:ListBucket"
]
Effect = "Allow"
Resource = ["arn:aws:s3:::${var.bucket_name}", "arn:aws:s3:::${var.bucket_name}/*"]
},
{
"Sid" = "cloudwatch",
Effect = "Allow",
Action = [
"logs:CreateLogStream",
"logs:CreateLogGroup",
"logs:PutLogEvents"
],
Resource = "*"
},
]
})
}