-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrbac.tf
67 lines (54 loc) · 1.61 KB
/
rbac.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
locals {
rbac_roles = concat(var.roles, local.service_accounts_roles)
}
resource "kubernetes_role" "extra_roles" {
count = length(local.rbac_roles)
metadata {
name = lookup(local.rbac_roles[count.index], "name", "default")
namespace = kubernetes_namespace.namespace.metadata.0.name
}
dynamic "rule" {
for_each = lookup(local.rbac_roles[count.index], "rules", [])
content {
api_groups = rule.value.api_groups
resources = rule.value.resources
verbs = rule.value.verbs
}
}
}
resource "kubernetes_role_binding" "extra_binding" {
count = length(local.rbac_roles)
metadata {
name = lookup(local.rbac_roles[count.index], "name", "default")
namespace = kubernetes_namespace.namespace.metadata.0.name
}
role_ref {
name = element(kubernetes_role.extra_roles.*.metadata.0.name, count.index)
api_group = "rbac.authorization.k8s.io"
kind = "Role"
}
dynamic "subject" {
for_each = lookup(local.rbac_roles[count.index], "groups", [])
content {
kind = "Group"
name = subject.value
api_group = "rbac.authorization.k8s.io"
}
}
dynamic "subject" {
for_each = lookup(local.rbac_roles[count.index], "users", [])
content {
kind = "User"
name = subject.value
api_group = "rbac.authorization.k8s.io"
}
}
dynamic "subject" {
for_each = lookup(local.rbac_roles[count.index], "service_accounts", [])
content {
kind = "ServiceAccount"
name = subject.value
namespace = kubernetes_namespace.namespace.metadata.0.name
}
}
}