forked from provectus/sak-incubator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiam.tf
120 lines (104 loc) · 3.04 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
data "aws_iam_policy_document" "aws_for_fluent_bit_assume_role_policy" {
statement {
actions = ["sts:AssumeRoleWithWebIdentity"]
effect = "Allow"
condition {
test = "StringEquals"
variable = "${replace(var.cluster_oidc_url, "https://", "")}:sub"
values = ["system:serviceaccount:${local.namespace}:${var.service_account_name}"]
}
principals {
identifiers = [var.cluster_oidc_arn]
type = "Federated"
}
}
}
resource "aws_iam_role" "aws_for_fluent_bit_iam_role" {
name = "${var.cluster_name}-aws-for-fluent-bit"
assume_role_policy = data.aws_iam_policy_document.aws_for_fluent_bit_assume_role_policy.json
tags = {
Environment = var.environment
Project = var.project
}
}
resource "aws_iam_policy" "cloudwatch_logs_policy" {
count = var.cloudwatch_enabled ? 1 : 0
name = "${var.cluster_name}-aws-for-fluent-bit-cloudwatch-policy"
policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:PutRetentionPolicy",
"logs:CreateLogStream",
"logs:DescribeLogStreams",
"logs:PutLogEvents"
],
"Resource": [
"arn:aws:logs:${var.aws_region}:${var.aws_account}:log-group:${var.cloudwatch_log_group_name}:log-stream:*"
]
}
]
}
POLICY
}
resource "aws_iam_role_policy_attachment" "cloudwatch_logs_role_policy_attachment" {
count = var.cloudwatch_enabled ? 1 : 0
role = aws_iam_role.aws_for_fluent_bit_iam_role.name
policy_arn = aws_iam_policy.cloudwatch_logs_policy[count.index].arn
}
resource "aws_iam_policy" "firehose_policy" {
count = var.firehose_enabled ? 1 : 0
name = "${var.cluster_name}-aws-for-fluent-bit-firehose-policy"
policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"firehose:PutRecord",
"firehose:PutRecordBatch"
],
"Resource": [
"arn:aws:firehose:${var.aws_region}:${var.aws_account}:deliverystream/${var.firehose_delivery_stream}"
]
}
]
}
POLICY
}
resource "aws_iam_role_policy_attachment" "firehose_role_policy_attachment" {
count = var.firehose_enabled ? 1 : 0
role = aws_iam_role.aws_for_fluent_bit_iam_role.name
policy_arn = aws_iam_policy.firehose_policy[count.index].arn
}
resource "aws_iam_policy" "kinesis_policy" {
count = var.kinesis_enabled ? 1 : 0
name = "${var.cluster_name}-aws-for-fluent-bit-kinesis-policy"
policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"kinesis:PutRecord",
"kinesis:PutRecords"
],
"Resource": [
"arn:aws:kinesis:${var.aws_region}:${var.aws_account}:stream/${var.kinesis_stream}"
]
}
]
}
POLICY
}
resource "aws_iam_role_policy_attachment" "kinesis_role_policy_attachment" {
count = var.kinesis_enabled ? 1 : 0
role = aws_iam_role.aws_for_fluent_bit_iam_role.name
policy_arn = aws_iam_policy.kinesis_policy[count.index].arn
}