-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.tf
159 lines (132 loc) · 4.13 KB
/
main.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
resource "null_resource" "dependencies" {
triggers = var.dependency_ids
}
resource "argocd_project" "this" {
count = var.argocd_project == null ? 1 : 0
metadata {
name = var.destination_cluster != "in-cluster" ? "kube-prometheus-stack-${var.destination_cluster}" : "kube-prometheus-stack"
namespace = "argocd"
}
spec {
description = "kube-prometheus-stack application project for cluster ${var.destination_cluster}"
source_repos = ["https://github.com/camptocamp/devops-stack-module-kube-prometheus-stack.git"]
destination {
name = var.destination_cluster
namespace = "kube-prometheus-stack"
}
# This extra destination block is needed by the v1/Service
# kube-prometheus-stack-coredns and kube-prometheus-stack-kubelet
# that have to be inside kube-system.
destination {
name = var.destination_cluster
namespace = "kube-system"
}
orphaned_resources {
warn = true
}
cluster_resource_whitelist {
group = "*"
kind = "*"
}
}
}
resource "kubernetes_namespace" "kube_prometheus_stack_namespace" {
metadata {
name = "kube-prometheus-stack"
}
depends_on = [
resource.null_resource.dependencies,
]
}
resource "kubernetes_secret" "thanos_object_storage_secret" {
count = var.metrics_storage_main != null ? 1 : 0
metadata {
name = "thanos-objectstorage"
namespace = "kube-prometheus-stack"
}
data = {
"thanos.yaml" = yamlencode(var.metrics_storage_main.storage_config)
}
depends_on = [
resource.null_resource.dependencies,
resource.kubernetes_namespace.kube_prometheus_stack_namespace
]
}
resource "random_password" "oauth2_cookie_secret" {
length = 16
special = false
}
data "utils_deep_merge_yaml" "values" {
input = [for i in concat(local.helm_values, var.helm_values) : yamlencode(i)]
append_list = var.deep_merge_append_list
}
resource "argocd_application" "this" {
metadata {
name = var.destination_cluster != "in-cluster" ? "kube-prometheus-stack-${var.destination_cluster}" : "kube-prometheus-stack"
namespace = "argocd"
labels = merge({
"application" = "kube-prometheus-stack"
"cluster" = var.destination_cluster
}, var.argocd_labels)
}
timeouts {
create = "15m"
delete = "15m"
}
wait = var.app_autosync == { "allow_empty" = tobool(null), "prune" = tobool(null), "self_heal" = tobool(null) } ? false : true
spec {
project = var.argocd_project == null ? argocd_project.this[0].metadata.0.name : var.argocd_project
source {
repo_url = "https://github.com/camptocamp/devops-stack-module-kube-prometheus-stack.git"
path = "charts/kube-prometheus-stack"
target_revision = var.target_revision
plugin {
name = "kustomized-helm"
env {
name = "HELM_ARGS"
value = "--name-template kube-prometheus-stack"
}
env {
name = "HELM_VALUES"
value = data.utils_deep_merge_yaml.values.output
}
}
}
destination {
name = var.destination_cluster
namespace = "kube-prometheus-stack"
}
sync_policy {
dynamic "automated" {
for_each = toset(var.app_autosync == { "allow_empty" = tobool(null), "prune" = tobool(null), "self_heal" = tobool(null) } ? [] : [var.app_autosync])
content {
prune = automated.value.prune
self_heal = automated.value.self_heal
allow_empty = automated.value.allow_empty
}
}
retry {
backoff {
duration = "20s"
max_duration = "2m"
factor = "2"
}
limit = "5"
}
sync_options = [
# Set to false because namespace is created by resource.kubernetes_namespace.kube_prometheus_stack_namespace
"CreateNamespace=false"
]
}
}
depends_on = [
resource.null_resource.dependencies,
resource.kubernetes_secret.thanos_object_storage_secret,
resource.kubernetes_namespace.kube_prometheus_stack_namespace
]
}
resource "null_resource" "this" {
depends_on = [
resource.argocd_application.this,
]
}