forked from particuleio/terraform-kubernetes-addons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeycloak.tf
166 lines (141 loc) · 4.51 KB
/
keycloak.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
locals {
keycloak = merge(
local.helm_defaults,
{
name = "keycloak"
namespace = "keycloak"
chart = "keycloak"
repository = "https://codecentric.github.io/helm-charts"
enabled = false
chart_version = "9.5.0"
version = "11.0.2"
default_network_policy = true
},
var.keycloak
)
values_keycloak = <<VALUES
image:
tag: ${local.keycloak["version"]}
serviceMonitor:
enabled: ${local.kube-prometheus-stack["enabled"]}
priorityClassName: ${local.priority-class["create"] ? kubernetes_priority_class.kubernetes_addons[0].metadata[0].name : ""}
VALUES
}
resource "kubernetes_namespace" "keycloak" {
count = local.keycloak["enabled"] ? 1 : 0
metadata {
labels = {
name = local.keycloak["namespace"]
}
name = local.keycloak["namespace"]
}
}
resource "helm_release" "keycloak" {
count = local.keycloak["enabled"] ? 1 : 0
repository = local.keycloak["repository"]
name = local.keycloak["name"]
chart = local.keycloak["chart"]
version = local.keycloak["chart_version"]
timeout = local.keycloak["timeout"]
force_update = local.keycloak["force_update"]
recreate_pods = local.keycloak["recreate_pods"]
wait = local.keycloak["wait"]
atomic = local.keycloak["atomic"]
cleanup_on_fail = local.keycloak["cleanup_on_fail"]
dependency_update = local.keycloak["dependency_update"]
disable_crd_hooks = local.keycloak["disable_crd_hooks"]
disable_webhooks = local.keycloak["disable_webhooks"]
render_subchart_notes = local.keycloak["render_subchart_notes"]
replace = local.keycloak["replace"]
reset_values = local.keycloak["reset_values"]
reuse_values = local.keycloak["reuse_values"]
skip_crds = local.keycloak["skip_crds"]
verify = local.keycloak["verify"]
values = [
local.values_keycloak,
local.keycloak["extra_values"]
]
namespace = kubernetes_namespace.keycloak.*.metadata.0.name[count.index]
depends_on = [
helm_release.kube-prometheus-stack
]
}
resource "kubernetes_network_policy" "keycloak_default_deny" {
count = local.keycloak["enabled"] && local.keycloak["default_network_policy"] ? 1 : 0
metadata {
name = "${kubernetes_namespace.keycloak.*.metadata.0.name[count.index]}-default-deny"
namespace = kubernetes_namespace.keycloak.*.metadata.0.name[count.index]
}
spec {
pod_selector {
}
policy_types = ["Ingress"]
}
}
resource "kubernetes_network_policy" "keycloak_allow_namespace" {
count = local.keycloak["enabled"] && local.keycloak["default_network_policy"] ? 1 : 0
metadata {
name = "${kubernetes_namespace.keycloak.*.metadata.0.name[count.index]}-allow-namespace"
namespace = kubernetes_namespace.keycloak.*.metadata.0.name[count.index]
}
spec {
pod_selector {
}
ingress {
from {
namespace_selector {
match_labels = {
name = kubernetes_namespace.keycloak.*.metadata.0.name[count.index]
}
}
}
}
policy_types = ["Ingress"]
}
}
resource "kubernetes_network_policy" "keycloak_allow_monitoring" {
count = local.keycloak["enabled"] && local.keycloak["default_network_policy"] ? 1 : 0
metadata {
name = "${kubernetes_namespace.keycloak.*.metadata.0.name[count.index]}-allow-monitoring"
namespace = kubernetes_namespace.keycloak.*.metadata.0.name[count.index]
}
spec {
pod_selector {
}
ingress {
ports {
port = "9990"
protocol = "TCP"
}
from {
namespace_selector {
match_labels = {
"${local.labels_prefix}/component" = "monitoring"
}
}
}
}
policy_types = ["Ingress"]
}
}
resource "kubernetes_network_policy" "keycloak_allow_ingress" {
count = local.keycloak["enabled"] && local.keycloak["default_network_policy"] ? 1 : 0
metadata {
name = "${kubernetes_namespace.keycloak.*.metadata.0.name[count.index]}-allow-ingress"
namespace = kubernetes_namespace.keycloak.*.metadata.0.name[count.index]
}
spec {
pod_selector {
}
ingress {
from {
namespace_selector {
match_labels = {
"${local.labels_prefix}/component" = "ingress"
}
}
}
}
policy_types = ["Ingress"]
}
}