-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathiam.tf
146 lines (122 loc) · 3.89 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
data "aws_iam_policy_document" "kinesis_firehose_stream_assume_role" {
statement {
effect = "Allow"
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["firehose.amazonaws.com"]
}
}
}
data "aws_iam_policy_document" "kinesis_firehose_access_bucket_assume_policy" {
statement {
effect = "Allow"
actions = [
"s3:AbortMultipartUpload",
"s3:GetBucketLocation",
"s3:GetObject",
"s3:ListBucket",
"s3:ListBucketMultipartUploads",
"s3:PutObject",
]
resources = [
aws_s3_bucket.kinesis_firehose_stream_bucket.arn,
"${aws_s3_bucket.kinesis_firehose_stream_bucket.arn}/*",
]
}
}
data "aws_iam_policy_document" "kinesis_firehose_access_glue_assume_policy" {
statement {
effect = "Allow"
actions = ["glue:GetTableVersions"]
resources = ["*"]
}
}
resource "aws_iam_role" "kinesis_firehose_stream_role" {
name = "kinesis_firehose_stream_role"
assume_role_policy = data.aws_iam_policy_document.kinesis_firehose_stream_assume_role.json
}
resource "aws_iam_role_policy" "kinesis_firehose_access_bucket_policy" {
name = "kinesis_firehose_access_bucket_policy"
role = aws_iam_role.kinesis_firehose_stream_role.name
policy = data.aws_iam_policy_document.kinesis_firehose_access_bucket_assume_policy.json
}
resource "aws_iam_role_policy" "kinesis_firehose_access_glue_policy" {
name = "kinesis_firehose_access_glue_policy"
role = aws_iam_role.kinesis_firehose_stream_role.name
policy = data.aws_iam_policy_document.kinesis_firehose_access_glue_assume_policy.json
}
data "aws_iam_policy_document" "lambda_assume_role" {
statement {
effect = "Allow"
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["lambda.amazonaws.com"]
}
}
}
data "aws_iam_policy_document" "lambda_assume_policy" {
statement {
effect = "Allow"
actions = [
"lambda:InvokeFunction",
"lambda:GetFunctionConfiguration",
]
resources = [
aws_lambda_function.lambda_kinesis_firehose_data_transformation.arn,
"${aws_lambda_function.lambda_kinesis_firehose_data_transformation.arn}:*",
]
}
}
data "aws_iam_policy_document" "lambda_to_cloudwatch_assume_policy" {
statement {
effect = "Allow"
actions = [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
]
resources = ["*"]
}
}
resource "aws_iam_role" "lambda" {
name = "lambda_function_role"
assume_role_policy = data.aws_iam_policy_document.lambda_assume_role.json
}
resource "aws_iam_role_policy" "lambda_policy" {
name = "lambda_function_policy"
role = aws_iam_role.kinesis_firehose_stream_role.name
policy = data.aws_iam_policy_document.lambda_assume_policy.json
}
resource "aws_iam_role_policy" "lambda_to_cloudwatch_policy" {
name = "lambda_to_cloudwatch_policy"
role = aws_iam_role.lambda.name
policy = data.aws_iam_policy_document.lambda_to_cloudwatch_assume_policy.json
}
data "aws_iam_policy_document" "cloudwatch_logs_assume_role" {
statement {
effect = "Allow"
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["logs.${data.aws_region.default.name}.amazonaws.com"]
}
}
}
data "aws_iam_policy_document" "cloudwatch_logs_assume_policy" {
statement {
effect = "Allow"
actions = ["firehose:*"]
resources = [aws_kinesis_firehose_delivery_stream.kinesis_firehose_stream.arn]
}
}
resource "aws_iam_role" "cloudwatch_logs_role" {
name = "cloudwatch_logs_role"
assume_role_policy = data.aws_iam_policy_document.cloudwatch_logs_assume_role.json
}
resource "aws_iam_role_policy" "cloudwatch_logs_policy" {
name = "cloudwatch_logs_policy"
role = aws_iam_role.cloudwatch_logs_role.name
policy = data.aws_iam_policy_document.cloudwatch_logs_assume_policy.json
}