generated from kedacore/github-template
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.tf
195 lines (172 loc) · 4.64 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
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
locals {
keda_role_name = "keda-operator"
workload1_role_name = "keda-workload-1"
workload2_role_name = "keda-workload-2"
keda_clusters_trusted_relations = jsonencode(
[for index, provider in aws_iam_openid_connect_provider.oidc_providers :
{
Effect : "Allow",
Principal : {
"Federated" : "${provider.arn}"
},
Action : "sts:AssumeRoleWithWebIdentity",
Condition : {
StringEquals : {
"${replace(var.identity_providers[index].oidc_issuer_url, "https://", "")}:sub" : "system:serviceaccount:keda:keda-operator",
"${replace(var.identity_providers[index].oidc_issuer_url, "https://", "")}:aud" : "sts.amazonaws.com"
}
}
}
]
)
}
resource "aws_iam_user" "e2e_test" {
name = "e2e-test-user"
path = "/"
tags = var.tags
}
resource "aws_iam_access_key" "e2e_test" {
user = aws_iam_user.e2e_test.name
}
resource "aws_iam_user_policy_attachment" "user_assignement" {
user = aws_iam_user.e2e_test.name
policy_arn = aws_iam_policy.policy.arn
}
data "tls_certificate" "certs" {
count = length(var.identity_providers)
url = var.identity_providers[count.index].oidc_issuer_url
}
resource "aws_iam_openid_connect_provider" "oidc_providers" {
count = length(data.tls_certificate.certs)
url = var.identity_providers[count.index].oidc_issuer_url
client_id_list = [
"sts.amazonaws.com",
]
thumbprint_list = [data.tls_certificate.certs[count.index].certificates[0].sha1_fingerprint]
tags = var.tags
}
resource "aws_iam_role" "keda_role" {
name = local.keda_role_name
tags = var.tags
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": ${local.keda_clusters_trusted_relations}
}
EOF
}
resource "aws_iam_role_policy_attachment" "keda_role_assignement" {
role = aws_iam_role.keda_role.name
policy_arn = aws_iam_policy.policy.arn
}
// This is the primary role to be used for almost all the
// e2e tests. It allows any action over any (suported resource)
// except over the assume role queues. This role also allows
// to assume workload-1 role using sts:AssumeRole
resource "aws_iam_policy" "policy" {
name = "e2e-test-policy"
tags = var.tags
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"aps:*",
"cloudwatch:*",
"dynamodb:*",
"kinesis:*",
"sqs:*",
"secretsmanager:*",
"kms:*"
],
"Resource": "*"
},
{
"Effect": "Deny",
"Action": "sqs:GetQueueAttributes",
"Resource": [
"arn:aws:sqs:*:589761922677:assume-role-*"
]
},
{
"Effect": "Allow",
"Action": "sts:AssumeRole",
"Resource": [
"arn:aws:iam::*:role/${local.workload1_role_name}"
]
}
]
}
EOF
}
resource "aws_iam_role" "workload1_role" {
name = local.workload1_role_name
tags = var.tags
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Sid" : "",
"Effect" : "Allow",
"Action" : "sts:AssumeRole",
"Principal" : {
"AWS" : "${aws_iam_role.keda_role.arn}"
}
}
]
}
EOF
}
resource "aws_iam_role" "workload2_role" {
name = local.workload2_role_name
tags = var.tags
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": ${local.keda_clusters_trusted_relations}
}
EOF
}
resource "aws_iam_policy" "workload1_role_policy" {
name = "e2e-test-assume-role-policy-workload1"
tags = var.tags
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "sqs:GetQueueAttributes",
"Resource": "arn:aws:sqs:*:589761922677:assume-role-workload1-queue-*"
}
]
}
EOF
}
resource "aws_iam_policy" "workload2_role_policy" {
name = "e2e-test-assume-role-policy-workload2"
tags = var.tags
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "sqs:GetQueueAttributes",
"Resource": "arn:aws:sqs:*:589761922677:assume-role-workload2-queue-*"
}
]
}
EOF
}
resource "aws_iam_role_policy_attachment" "workload1_role_assignement" {
role = aws_iam_role.workload1_role.name
policy_arn = aws_iam_policy.workload1_role_policy.arn
}
resource "aws_iam_role_policy_attachment" "workload2_role_assignement" {
role = aws_iam_role.workload2_role.name
policy_arn = aws_iam_policy.workload2_role_policy.arn
}