-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiam.tf
61 lines (55 loc) · 1.7 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
resource "random_string" "random" {
length = 4
special = false
upper = false
}
resource "google_service_account" "sa" {
account_id = "gke-oom-monitoring-${random_string.random.result}"
display_name = "gke-oom-monitoring-${random_string.random.result}"
}
resource "kubernetes_service_account" "sa" {
metadata {
namespace = var.namespace
name = "gke-oom-monitoring-${random_string.random.result}"
annotations = {
"iam.gke.io/gcp-service-account" : google_service_account.sa.email
}
}
}
resource "google_service_account_iam_member" "sa_allow_iam_workload_identity" {
service_account_id = google_service_account.sa.name
role = "roles/iam.workloadIdentityUser"
member = "serviceAccount:${var.project}.svc.id.goog[${var.namespace}/gke-oom-monitoring-${random_string.random.result}]"
}
resource "google_project_iam_member" "sa" {
project = var.project
role = "roles/monitoring.metricWriter"
member = "serviceAccount:${google_service_account.sa.email}"
}
resource "kubernetes_role" "sa" {
metadata {
namespace = var.namespace
name = "gke-oom-monitoring-${random_string.random.result}"
}
rule {
api_groups = [""]
resources = ["pods"]
verbs = ["get", "list", "watch"]
}
}
resource "kubernetes_role_binding" "sa" {
metadata {
name = "gke-oom-monitoring-${random_string.random.result}"
namespace = var.namespace
}
role_ref {
api_group = "rbac.authorization.k8s.io"
kind = "Role"
name = kubernetes_role.sa.metadata[0].name
}
subject {
kind = "ServiceAccount"
name = "gke-oom-monitoring-${random_string.random.result}"
namespace = var.namespace
}
}