forked from particuleio/terraform-kubernetes-addons
-
Notifications
You must be signed in to change notification settings - Fork 2
/
flux.tf
182 lines (154 loc) · 4.99 KB
/
flux.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
locals {
flux = merge(
local.helm_defaults,
{
name = local.helm_dependencies[index(local.helm_dependencies.*.name, "flux")].name
chart = local.helm_dependencies[index(local.helm_dependencies.*.name, "flux")].name
repository = local.helm_dependencies[index(local.helm_dependencies.*.name, "flux")].repository
chart_version = local.helm_dependencies[index(local.helm_dependencies.*.name, "flux")].version
namespace = "flux"
service_account_name = "flux"
enabled = false
default_network_policy = true
},
var.flux
)
values_flux = <<VALUES
rbac:
create: true
pspEnabled: false
syncGarbageCollection:
enabled: true
dry: false
prometheus:
enabled: ${local.kube-prometheus-stack["enabled"] || local.victoria-metrics-k8s-stack["enabled"]}
serviceMonitor:
create: ${local.kube-prometheus-stack["enabled"] || local.victoria-metrics-k8s-stack["enabled"]}
VALUES
}
resource "kubernetes_namespace" "flux" {
count = local.flux["enabled"] ? 1 : 0
metadata {
labels = {
name = local.flux["namespace"]
}
name = local.flux["namespace"]
}
}
resource "kubernetes_role" "flux" {
count = local.flux["enabled"] ? 1 : 0
metadata {
name = "flux-${kubernetes_namespace.flux.*.metadata.0.name[count.index]}"
namespace = kubernetes_namespace.flux.*.metadata.0.name[count.index]
}
rule {
api_groups = ["", "batch", "extensions", "apps"]
resources = ["*"]
verbs = ["*"]
}
}
resource "kubernetes_role_binding" "flux" {
count = local.flux["enabled"] ? 1 : 0
metadata {
name = "flux-${kubernetes_namespace.flux.*.metadata.0.name[count.index]}-binding"
namespace = kubernetes_namespace.flux.*.metadata.0.name[count.index]
}
role_ref {
api_group = "rbac.authorization.k8s.io"
kind = "Role"
name = kubernetes_role.flux.*.metadata.0.name[count.index]
}
subject {
kind = "ServiceAccount"
name = "flux"
namespace = "flux"
}
}
resource "helm_release" "flux" {
count = local.flux["enabled"] ? 1 : 0
repository = local.flux["repository"]
name = local.flux["name"]
chart = local.flux["chart"]
version = local.flux["chart_version"]
timeout = local.flux["timeout"]
force_update = local.flux["force_update"]
recreate_pods = local.flux["recreate_pods"]
wait = local.flux["wait"]
atomic = local.flux["atomic"]
cleanup_on_fail = local.flux["cleanup_on_fail"]
dependency_update = local.flux["dependency_update"]
disable_crd_hooks = local.flux["disable_crd_hooks"]
disable_webhooks = local.flux["disable_webhooks"]
render_subchart_notes = local.flux["render_subchart_notes"]
replace = local.flux["replace"]
reset_values = local.flux["reset_values"]
reuse_values = local.flux["reuse_values"]
skip_crds = local.flux["skip_crds"]
verify = local.flux["verify"]
values = [
local.values_flux,
local.flux["extra_values"]
]
namespace = kubernetes_namespace.flux.*.metadata.0.name[count.index]
depends_on = [
helm_release.kube-prometheus-stack
]
}
resource "kubernetes_network_policy" "flux_default_deny" {
count = local.flux["enabled"] && local.flux["default_network_policy"] ? 1 : 0
metadata {
name = "${kubernetes_namespace.flux.*.metadata.0.name[count.index]}-default-deny"
namespace = kubernetes_namespace.flux.*.metadata.0.name[count.index]
}
spec {
pod_selector {
}
policy_types = ["Ingress"]
}
}
resource "kubernetes_network_policy" "flux_allow_namespace" {
count = local.flux["enabled"] && local.flux["default_network_policy"] ? 1 : 0
metadata {
name = "${kubernetes_namespace.flux.*.metadata.0.name[count.index]}-allow-namespace"
namespace = kubernetes_namespace.flux.*.metadata.0.name[count.index]
}
spec {
pod_selector {
}
ingress {
from {
namespace_selector {
match_labels = {
name = kubernetes_namespace.flux.*.metadata.0.name[count.index]
}
}
}
}
policy_types = ["Ingress"]
}
}
resource "kubernetes_network_policy" "flux_allow_monitoring" {
count = local.flux["enabled"] && local.flux["default_network_policy"] && local.kube-prometheus-stack["enabled"] ? 1 : 0
metadata {
name = "${kubernetes_namespace.flux.*.metadata.0.name[count.index]}-allow-monitoring"
namespace = kubernetes_namespace.flux.*.metadata.0.name[count.index]
}
spec {
pod_selector {
}
ingress {
ports {
port = "3030"
protocol = "TCP"
}
from {
namespace_selector {
match_labels = {
name = kubernetes_namespace.kube-prometheus-stack.*.metadata.0.name[count.index]
}
}
}
}
policy_types = ["Ingress"]
}
}