forked from provectus/sak-efk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
268 lines (244 loc) · 7.09 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
data "aws_eks_cluster" "this" {
name = var.cluster_name
}
data "aws_region" "current" {}
resource "kubernetes_namespace" "this" {
count = var.namespace == "" ? 1 - local.argocd_enabled : 0
metadata {
name = var.namespace_name
}
}
resource "local_file" "namespace" {
count = local.argocd_enabled
content = yamlencode({
"apiVersion" = "v1"
"kind" = "Namespace"
"metadata" = {
"name" = local.namespace
}
})
filename = "${path.root}/${var.argocd.path}/ns-${local.namespace}.yaml"
}
locals {
argocd_enabled = length(var.argocd) > 0 ? 1 : 0
namespace = coalescelist(var.namespace == "" && local.argocd_enabled > 0 ? [{ "metadata" = [{ "name" = var.namespace_name }] }] : kubernetes_namespace.this, [{ "metadata" = [{ "name" = var.namespace }] }])[0].metadata[0].name
}
#Elasticsearch
resource "helm_release" "elastic" {
count = 1 - local.argocd_enabled
name = local.elastic_name
repository = local.elastic_repository
chart = local.elastic_chart
version = var.elastic_chart_version
namespace = local.namespace
recreate_pods = true
timeout = 1200
dynamic "set" {
for_each = merge(local.elastic_conf)
content {
name = set.key
value = set.value
}
}
}
resource "local_file" "elastic" {
count = local.argocd_enabled
content = yamlencode(local.elastic_application)
filename = "${path.root}/${var.argocd.path}/${local.elastic_name}.yaml"
}
#Kibana
resource "helm_release" "kibana" {
count = 1 - local.argocd_enabled
name = local.kibana_name
repository = local.kibana_repository
chart = local.kibana_chart
version = var.kibana_chart_version
namespace = local.namespace
recreate_pods = true
timeout = 1200
dynamic "set" {
for_each = merge(local.kibana_conf)
content {
name = set.key
value = set.value
}
}
}
resource "local_file" "kibana" {
count = local.argocd_enabled
content = yamlencode(local.kibana_application)
filename = "${path.root}/${var.argocd.path}/${local.kibana_name}.yaml"
}
#Filebeat
# resource "helm_release" "filebeat" {
# count = 1 - local.argocd_enabled
# name = local.filebeat_name
# repository = local.filebeat_repository
# chart = local.filebeat_chart
# version = var.filebeat_chart_version
# namespace = local.namespace
# recreate_pods = true
# timeout = 1200
# dynamic "set" {
# for_each = local.filebeat_conf
# content {
# name = set.key
# value = set.value
# }
# }
# }
resource "local_file" "filebeat" {
count = local.argocd_enabled
content = yamlencode(local.filebeat_application)
filename = "${path.root}/${var.argocd.path}/${local.filebeat_name}.yaml"
}
locals {
#elasticsearch
elastic_name = "elasticsearch"
elastic_repository = "https://helm.elastic.co/"
elastic_chart = "elasticsearch"
elastic_conf = merge(local.elastic_conf_defaults, var.elastic_conf)
#kibana
kibana_name = "kibana"
kibana_repository = "https://helm.elastic.co/"
kibana_chart = "kibana"
kibana_conf = merge(local.kibana_conf_defaults, var.kibana_conf)
#filebeat
filebeat_name = "filebeat"
filebeat_repository = "https://helm.elastic.co/"
filebeat_chart = "filebeat"
filebeat_conf = local.filebeat_conf_merge
elastic_conf_defaults = {
"replicas" = var.elasticReplicas
"minimumMasterNodes" = var.elasticMinMasters
"volumeClaimTemplate.resources.requests.storage" = var.elasticDataSize
}
kibana_conf_defaults = {
"elasticsearchHosts" = "http://elasticsearch-master:9200"
"ingress.enabled" = "true"
"ingress.hosts[0]" = "kibana.${var.domains[0]}"
"ingress.tls[0].secretName" = "kibana-tls"
"ingress.tls[0].hosts[0]" = "kibana.${var.domains[0]}"
}
filebeat_conf_merge = yamlencode(
{
"filebeatConfig" = {
"filebeat\\.yml" = merge(local.filebeat_conf_defaults, var.filebeat_conf)
}
})
filebeat_conf_defaults = {
"output.elasticsearch" = {
"host" = "$\\{NODE_NAME\\}"
"hosts" = "$\\{ELASTICSEARCH_HOSTS:elasticsearch-master:9200\\}"
}
}
elastic_application = {
"apiVersion" = "argoproj.io/v1alpha1"
"kind" = "Application"
"metadata" = {
"name" = local.elastic_name
"namespace" = var.argocd.namespace
}
"spec" = {
"destination" = {
"namespace" = local.namespace
"server" = "https://kubernetes.default.svc"
}
"project" = "default"
"source" = {
"repoURL" = local.elastic_repository
"targetRevision" = var.elastic_chart_version
"chart" = local.elastic_chart
"helm" = {
"parameters" = values({
for key, value in local.elastic_conf :
key => {
"name" = key
"value" = tostring(value)
}
})
}
}
"syncPolicy" = {
"automated" = {
"prune" = true
"selfHeal" = true
}
}
}
}
kibana_application = {
"apiVersion" = "argoproj.io/v1alpha1"
"kind" = "Application"
"metadata" = {
"name" = local.kibana_name
"namespace" = var.argocd.namespace
}
"spec" = {
"destination" = {
"namespace" = local.namespace
"server" = "https://kubernetes.default.svc"
}
"project" = "default"
"source" = {
"repoURL" = local.kibana_repository
"targetRevision" = var.kibana_chart_version
"chart" = local.kibana_chart
"helm" = {
"parameters" = concat(
values({
for key, value in local.kibana_conf :
key => {
"name" = key
"value" = tostring(value)
}
}),
values({
for key, value in var.ingress_annotations :
key => {
"name" = "ingress.annotations.${replace(key, ".", "\\.")}"
"value" = tostring(value)
"forceString" = true
}
})
)
}
}
"syncPolicy" = {
"automated" = {
"prune" = true
"selfHeal" = true
}
}
}
}
filebeat_application = {
"apiVersion" = "argoproj.io/v1alpha1"
"kind" = "Application"
"metadata" = {
"name" = local.filebeat_name
"namespace" = var.argocd.namespace
}
"spec" = {
"destination" = {
"namespace" = local.namespace
"server" = "https://kubernetes.default.svc"
}
"project" = "default"
"source" = {
"repoURL" = local.filebeat_repository
"targetRevision" = var.filebeat_chart_version
"chart" = local.filebeat_chart
"helm" = {
"values" = local.filebeat_conf
}
}
"syncPolicy" = {
"automated" = {
"prune" = true
"selfHeal" = true
}
}
}
}
}