-
Notifications
You must be signed in to change notification settings - Fork 1
/
16_rbac.tf
100 lines (81 loc) · 2.53 KB
/
16_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
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
resource "kubernetes_service_account_v1" "serviceAccount" {
count = var.podResourceType != "none" ? 1 : 0
metadata {
name = var.consistency.hard.namespaceUniqueName
namespace = var.consistency.hard.namespace
labels = var.consistency.soft.labels
}
automount_service_account_token = true
}
resource "kubernetes_cluster_role_binding_v1" "clusterRoleBinding" {
count = length(var.rbac.clusterRoleRules) > 0 ? 1 : 0
metadata {
name = var.consistency.hard.clusterUniqueName
labels = var.consistency.soft.labels
}
role_ref {
api_group = "rbac.authorization.k8s.io"
kind = "ClusterRole"
name = kubernetes_cluster_role_v1.clusterRole.0.metadata.0.name
}
subject {
kind = "ServiceAccount"
api_group = ""
name = kubernetes_service_account_v1.serviceAccount.0.metadata.0.name
namespace = var.consistency.hard.namespace
}
}
resource "kubernetes_cluster_role_v1" "clusterRole" {
count = length(var.rbac.clusterRoleRules) > 0 ? 1 : 0
metadata {
name = var.consistency.hard.clusterUniqueName
labels = var.consistency.soft.labels
}
dynamic "rule" {
for_each = var.rbac.clusterRoleRules
content {
api_groups = rule.value.apiGroups
resources = rule.value.resources
verbs = rule.value.verbs
resource_names = rule.value.resourceNames
non_resource_urls = rule.value.nonResourceUrls
}
}
}
###
resource "kubernetes_role_binding_v1" "roleBinding" {
count = length(var.rbac.roleRules) > 0 ? 1 : 0
metadata {
name = var.consistency.hard.namespaceUniqueName
namespace = var.consistency.hard.namespace
labels = var.consistency.soft.labels
}
role_ref {
api_group = "rbac.authorization.k8s.io"
kind = "Role"
name = kubernetes_role_v1.role.0.metadata.0.name
}
subject {
kind = "ServiceAccount"
api_group = ""
name = kubernetes_service_account_v1.serviceAccount.0.metadata.0.name
namespace = var.consistency.hard.namespace
}
}
resource "kubernetes_role_v1" "role" {
count = length(var.rbac.roleRules) > 0 ? 1 : 0
metadata {
name = var.consistency.hard.namespaceUniqueName
labels = var.consistency.soft.labels
namespace = var.consistency.hard.namespace
}
dynamic "rule" {
for_each = var.rbac.roleRules
content {
api_groups = rule.value.apiGroups
resources = rule.value.resources
verbs = rule.value.verbs
resource_names = rule.value.resourceNames
}
}
}