-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.tf
1286 lines (1130 loc) · 39.3 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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
provider "kubernetes" {
host = module.eks.cluster_endpoint
cluster_ca_certificate = base64decode(module.eks.cluster_certificate_authority_data)
exec {
api_version = "client.authentication.k8s.io/v1beta1"
command = "aws"
# This requires the awscli to be installed locally where Terraform is executed
args = ["eks", "get-token", "--cluster-name", module.eks.cluster_name]
}
}
provider "helm" {
kubernetes {
host = module.eks.cluster_endpoint
cluster_ca_certificate = base64decode(module.eks.cluster_certificate_authority_data)
exec {
api_version = "client.authentication.k8s.io/v1beta1"
command = "aws"
# This requires the awscli to be installed locally where Terraform is executed
args = ["eks", "get-token", "--cluster-name", module.eks.cluster_name]
}
}
}
data "aws_vpc" "default" {
default = true
}
data "aws_availability_zones" "this" {}
data "aws_subnets" "private" {
count = length(data.aws_availability_zones.this.names)
filter {
name = "availability-zone"
values = [data.aws_availability_zones.this.names[count.index]]
}
filter {
name = "vpc-id"
values = [local.vpc_id]
}
filter {
name = "state"
values = ["available"]
}
dynamic "filter" {
for_each = var.private_subnets_filters
content {
name = filter.value.name
values = filter.value.values
}
}
}
data "aws_subnets" "available" {
count = length(data.aws_availability_zones.this.names)
filter {
name = "availability-zone"
values = [data.aws_availability_zones.this.names[count.index]]
}
filter {
name = "vpc-id"
values = [local.vpc_id]
}
filter {
name = "state"
values = ["available"]
}
}
locals {
vpc_id = coalesce(var.vpc_id, data.aws_vpc.default.id)
private_subnets_by_az = [
for i, name in data.aws_availability_zones.this.names: {
zone = name
subnets = data.aws_subnets.private[i].ids
} if length(data.aws_subnets.private[i].ids) > 0
]
available_subnets_by_az = [
for i, name in data.aws_availability_zones.this.names: {
zone = name
subnets = data.aws_subnets.available[i].ids
} if length(data.aws_subnets.available[i].ids) > 0
]
subnets_by_az = coalescelist(
var.subnets_by_az,
local.private_subnets_by_az,
local.available_subnets_by_az
)
number_of_multi_az = min(var.number_of_multi_az, length(local.subnets_by_az))
# I don't think that we need more availability zones in node groups than in control plane
self_managed_node_group_number_of_multi_az = min(
var.self_managed_node_group_number_of_multi_az,
local.number_of_multi_az
)
eks_managed_node_group_number_of_multi_az = min(
var.eks_managed_node_group_number_of_multi_az,
local.number_of_multi_az
)
fargate_profile_number_of_multi_az = min(
var.fargate_profile_number_of_multi_az,
local.number_of_multi_az,
length(local.private_subnets_by_az) # fargate works only in private subnets
)
subnets = flatten([
for az in slice(local.subnets_by_az, 0, local.number_of_multi_az):
az.subnets
])
# place for defaults
self_managed_node_group_templates_for_multi_az = merge(
{},
var.self_managed_node_group_templates_for_multi_az
)
self_managed_node_groups_multi_az_list = flatten([
for key, value in local.self_managed_node_group_templates_for_multi_az: [
for az in slice(local.subnets_by_az, 0, local.self_managed_node_group_number_of_multi_az): merge(
value,
{
key = key
name = "${key}_${az.zone}"
subnet_ids = az.subnets
}
)
]
])
self_managed_node_groups_multi_az = {
for i in local.self_managed_node_groups_multi_az_list: i.name => i
}
self_managed_node_groups = merge(local.self_managed_node_groups_multi_az, var.self_managed_node_groups)
# place for defaults
eks_managed_node_group_templates_for_multi_az = merge(
{},
var.eks_managed_node_group_templates_for_multi_az
)
eks_managed_node_groups_multi_az_list = flatten([
for key, value in local.eks_managed_node_group_templates_for_multi_az: [
for az in slice(local.subnets_by_az, 0, local.eks_managed_node_group_number_of_multi_az): merge(
value,
{
key = key
name = "${key}_${az.zone}"
subnet_ids = az.subnets
}
)
]
])
eks_managed_node_groups_multi_az = {
for i in local.eks_managed_node_groups_multi_az_list: i.name => i
}
eks_managed_node_groups = merge(local.eks_managed_node_groups_multi_az, var.eks_managed_node_groups)
# https://docs.aws.amazon.com/eks/latest/userguide/fargate-profile.html
# https://aws.amazon.com/ru/blogs/containers/monitoring-amazon-eks-on-aws-fargate-using-prometheus-and-grafana/
# https://docs.aws.amazon.com/eks/latest/userguide/monitoring-fargate-usage.html
# Amazon EKS and Fargate spread Pods across each of the subnets that's defined
# in the Fargate profile. However, you might end up with an uneven spread.
# If you must have an even spread, use two Fargate profiles. Even spread
# is important in scenarios where you want to deploy two replicas and don't
# want any downtime. We recommend that each profile has only one subnet.
fargate_profile_templates_for_multi_az = merge(
# disable this as coredns and some other addons
# had untolerated taint {eks.amazonaws.com/compute-type: fargate}.
# and also EKS has quote for 10 fargate profiles by default.
# and also all fargate instances was started in one AZ instead of splitting by AZs
# {
# # default = {}
# kube-system = {}
# kube-node-lease = {}
# kube-public = {}
# cert-manager = {}
# external-dns = {}
# external-secrets = {}
# vpa = {}
# aws-node-termination-handler = {}
# },
{},
var.fargate_profile_templates_for_multi_az
)
fargate_profiles_multi_az_list = flatten([
for key, value in local.fargate_profile_templates_for_multi_az: [
for az in slice(local.subnets_by_az, 0, local.fargate_profile_number_of_multi_az): merge(
value,
{
key = key
name = "${key}_${az.zone}"
subnet_ids = az.subnets
selectors = try(
value.selectors,
[{namespace = key}]
)
tags = merge(try(value.tags, {}), var.tags)
}
)
]
])
fargate_profiles_multi_az = {
for i in local.fargate_profiles_multi_az_list: i.name => i
}
fargate_profiles = merge(local.fargate_profiles_multi_az, var.fargate_profiles)
universal_cluster_addon_config = {
most_recent = true
configuration_values = jsonencode(yamldecode(file("${path.module}/universal_values.yaml")))
}
eks_addons = merge(
{
coredns = local.universal_cluster_addon_config
kube-proxy = {
most_recent = true
}
vpc-cni = {
most_recent = true
service_account_role_arn = module.vpc_cni_irsa.iam_role_arn
}
aws-ebs-csi-driver = {
most_recent = true
service_account_role_arn = module.ebs_csi_driver_irsa.iam_role_arn
}
snapshot-controller = {
most_recent = true
}
},
var.eks_addons
)
universal_values_string = templatefile("${path.module}/universal_values.yaml", {})
universal_addon_config = {
values = [local.universal_values_string]
}
# https://github.com/kubernetes-sigs/aws-efs-csi-driver/blob/master/charts/aws-efs-csi-driver/values.yaml
aws_efs_csi_driver_config = merge(
local.universal_addon_config,
{
chart_version = null
reset_values = true
values = [
<<-EOT
controller:
${replace(local.universal_values_string, "\n", "\n ")}
EOT
]
},
var.aws_efs_csi_driver_config
)
# https://github.com/aws/aws-node-termination-handler/blob/main/config/helm/aws-node-termination-handler/values.yaml
aws_node_termination_handler_config = merge(
local.universal_addon_config,
{
chart_version = null
reset_values = true
},
var.aws_node_termination_handler_config
)
aws_node_termination_handler_asg_arns = concat(
[for asg in module.eks.self_managed_node_groups : asg.autoscaling_group_arn],
var.aws_node_termination_handler_asg_arns
)
# https://github.com/cert-manager/cert-manager/blob/master/deploy/charts/cert-manager/values.yaml
cert_manager_config = merge(
local.universal_addon_config,
{
chart_version = null
reset_values = true
values = [
<<-EOT
webhook:
${replace(local.universal_values_string, "\n", "\n ")}
cainjector:
${replace(local.universal_values_string, "\n", "\n ")}
startupapicheck:
${replace(local.universal_values_string, "\n", "\n ")}
EOT
]
},
var.cert_manager_config
)
# https://github.com/kubernetes/autoscaler/blob/master/charts/cluster-autoscaler/values.yaml
cluster_autoscaler_config = merge(
local.universal_addon_config,
{
chart_version = null
reset_values = true
},
var.cluster_autoscaler_config
)
# https://github.com/kubernetes-sigs/metrics-server/blob/master/charts/metrics-server/values.yaml
metrics_server_config = merge(
local.universal_addon_config,
{
chart_version = null
reset_values = true
},
var.metrics_server_config
)
# https://github.com/FairwindsOps/charts/blob/master/stable/vpa/values.yaml
vpa_config = merge(
local.universal_addon_config,
{
chart_version = null
reset_values = true
values = [
<<-EOT
recommender:
${replace(local.universal_values_string, "\n", "\n ")}
updater:
${replace(local.universal_values_string, "\n", "\n ")}
admissionController:
${replace(local.universal_values_string, "\n", "\n ")}
mutatingWebhookConfiguration:
${replace(local.universal_values_string, "\n", "\n ")}
EOT
]
},
var.vpa_config
)
# don't like using root password for monitoring agents but for speedup
openobserve_authorization = try(base64encode("${var.admin_email}:${module.openobserve.zo_root_user_password}"), "")
}
module "eks" {
source = "./modules/eks"
vpc_id = local.vpc_id
subnet_ids = local.subnets
cluster_name = var.cluster_name
cluster_version = var.cluster_version
cluster_addons = {}
self_managed_node_group_defaults = var.self_managed_node_group_defaults
eks_managed_node_group_defaults = var.eks_managed_node_group_defaults
fargate_profile_defaults = var.fargate_profile_defaults
group_defaults = var.group_defaults
self_managed_node_groups = local.self_managed_node_groups
eks_managed_node_groups = local.eks_managed_node_groups
fargate_profiles = local.fargate_profiles
admin_iam_roles = var.admin_iam_roles
admin_iam_users = var.admin_iam_users
eks_iam_roles = var.eks_iam_roles
tags = var.tags
}
# IRSA
module "ebs_csi_driver_irsa" {
source = "terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks"
version = "~> 5.20"
role_name_prefix = "${var.cluster_name}-ebs-csi-driver-"
attach_ebs_csi_policy = true
oidc_providers = {
main = {
provider_arn = module.eks.oidc_provider_arn
namespace_service_accounts = ["kube-system:ebs-csi-controller-sa"]
}
}
tags = var.tags
}
module "vpc_cni_irsa" {
source = "terraform-aws-modules/iam/aws//modules/iam-role-for-service-accounts-eks"
version = "~> 5.20"
role_name_prefix = "${var.cluster_name}-vpc-cni-"
attach_vpc_cni_policy = true
vpc_cni_enable_ipv4 = true
oidc_providers = {
main = {
provider_arn = module.eks.oidc_provider_arn
namespace_service_accounts = ["kube-system:aws-node"]
}
}
tags = var.tags
}
module "addons" {
source = "aws-ia/eks-blueprints-addons/aws"
version = "~> 1.1"
cluster_name = module.eks.cluster_name
cluster_endpoint = module.eks.cluster_endpoint
cluster_version = module.eks.cluster_version
oidc_provider_arn = module.eks.oidc_provider_arn
eks_addons = local.eks_addons
eks_addons_timeouts = var.eks_addons_timeouts
# https://github.com/aws-ia/terraform-aws-eks-blueprints-addons/blob/main/docs/addons/aws-efs-csi-driver.md
# https://github.com/kubernetes-sigs/aws-efs-csi-driver/blob/master/charts/aws-efs-csi-driver/values.yaml
enable_aws_efs_csi_driver = var.enable_aws_efs_csi_driver
aws_efs_csi_driver = local.aws_efs_csi_driver_config
# https://github.com/aws-ia/terraform-aws-eks-blueprints-addons/blob/main/docs/addons/aws-node-termination-handler.md
# https://github.com/aws/aws-node-termination-handler/blob/main/config/helm/aws-node-termination-handler/values.yaml
enable_aws_node_termination_handler = var.enable_aws_node_termination_handler && length(local.aws_node_termination_handler_asg_arns) > 0
aws_node_termination_handler = local.aws_node_termination_handler_config
aws_node_termination_handler_sqs = var.aws_node_termination_handler_sqs
aws_node_termination_handler_asg_arns = local.aws_node_termination_handler_asg_arns
# https://github.com/aws-ia/terraform-aws-eks-blueprints-addons/blob/main/docs/addons/cert-manager.md
# https://github.com/cert-manager/cert-manager/blob/master/deploy/charts/cert-manager/values.yaml
enable_cert_manager = var.enable_cert_manager
cert_manager = local.cert_manager_config
cert_manager_route53_hosted_zone_arns = var.cert_manager_route53_hosted_zone_arns
# https://github.com/aws-ia/terraform-aws-eks-blueprints-addons/blob/main/docs/addons/cluster-autoscaler.md
# https://github.com/kubernetes/autoscaler/blob/master/charts/cluster-autoscaler/values.yaml
enable_cluster_autoscaler = var.enable_cluster_autoscaler
cluster_autoscaler = local.cluster_autoscaler_config
# https://github.com/aws-ia/terraform-aws-eks-blueprints-addons/blob/main/docs/addons/metrics-server.md
# https://github.com/kubernetes-sigs/metrics-server/blob/master/charts/metrics-server/values.yaml
enable_metrics_server = var.enable_metrics_server
metrics_server = local.metrics_server_config
# https://github.com/aws-ia/terraform-aws-eks-blueprints-addons/blob/main/docs/addons/vertical-pod-autoscaler.md
# https://github.com/FairwindsOps/charts/blob/master/stable/vpa/values.yaml
enable_vpa = var.enable_vpa
vpa = local.vpa_config
tags = var.tags
}
# patch addons and modules as some eks addons don't have tolerations
resource "null_resource" "apply_kubectl_patch" {
count = var.apply_kubectl_patch? 1 : 0
depends_on = [
#module.eks,
module.addons
]
provisioner "local-exec" {
command = <<-EOT
export KUBECONFIG="${module.eks.kubeconfig}"
kubectl get deployments -o name -n kube-system | xargs -I {} kubectl patch {} -n kube-system -p '{"spec": {"template":{"spec":${jsonencode(yamldecode(file("${path.module}/universal_values.yaml")))}}}}'
EOT
}
}
# https://cert-manager.io/docs/configuration/acme/
module "cert_manager_acme_manifests" {
source = "./modules/kubernetes-manifests"
count = var.enable_cert_manager ? 1 : 0
depends_on = [
#module.eks,
module.addons
]
create = true
name = "cert-manager-acme-manifests"
namespace = try(var.cert_manager_config.namespace, "cert-manager")
tags = var.tags
values = [
<<-EOT
resources:
- apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
name: letsencrypt-staging
spec:
acme:
email: "${var.admin_email}"
server: "https://acme-staging-v02.api.letsencrypt.org/directory"
privateKeySecretRef:
name: cert-manager-issuer-letsencrypt-staging-account-key
solvers:
- http01:
ingress:
ingressClassName: "${var.ingress_class_name}"
- apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
name: letsencrypt-prod
spec:
acme:
email: "${var.admin_email}"
server: "https://acme-v01.api.letsencrypt.org/directory"
privateKeySecretRef:
name: cert-manager-issuer-letsencrypt-prod-account-key
solvers:
- http01:
ingress:
ingressClassName: "${var.ingress_class_name}"
EOT
]
}
# OPERATOR
module "victoriametrics_operator" {
source = "./modules/victoriametrics-operator"
count = var.enable_victoriametrics_operator ? 1 : 0
depends_on = [
#module.eks,
#module.addons
]
create = var.enable_victoriametrics_operator
chart_version = var.victoriametrics_operator_chart_version
namespace = var.victoriametrics_operator_namespace
set = var.victoriametrics_operator_set
tags = var.tags
values = concat(
[local.universal_values_string],
var.victoriametrics_operator_values
)
}
module "opentelemetry_operator" {
source = "./modules/opentelemetry-operator"
count = var.enable_opentelemetry_operator ? 1 : 0
depends_on = [
#module.eks,
#module.addons
module.victoriametrics_operator
]
create = var.enable_opentelemetry_operator
chart_version = var.opentelemetry_operator_chart_version
namespace = var.opentelemetry_operator_namespace
set = var.opentelemetry_operator_set
tags = var.tags
values = concat(
[local.universal_values_string],
[
<<-EOT
%{ if var.enable_victoriametrics_operator == true }
manager:
serviceMonitor:
enabled: true
%{ endif }
EOT
],
var.opentelemetry_operator_values
)
}
module "grafana_operator" {
source = "./modules/grafana-operator"
count = var.enable_grafana_operator ? 1 : 0
depends_on = [
#module.eks,
#module.addons
]
create = var.enable_grafana_operator
chart_version = var.grafana_operator_chart_version
namespace = var.grafana_operator_namespace
set = var.grafana_operator_set
tags = var.tags
values = concat(
[local.universal_values_string],
var.grafana_operator_values
)
}
module "clickhouse_operator" {
source = "./modules/clickhouse-operator"
count = var.enable_clickhouse_operator ? 1 : 0
depends_on = [
#module.eks,
#module.addons
]
create = var.enable_clickhouse_operator
chart_version = var.clickhouse_operator_chart_version
namespace = var.clickhouse_operator_namespace
set = var.clickhouse_operator_set
tags = var.tags
values = concat(
[local.universal_values_string],
var.clickhouse_operator_values
)
}
# INGRESS
module "ingress_apisix" {
source = "./modules/apisix"
count = var.enable_ingress_apisix ? 1 : 0
depends_on = [
#module.eks,
#module.addons
module.victoriametrics_operator
]
create = var.enable_ingress_apisix
chart_version = var.ingress_apisix_chart_version
namespace = var.ingress_apisix_namespace
set = var.ingress_apisix_set
tags = var.tags
values = concat(
[local.universal_values_string],
[
<<-EOT
%{ if var.enable_victoriametrics_operator == true }
serviceMonitor:
enabled: true
namespace: "${var.ingress_apisix_namespace}"
%{ endif }
EOT
],
var.ingress_apisix_values
)
}
module "ingress_nginx" {
source = "./modules/nginx"
count = var.enable_ingress_nginx ? 1 : 0
depends_on = [
#module.eks,
#module.addons
module.victoriametrics_operator
]
create = var.enable_ingress_nginx
chart_version = var.ingress_nginx_chart_version
namespace = var.ingress_nginx_namespace
set = var.ingress_nginx_set
tags = var.tags
values = concat(
[
<<-EOT
controller:
${replace(local.universal_values_string, "\n", "\n ")}
defaultBackend:
${replace(local.universal_values_string, "\n", "\n ")}
EOT
],
[
<<-EOT
%{ if var.enable_victoriametrics_operator == true }
controller:
metrics:
serviceMonitor:
enabled: true
namespace: "${var.ingress_nginx_namespace}"
scrapeInterval: 30s # default
%{ endif }
EOT
],
var.ingress_nginx_values
)
}
# MONITORING
module "victoriametrics" {
source = "./modules/victoriametrics"
count = var.enable_victoriametrics ? 1 : 0
depends_on = [
#module.eks,
#module.addons,
module.victoriametrics_operator,
module.grafana_operator,
# module.uptrace,
# module.qryn
]
create = var.enable_victoriametrics
chart_version = var.victoriametrics_chart_version
namespace = var.victoriametrics_namespace
set = var.victoriametrics_set
tags = var.tags
grafana_admin_user = var.admin_email
grafana_operator_integration = var.enable_grafana_operator
grafana_operator_namespace = var.grafana_operator_namespace
values = concat(
[local.universal_values_string],
[
<<-EOT
%{ if var.enable_victoriametrics_operator == true }
victoria-metrics-operator:
enabled: false
crds:
enabled: false
%{ endif }
EOT
,
<<-EOT
%{ if var.enable_grafana_operator == true || var.enable_grafana == true }
grafanaOperatorDashboardsFormat:
enabled: true
instanceSelector:
matchLabels:
dashboards: "grafana"
allowCrossNamespaceImport: true
grafana:
enabled: false
%{ else }
%{ if var.victoriametrics_grafana_ingress_enabled == true }
grafana:
enabled: true
ingress:
enabled: true
ingressClassName: ${var.ingress_class_name}
# https://apisix.apache.org/docs/ingress-controller/concepts/annotations/
# https://cert-manager.io/docs/usage/ingress/
annotations:
kubernetes.io/ingress.class: ${var.ingress_class_name}
k8s.apisix.apache.org/enable-cors: "true"
%{~ if coalesce(var.victoriametrics_cert_manager_issuer, var.cert_manager_issuer, false) ~}
k8s.apisix.apache.org/http-to-https: "true"
cert-manager.io/cluster-issuer: ${coalesce(var.victoriametrics_cert_manager_issuer, var.cert_manager_issuer)}
%{ endif }
hosts:
- grafana.${var.ingress_domain}
%{~ if coalesce(var.victoriametrics_cert_manager_issuer, var.cert_manager_issuer, false) ~}
tls:
- secretName: grafana-${var.victoriametrics_namespace}-tls
hosts:
- grafana.${var.ingress_domain}
%{ else }
tls: []
%{ endif }
%{ endif }
%{ endif }
EOT
,
<<-EOT
%{ if var.enable_uptrace == true || var.enable_qryn == true }
vmagent:
# https://docs.victoriametrics.com/operator/api/#vmagentremotewritespec
# https://uptrace.dev/get/ingest/prometheus.html#prometheus-remote-write
additionalRemoteWrites:
%{ if var.enable_uptrace == true }
- url: "http://${module.uptrace[0].chart.uptrace}.${module.uptrace[0].namespace.uptrace}.svc:14318/api/v1/prometheus/write"
headers:
- "uptrace-dsn: http://${module.uptrace[0].project_tokens[1]}@${module.uptrace[0].chart.uptrace}.${module.uptrace[0].namespace.uptrace}.svc:14318/2?grpc=14317"
%{ endif }
%{ if var.enable_qryn == true }
- url: "http://${var.admin_email}:${module.qryn[0].root_password}@${module.qryn[0].chart.qryn}.${module.qryn[0].namespace.qryn}.svc:3100/api/v1/write"
%{ endif }
%{ endif }
EOT
],
var.victoriametrics_values
)
auth_chart_version = var.victoriametrics_auth_chart_version
auth_set = var.victoriametrics_auth_set
auth_values = concat(
[local.universal_values_string],
[
<<-EOT
%{ if var.victoriametrics_auth_ingress_enabled == true }
ingress:
enabled: true
ingressClassName: ${var.ingress_class_name}
# https://apisix.apache.org/docs/ingress-controller/concepts/annotations/
# https://cert-manager.io/docs/usage/ingress/
annotations:
kubernetes.io/ingress.class: ${var.ingress_class_name}
k8s.apisix.apache.org/enable-cors: "true"
%{~ if coalesce(var.victoriametrics_cert_manager_issuer, var.cert_manager_issuer, false) ~}
k8s.apisix.apache.org/http-to-https: "true"
cert-manager.io/cluster-issuer: ${coalesce(var.victoriametrics_cert_manager_issuer, var.cert_manager_issuer)}
%{ endif }
hosts:
- name: vmauth.${var.ingress_domain}
path: /
port: http
- name: victoriametrics.${var.ingress_domain}
path: /
port: http
- name: vmalertmanager.${var.ingress_domain}
path: /
port: http
- name: vmagent.${var.ingress_domain}
path: /
port: http
- name: vmalert.${var.ingress_domain}
path: /
port: http
%{~ if coalesce(var.victoriametrics_cert_manager_issuer, var.cert_manager_issuer, false) ~}
tls:
- secretName: vmauth-${var.victoriametrics_namespace}-tls
hosts:
- vmauth.${var.ingress_domain}
- victoriametrics.${var.ingress_domain}
- vmalertmanager.${var.ingress_domain}
- vmagent.${var.ingress_domain}
- vmalert.${var.ingress_domain}
%{ else }
tls: []
%{ endif }
%{ endif }
EOT
],
var.victoriametrics_auth_values
)
}
module "grafana" {
source = "./modules/grafana"
count = var.enable_grafana ? 1 : 0
depends_on = [
#module.eks,
#module.addons,
module.grafana_operator,
module.victoriametrics_operator
]
create = var.enable_grafana
chart_version = var.grafana_chart_version
namespace = var.grafana_namespace
set = var.grafana_set
tags = var.tags
admin_user = var.admin_email
grafana_operator_integration = var.enable_grafana_operator
grafana_operator_namespace = var.grafana_operator_namespace
values = concat(
[local.universal_values_string],
[
<<-EOT
%{ if var.enable_victoriametrics_operator == true }
serviceMonitor:
enabled: true
%{ endif }
%{ if var.grafana_ingress_enabled == true }
ingress:
enabled: true
ingressClassName: ${var.ingress_class_name}
# https://apisix.apache.org/docs/ingress-controller/concepts/annotations/
# https://cert-manager.io/docs/usage/ingress/
annotations:
kubernetes.io/ingress.class: ${var.ingress_class_name}
k8s.apisix.apache.org/enable-cors: "true"
%{~ if coalesce(var.grafana_cert_manager_issuer, var.cert_manager_issuer, false) ~}
k8s.apisix.apache.org/http-to-https: "true"
cert-manager.io/cluster-issuer: ${coalesce(var.grafana_cert_manager_issuer, var.cert_manager_issuer)}
%{ endif }
hosts:
- grafana.${var.ingress_domain}
%{~ if coalesce(var.grafana_cert_manager_issuer, var.cert_manager_issuer, false) ~}
tls:
- secretName: grafana-${var.grafana_namespace}-tls
hosts:
- grafana.${var.ingress_domain}
%{ else }
tls: []
%{ endif }
%{ endif }
EOT
],
var.grafana_values
)
}
# signoz.io vs openobserve.ai vs qryn.metrico.in vs uptrace.dev vs skywalking.apache.org vs siglens.com
# https://uptrace.dev/get/open-source-apm.html#why-not
module "uptrace" {
source = "./modules/uptrace"
count = var.enable_uptrace ? 1 : 0
depends_on = [
#module.eks,
#module.addons
]
create = var.enable_uptrace
chart_version = var.uptrace_chart_version
namespace = var.uptrace_namespace
set = var.uptrace_set
tags = var.tags
root_email = var.admin_email
oidc_provider_arn = module.eks.oidc_provider_arn
grafana_operator_integration = var.enable_grafana_operator
grafana_operator_namespace = var.grafana_operator_namespace
values = concat(
[local.universal_values_string],
[
<<-EOT
%{ if var.uptrace_ingress_enabled == true }
uptrace:
config:
site:
%{~ if coalesce(var.uptrace_cert_manager_issuer, var.cert_manager_issuer, false) ~}
addr: 'https://uptrace.${var.ingress_domain}/'
%{ else }
addr: 'http://uptrace.${var.ingress_domain}/'
%{ endif }
ingress:
enabled: true
className: ${var.ingress_class_name}
# https://apisix.apache.org/docs/ingress-controller/concepts/annotations/
# https://cert-manager.io/docs/usage/ingress/
annotations:
kubernetes.io/ingress.class: ${var.ingress_class_name}
k8s.apisix.apache.org/enable-cors: "true"
%{~ if coalesce(var.uptrace_cert_manager_issuer, var.cert_manager_issuer, false) ~}
k8s.apisix.apache.org/http-to-https: "true"
cert-manager.io/cluster-issuer: ${coalesce(var.uptrace_cert_manager_issuer, var.cert_manager_issuer)}
%{ endif }
hosts:
- host: uptrace.${var.ingress_domain}
paths:
- path: /
pathType: Prefix
%{~ if coalesce(var.uptrace_cert_manager_issuer, var.cert_manager_issuer, false) ~}
tls:
- secretName: uptrace-${var.uptrace_namespace}-tls
hosts:
- uptrace.${var.ingress_domain}
%{ else }
tls: []
%{ endif }
%{ endif }
EOT
],
var.uptrace_values
)
clickhouse_chart_version = var.uptrace_clickhouse_chart_version
clickhouse_set = var.uptrace_clickhouse_set
clickhouse_values = concat(
[local.universal_values_string],
var.uptrace_clickhouse_values
)
postgresql_chart_version = var.uptrace_postgresql_chart_version
postgresql_set = var.uptrace_postgresql_set
postgresql_values = concat(
[local.universal_values_string],
var.uptrace_postgresql_values
)
}
module "qryn" {
source = "./modules/qryn"
count = var.enable_qryn ? 1 : 0