-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrole_binding.tf
97 lines (78 loc) · 2.22 KB
/
role_binding.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
resource "kubernetes_role_binding" "role_binding" {
for_each = {
for v in local.roles_binding_array : "${v.role}_${v.prefix}_${v.namespace}" => v if v.type == "role_binding"
}
metadata {
name = "${each.value["role"]}-${each.value["prefix"]}-role"
namespace = each.value["namespace"]
}
role_ref {
api_group = "rbac.authorization.k8s.io"
kind = "Role"
name = each.value["role"]
}
dynamic "subject" {
for_each = coalesce(each.value["sa"], [])
content {
kind = "ServiceAccount"
name = subject.value["name"]
namespace = subject.value["namespace"]
}
}
dynamic "subject" {
for_each = coalesce(each.value["users"], [])
content {
kind = "User"
name = subject.value.name
api_group = "rbac.authorization.k8s.io"
}
}
dynamic "subject" {
for_each = coalesce(each.value["groups"], [])
content {
kind = "Group"
name = subject.value
api_group = "rbac.authorization.k8s.io"
}
}
depends_on = [kubernetes_role.roles]
}
resource "kubernetes_role_binding" "role_binding_cluster_role" {
for_each = {
for v in local.roles_binding_cluster_role_array : "${v.cluster_role}_${v.prefix}_${v.namespace}" => v if v.type == "role_binding"
}
metadata {
name = "${each.value["cluster_role"]}-${each.value["prefix"]}-cluster-role"
namespace = each.value["namespace"]
}
role_ref {
api_group = "rbac.authorization.k8s.io"
kind = "ClusterRole"
name = each.value["cluster_role"]
}
dynamic "subject" {
for_each = coalesce(each.value["sa"], [])
content {
kind = "ServiceAccount"
name = subject.value["name"]
namespace = subject.value["namespace"]
}
}
dynamic "subject" {
for_each = coalesce(each.value["users"], [])
content {
kind = "User"
name = subject.value.name
api_group = "rbac.authorization.k8s.io"
}
}
dynamic "subject" {
for_each = coalesce(each.value["groups"], [])
content {
kind = "Group"
name = subject.value
api_group = "rbac.authorization.k8s.io"
}
}
depends_on = [kubernetes_cluster_role.cluster_roles]
}