generated from aws-ia/terraform-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 117
/
main.tf
3802 lines (3305 loc) · 168 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
data "aws_partition" "current" {}
data "aws_caller_identity" "current" {}
data "aws_region" "current" {}
# This resource is used to provide a means of mapping an implicit dependency
# between the cluster and the addons.
resource "time_sleep" "this" {
create_duration = var.create_delay_duration
triggers = {
cluster_endpoint = var.cluster_endpoint
cluster_name = var.cluster_name
custom = join(",", var.create_delay_dependencies)
oidc_provider_arn = var.oidc_provider_arn
}
}
locals {
account_id = data.aws_caller_identity.current.account_id
partition = data.aws_partition.current.partition
region = data.aws_region.current.name
# Threads the sleep resource into the module to make the dependency
cluster_endpoint = time_sleep.this.triggers["cluster_endpoint"]
cluster_name = time_sleep.this.triggers["cluster_name"]
oidc_provider_arn = time_sleep.this.triggers["oidc_provider_arn"]
iam_role_policy_prefix = "arn:${local.partition}:iam::aws:policy"
# Used by Karpenter & AWS Node Termination Handler
ec2_events = {
health_event = {
name = "HealthEvent"
description = "AWS health event"
event_pattern = {
source = ["aws.health"]
detail-type = ["AWS Health Event"]
}
}
spot_interupt = {
name = "SpotInterrupt"
description = "EC2 spot instance interruption warning"
event_pattern = {
source = ["aws.ec2"]
detail-type = ["EC2 Spot Instance Interruption Warning"]
}
}
instance_rebalance = {
name = "InstanceRebalance"
description = "EC2 instance rebalance recommendation"
event_pattern = {
source = ["aws.ec2"]
detail-type = ["EC2 Instance Rebalance Recommendation"]
}
}
instance_state_change = {
name = "InstanceStateChange"
description = "EC2 instance state-change notification"
event_pattern = {
source = ["aws.ec2"]
detail-type = ["EC2 Instance State-change Notification"]
}
}
}
}
################################################################################
# Argo Rollouts
################################################################################
module "argo_rollouts" {
source = "aws-ia/eks-blueprints-addon/aws"
version = "1.1.1"
create = var.enable_argo_rollouts
# Disable helm release
create_release = var.create_kubernetes_resources
# https://github.com/argoproj/argo-helm/tree/main/charts/argo-rollouts
name = try(var.argo_rollouts.name, "argo-rollouts")
description = try(var.argo_rollouts.description, "A Helm chart for Argo Rollouts")
namespace = try(var.argo_rollouts.namespace, "argo-rollouts")
create_namespace = try(var.argo_rollouts.create_namespace, true)
chart = try(var.argo_rollouts.chart, "argo-rollouts")
chart_version = try(var.argo_rollouts.chart_version, "2.34.3")
repository = try(var.argo_rollouts.repository, "https://argoproj.github.io/argo-helm")
values = try(var.argo_rollouts.values, [])
timeout = try(var.argo_rollouts.timeout, null)
repository_key_file = try(var.argo_rollouts.repository_key_file, null)
repository_cert_file = try(var.argo_rollouts.repository_cert_file, null)
repository_ca_file = try(var.argo_rollouts.repository_ca_file, null)
repository_username = try(var.argo_rollouts.repository_username, null)
repository_password = try(var.argo_rollouts.repository_password, null)
devel = try(var.argo_rollouts.devel, null)
verify = try(var.argo_rollouts.verify, null)
keyring = try(var.argo_rollouts.keyring, null)
disable_webhooks = try(var.argo_rollouts.disable_webhooks, null)
reuse_values = try(var.argo_rollouts.reuse_values, null)
reset_values = try(var.argo_rollouts.reset_values, null)
force_update = try(var.argo_rollouts.force_update, null)
recreate_pods = try(var.argo_rollouts.recreate_pods, null)
cleanup_on_fail = try(var.argo_rollouts.cleanup_on_fail, null)
max_history = try(var.argo_rollouts.max_history, null)
atomic = try(var.argo_rollouts.atomic, null)
skip_crds = try(var.argo_rollouts.skip_crds, null)
render_subchart_notes = try(var.argo_rollouts.render_subchart_notes, null)
disable_openapi_validation = try(var.argo_rollouts.disable_openapi_validation, null)
wait = try(var.argo_rollouts.wait, false)
wait_for_jobs = try(var.argo_rollouts.wait_for_jobs, null)
dependency_update = try(var.argo_rollouts.dependency_update, null)
replace = try(var.argo_rollouts.replace, null)
lint = try(var.argo_rollouts.lint, null)
postrender = try(var.argo_rollouts.postrender, [])
set = try(var.argo_rollouts.set, [])
set_sensitive = try(var.argo_rollouts.set_sensitive, [])
tags = var.tags
}
################################################################################
# Argo Workflows
################################################################################
module "argo_workflows" {
source = "aws-ia/eks-blueprints-addon/aws"
version = "1.1.1"
create = var.enable_argo_workflows
# Disable helm release
create_release = var.create_kubernetes_resources
# https://github.com/argoproj/argo-helm/tree/main/charts/argo-workflows
name = try(var.argo_workflows.name, "argo-workflows")
description = try(var.argo_workflows.description, "A Helm chart for Argo Workflows")
namespace = try(var.argo_workflows.namespace, "argo-workflows")
create_namespace = try(var.argo_workflows.create_namespace, true)
chart = try(var.argo_workflows.chart, "argo-workflows")
chart_version = try(var.argo_workflows.chart_version, "0.40.14")
repository = try(var.argo_workflows.repository, "https://argoproj.github.io/argo-helm")
values = try(var.argo_workflows.values, [])
timeout = try(var.argo_workflows.timeout, null)
repository_key_file = try(var.argo_workflows.repository_key_file, null)
repository_cert_file = try(var.argo_workflows.repository_cert_file, null)
repository_ca_file = try(var.argo_workflows.repository_ca_file, null)
repository_username = try(var.argo_workflows.repository_username, null)
repository_password = try(var.argo_workflows.repository_password, null)
devel = try(var.argo_workflows.devel, null)
verify = try(var.argo_workflows.verify, null)
keyring = try(var.argo_workflows.keyring, null)
disable_webhooks = try(var.argo_workflows.disable_webhooks, null)
reuse_values = try(var.argo_workflows.reuse_values, null)
reset_values = try(var.argo_workflows.reset_values, null)
force_update = try(var.argo_workflows.force_update, null)
recreate_pods = try(var.argo_workflows.recreate_pods, null)
cleanup_on_fail = try(var.argo_workflows.cleanup_on_fail, null)
max_history = try(var.argo_workflows.max_history, null)
atomic = try(var.argo_workflows.atomic, null)
skip_crds = try(var.argo_workflows.skip_crds, null)
render_subchart_notes = try(var.argo_workflows.render_subchart_notes, null)
disable_openapi_validation = try(var.argo_workflows.disable_openapi_validation, null)
wait = try(var.argo_workflows.wait, false)
wait_for_jobs = try(var.argo_workflows.wait_for_jobs, null)
dependency_update = try(var.argo_workflows.dependency_update, null)
replace = try(var.argo_workflows.replace, null)
lint = try(var.argo_workflows.lint, null)
postrender = try(var.argo_workflows.postrender, [])
set = try(var.argo_workflows.set, [])
set_sensitive = try(var.argo_workflows.set_sensitive, [])
tags = var.tags
}
################################################################################
# ArgoCD
################################################################################
module "argocd" {
source = "aws-ia/eks-blueprints-addon/aws"
version = "1.1.1"
create = var.enable_argocd
# Disable helm release
create_release = var.create_kubernetes_resources
# https://github.com/argoproj/argo-helm/blob/main/charts/argo-cd/Chart.yaml
name = try(var.argocd.name, "argo-cd")
description = try(var.argocd.description, "A Helm chart to install the ArgoCD")
namespace = try(var.argocd.namespace, "argocd")
create_namespace = try(var.argocd.create_namespace, true)
chart = try(var.argocd.chart, "argo-cd")
chart_version = try(var.argocd.chart_version, "5.55.0") # TODO - v6.x
repository = try(var.argocd.repository, "https://argoproj.github.io/argo-helm")
values = try(var.argocd.values, [])
timeout = try(var.argocd.timeout, null)
repository_key_file = try(var.argocd.repository_key_file, null)
repository_cert_file = try(var.argocd.repository_cert_file, null)
repository_ca_file = try(var.argocd.repository_ca_file, null)
repository_username = try(var.argocd.repository_username, null)
repository_password = try(var.argocd.repository_password, null)
devel = try(var.argocd.devel, null)
verify = try(var.argocd.verify, null)
keyring = try(var.argocd.keyring, null)
disable_webhooks = try(var.argocd.disable_webhooks, null)
reuse_values = try(var.argocd.reuse_values, null)
reset_values = try(var.argocd.reset_values, null)
force_update = try(var.argocd.force_update, null)
recreate_pods = try(var.argocd.recreate_pods, null)
cleanup_on_fail = try(var.argocd.cleanup_on_fail, null)
max_history = try(var.argocd.max_history, null)
atomic = try(var.argocd.atomic, null)
skip_crds = try(var.argocd.skip_crds, null)
render_subchart_notes = try(var.argocd.render_subchart_notes, null)
disable_openapi_validation = try(var.argocd.disable_openapi_validation, null)
wait = try(var.argocd.wait, false)
wait_for_jobs = try(var.argocd.wait_for_jobs, null)
dependency_update = try(var.argocd.dependency_update, null)
replace = try(var.argocd.replace, null)
lint = try(var.argocd.lint, null)
postrender = try(var.argocd.postrender, [])
set = try(var.argocd.set, [])
set_sensitive = try(var.argocd.set_sensitive, [])
tags = var.tags
}
################################################################################
# Argo Events
################################################################################
module "argo_events" {
source = "aws-ia/eks-blueprints-addon/aws"
version = "1.1.1"
create = var.enable_argo_events
# Disable helm release
create_release = var.create_kubernetes_resources
# https://github.com/argoproj/argo-helm/tree/main/charts/argo-events
name = try(var.argo_events.name, "argo-events")
description = try(var.argo_events.description, "A Helm chart to install the Argo Events")
namespace = try(var.argo_events.namespace, "argo-events")
create_namespace = try(var.argo_events.create_namespace, true)
chart = try(var.argo_events.chart, "argo-events")
chart_version = try(var.argo_events.chart_version, "2.4.3")
repository = try(var.argo_events.repository, "https://argoproj.github.io/argo-helm")
values = try(var.argo_events.values, [])
timeout = try(var.argo_events.timeout, null)
repository_key_file = try(var.argo_events.repository_key_file, null)
repository_cert_file = try(var.argo_events.repository_cert_file, null)
repository_ca_file = try(var.argo_events.repository_ca_file, null)
repository_username = try(var.argo_events.repository_username, null)
repository_password = try(var.argo_events.repository_password, null)
devel = try(var.argo_events.devel, null)
verify = try(var.argo_events.verify, null)
keyring = try(var.argo_events.keyring, null)
disable_webhooks = try(var.argo_events.disable_webhooks, null)
reuse_values = try(var.argo_events.reuse_values, null)
reset_values = try(var.argo_events.reset_values, null)
force_update = try(var.argo_events.force_update, null)
recreate_pods = try(var.argo_events.recreate_pods, null)
cleanup_on_fail = try(var.argo_events.cleanup_on_fail, null)
max_history = try(var.argo_events.max_history, null)
atomic = try(var.argo_events.atomic, null)
skip_crds = try(var.argo_events.skip_crds, null)
render_subchart_notes = try(var.argo_events.render_subchart_notes, null)
disable_openapi_validation = try(var.argo_events.disable_openapi_validation, null)
wait = try(var.argo_events.wait, false)
wait_for_jobs = try(var.argo_events.wait_for_jobs, null)
dependency_update = try(var.argo_events.dependency_update, null)
replace = try(var.argo_events.replace, null)
lint = try(var.argo_events.lint, null)
postrender = try(var.argo_events.postrender, [])
set = try(var.argo_events.set, [])
set_sensitive = try(var.argo_events.set_sensitive, [])
tags = var.tags
}
################################################################################
# AWS Cloudwatch Metrics
################################################################################
locals {
aws_cloudwatch_metrics_service_account = try(var.aws_cloudwatch_metrics.service_account_name, "aws-cloudwatch-metrics")
aws_cloudwatch_metrics_namespace = try(var.aws_cloudwatch_metrics.namespace, "amazon-cloudwatch")
}
module "aws_cloudwatch_metrics" {
source = "aws-ia/eks-blueprints-addon/aws"
version = "1.1.1"
create = var.enable_aws_cloudwatch_metrics
# Disable helm release
create_release = var.create_kubernetes_resources
# https://github.com/aws/eks-charts/tree/master/stable/aws-cloudwatch-metrics
name = try(var.aws_cloudwatch_metrics.name, "aws-cloudwatch-metrics")
description = try(var.aws_cloudwatch_metrics.description, "A Helm chart to deploy aws-cloudwatch-metrics project")
namespace = local.aws_cloudwatch_metrics_namespace
create_namespace = try(var.aws_cloudwatch_metrics.create_namespace, true)
chart = try(var.aws_cloudwatch_metrics.chart, "aws-cloudwatch-metrics")
chart_version = try(var.aws_cloudwatch_metrics.chart_version, "0.0.10")
repository = try(var.aws_cloudwatch_metrics.repository, "https://aws.github.io/eks-charts")
values = try(var.aws_cloudwatch_metrics.values, [])
timeout = try(var.aws_cloudwatch_metrics.timeout, null)
repository_key_file = try(var.aws_cloudwatch_metrics.repository_key_file, null)
repository_cert_file = try(var.aws_cloudwatch_metrics.repository_cert_file, null)
repository_ca_file = try(var.aws_cloudwatch_metrics.repository_ca_file, null)
repository_username = try(var.aws_cloudwatch_metrics.repository_username, null)
repository_password = try(var.aws_cloudwatch_metrics.repository_password, null)
devel = try(var.aws_cloudwatch_metrics.devel, null)
verify = try(var.aws_cloudwatch_metrics.verify, null)
keyring = try(var.aws_cloudwatch_metrics.keyring, null)
disable_webhooks = try(var.aws_cloudwatch_metrics.disable_webhooks, null)
reuse_values = try(var.aws_cloudwatch_metrics.reuse_values, null)
reset_values = try(var.aws_cloudwatch_metrics.reset_values, null)
force_update = try(var.aws_cloudwatch_metrics.force_update, null)
recreate_pods = try(var.aws_cloudwatch_metrics.recreate_pods, null)
cleanup_on_fail = try(var.aws_cloudwatch_metrics.cleanup_on_fail, null)
max_history = try(var.aws_cloudwatch_metrics.max_history, null)
atomic = try(var.aws_cloudwatch_metrics.atomic, null)
skip_crds = try(var.aws_cloudwatch_metrics.skip_crds, null)
render_subchart_notes = try(var.aws_cloudwatch_metrics.render_subchart_notes, null)
disable_openapi_validation = try(var.aws_cloudwatch_metrics.disable_openapi_validation, null)
wait = try(var.aws_cloudwatch_metrics.wait, false)
wait_for_jobs = try(var.aws_cloudwatch_metrics.wait_for_jobs, null)
dependency_update = try(var.aws_cloudwatch_metrics.dependency_update, null)
replace = try(var.aws_cloudwatch_metrics.replace, null)
lint = try(var.aws_cloudwatch_metrics.lint, null)
postrender = try(var.aws_cloudwatch_metrics.postrender, [])
set = concat(
[
{
name = "clusterName"
value = local.cluster_name
},
{
name = "serviceAccount.name"
value = local.aws_cloudwatch_metrics_service_account
}
],
try(var.aws_cloudwatch_metrics.set, [])
)
set_sensitive = try(var.aws_cloudwatch_metrics.set_sensitive, [])
# IAM role for service account (IRSA)
set_irsa_names = ["serviceAccount.annotations.eks\\.amazonaws\\.com/role-arn"]
create_role = try(var.aws_cloudwatch_metrics.create_role, true)
role_name = try(var.aws_cloudwatch_metrics.role_name, "aws-cloudwatch-metrics")
role_name_use_prefix = try(var.aws_cloudwatch_metrics.role_name_use_prefix, true)
role_path = try(var.aws_cloudwatch_metrics.role_path, "/")
role_permissions_boundary_arn = try(var.aws_cloudwatch_metrics.role_permissions_boundary_arn, null)
role_description = try(var.aws_cloudwatch_metrics.role_description, "IRSA for aws-cloudwatch-metrics project")
role_policies = lookup(var.aws_cloudwatch_metrics, "role_policies",
{ CloudWatchAgentServerPolicy = "arn:${local.partition}:iam::aws:policy/CloudWatchAgentServerPolicy" }
)
create_policy = try(var.aws_cloudwatch_metrics.create_policy, false)
oidc_providers = {
this = {
provider_arn = local.oidc_provider_arn
# namespace is inherited from chart
service_account = local.aws_cloudwatch_metrics_service_account
}
}
tags = var.tags
}
################################################################################
# AWS EFS CSI DRIVER
################################################################################
locals {
aws_efs_csi_driver_controller_service_account = try(var.aws_efs_csi_driver.controller_service_account_name, "efs-csi-controller-sa")
aws_efs_csi_driver_node_service_account = try(var.aws_efs_csi_driver.node_service_account_name, "efs-csi-node-sa")
aws_efs_csi_driver_namespace = try(var.aws_efs_csi_driver.namespace, "kube-system")
efs_arns = lookup(var.aws_efs_csi_driver, "efs_arns",
["arn:${local.partition}:elasticfilesystem:${local.region}:${local.account_id}:file-system/*"],
)
efs_access_point_arns = lookup(var.aws_efs_csi_driver, "efs_access_point_arns",
["arn:${local.partition}:elasticfilesystem:${local.region}:${local.account_id}:access-point/*"]
)
}
data "aws_iam_policy_document" "aws_efs_csi_driver" {
count = var.enable_aws_efs_csi_driver ? 1 : 0
source_policy_documents = lookup(var.aws_efs_csi_driver, "source_policy_documents", [])
override_policy_documents = lookup(var.aws_efs_csi_driver, "override_policy_documents", [])
statement {
sid = "AllowDescribeAvailabilityZones"
actions = ["ec2:DescribeAvailabilityZones"]
resources = ["*"]
}
statement {
sid = "AllowDescribeFileSystems"
actions = [
"elasticfilesystem:DescribeAccessPoints",
"elasticfilesystem:DescribeFileSystems",
"elasticfilesystem:DescribeMountTargets"
]
resources = flatten([
local.efs_arns,
local.efs_access_point_arns,
])
}
statement {
actions = [
"elasticfilesystem:CreateAccessPoint",
"elasticfilesystem:TagResource",
]
resources = local.efs_arns
condition {
test = "StringLike"
variable = "aws:RequestTag/efs.csi.aws.com/cluster"
values = ["true"]
}
}
statement {
sid = "AllowDeleteAccessPoint"
actions = ["elasticfilesystem:DeleteAccessPoint"]
resources = local.efs_access_point_arns
condition {
test = "StringLike"
variable = "aws:ResourceTag/efs.csi.aws.com/cluster"
values = ["true"]
}
}
statement {
sid = "ClientReadWrite"
actions = [
"elasticfilesystem:ClientRootAccess",
"elasticfilesystem:ClientWrite",
"elasticfilesystem:ClientMount",
]
resources = local.efs_arns
condition {
test = "Bool"
variable = "elasticfilesystem:AccessedViaMountTarget"
values = ["true"]
}
}
}
module "aws_efs_csi_driver" {
source = "aws-ia/eks-blueprints-addon/aws"
version = "1.1.1"
create = var.enable_aws_efs_csi_driver
# Disable helm release
create_release = var.create_kubernetes_resources
# https://github.com/kubernetes-sigs/aws-efs-csi-driver/tree/master/charts/aws-efs-csi-driver
name = try(var.aws_efs_csi_driver.name, "aws-efs-csi-driver")
description = try(var.aws_efs_csi_driver.description, "A Helm chart to deploy aws-efs-csi-driver")
namespace = local.aws_efs_csi_driver_namespace
create_namespace = try(var.aws_efs_csi_driver.create_namespace, false)
chart = try(var.aws_efs_csi_driver.chart, "aws-efs-csi-driver")
chart_version = try(var.aws_efs_csi_driver.chart_version, "2.5.6")
repository = try(var.aws_efs_csi_driver.repository, "https://kubernetes-sigs.github.io/aws-efs-csi-driver/")
values = try(var.aws_efs_csi_driver.values, [])
timeout = try(var.aws_efs_csi_driver.timeout, null)
repository_key_file = try(var.aws_efs_csi_driver.repository_key_file, null)
repository_cert_file = try(var.aws_efs_csi_driver.repository_cert_file, null)
repository_ca_file = try(var.aws_efs_csi_driver.repository_ca_file, null)
repository_username = try(var.aws_efs_csi_driver.repository_username, null)
repository_password = try(var.aws_efs_csi_driver.repository_password, null)
devel = try(var.aws_efs_csi_driver.devel, null)
verify = try(var.aws_efs_csi_driver.verify, null)
keyring = try(var.aws_efs_csi_driver.keyring, null)
disable_webhooks = try(var.aws_efs_csi_driver.disable_webhooks, null)
reuse_values = try(var.aws_efs_csi_driver.reuse_values, null)
reset_values = try(var.aws_efs_csi_driver.reset_values, null)
force_update = try(var.aws_efs_csi_driver.force_update, null)
recreate_pods = try(var.aws_efs_csi_driver.recreate_pods, null)
cleanup_on_fail = try(var.aws_efs_csi_driver.cleanup_on_fail, null)
max_history = try(var.aws_efs_csi_driver.max_history, null)
atomic = try(var.aws_efs_csi_driver.atomic, null)
skip_crds = try(var.aws_efs_csi_driver.skip_crds, null)
render_subchart_notes = try(var.aws_efs_csi_driver.render_subchart_notes, null)
disable_openapi_validation = try(var.aws_efs_csi_driver.disable_openapi_validation, null)
wait = try(var.aws_efs_csi_driver.wait, false)
wait_for_jobs = try(var.aws_efs_csi_driver.wait_for_jobs, null)
dependency_update = try(var.aws_efs_csi_driver.dependency_update, null)
replace = try(var.aws_efs_csi_driver.replace, null)
lint = try(var.aws_efs_csi_driver.lint, null)
postrender = try(var.aws_efs_csi_driver.postrender, [])
set = concat([
{
name = "controller.serviceAccount.name"
value = local.aws_efs_csi_driver_controller_service_account
},
{
name = "node.serviceAccount.name"
value = local.aws_efs_csi_driver_node_service_account
}],
try(var.aws_efs_csi_driver.set, [])
)
set_sensitive = try(var.aws_efs_csi_driver.set_sensitive, [])
# IAM role for service account (IRSA)
set_irsa_names = [
"controller.serviceAccount.annotations.eks\\.amazonaws\\.com/role-arn",
"node.serviceAccount.annotations.eks\\.amazonaws\\.com/role-arn"
]
create_role = try(var.aws_efs_csi_driver.create_role, true)
role_name = try(var.aws_efs_csi_driver.role_name, "aws-efs-csi-driver")
role_name_use_prefix = try(var.aws_efs_csi_driver.role_name_use_prefix, true)
role_path = try(var.aws_efs_csi_driver.role_path, "/")
role_permissions_boundary_arn = lookup(var.aws_efs_csi_driver, "role_permissions_boundary_arn", null)
role_description = try(var.aws_efs_csi_driver.role_description, "IRSA for aws-efs-csi-driver project")
role_policies = lookup(var.aws_efs_csi_driver, "role_policies", {})
source_policy_documents = data.aws_iam_policy_document.aws_efs_csi_driver[*].json
policy_statements = lookup(var.aws_efs_csi_driver, "policy_statements", [])
policy_name = try(var.aws_efs_csi_driver.policy_name, null)
policy_name_use_prefix = try(var.aws_efs_csi_driver.policy_name_use_prefix, true)
policy_path = try(var.aws_efs_csi_driver.policy_path, null)
policy_description = try(var.aws_efs_csi_driver.policy_description, "IAM Policy for AWS EFS CSI Driver")
oidc_providers = {
controller = {
provider_arn = local.oidc_provider_arn
# namespace is inherited from chart
service_account = local.aws_efs_csi_driver_controller_service_account
}
node = {
provider_arn = local.oidc_provider_arn
# namespace is inherited from chart
service_account = local.aws_efs_csi_driver_node_service_account
}
}
tags = var.tags
}
################################################################################
# AWS for Fluent-bit
################################################################################
locals {
aws_for_fluentbit_service_account = try(var.aws_for_fluentbit.service_account_name, "aws-for-fluent-bit-sa")
aws_for_fluentbit_cw_log_group_name = try(var.aws_for_fluentbit_cw_log_group.create, true) ? try(var.aws_for_fluentbit_cw_log_group.name, "/aws/eks/${var.cluster_name}/aws-fluentbit-logs") : ""
aws_for_fluentbit_namespace = try(var.aws_for_fluentbit.namespace, "kube-system")
}
resource "aws_cloudwatch_log_group" "aws_for_fluentbit" {
count = try(var.aws_for_fluentbit_cw_log_group.create, true) && var.enable_aws_for_fluentbit ? 1 : 0
name = try(var.aws_for_fluentbit_cw_log_group.use_name_prefix, true) ? null : local.aws_for_fluentbit_cw_log_group_name
name_prefix = try(var.aws_for_fluentbit_cw_log_group.use_name_prefix, true) ? try(var.aws_for_fluentbit_cw_log_group.name_prefix, "${local.aws_for_fluentbit_cw_log_group_name}-") : null
retention_in_days = try(var.aws_for_fluentbit_cw_log_group.retention, 90)
kms_key_id = try(var.aws_for_fluentbit_cw_log_group.kms_key_arn, null)
skip_destroy = try(var.aws_for_fluentbit_cw_log_group.skip_destroy, false)
tags = merge(var.tags, try(var.aws_for_fluentbit_cw_log_group.tags, {}))
}
data "aws_iam_policy_document" "aws_for_fluentbit" {
count = (try(var.aws_for_fluentbit_cw_log_group.create, true) || length(lookup(var.aws_for_fluentbit, "s3_bucket_arns", [])) > 0) && var.enable_aws_for_fluentbit ? 1 : 0
source_policy_documents = lookup(var.aws_for_fluentbit, "source_policy_documents", [])
override_policy_documents = lookup(var.aws_for_fluentbit, "override_policy_documents", [])
dynamic "statement" {
for_each = try(var.aws_for_fluentbit_cw_log_group.create, true) ? [1] : []
content {
sid = "PutLogEvents"
effect = "Allow"
resources = [
"arn:${local.partition}:logs:${local.region}:${local.account_id}:log-group:${try(var.aws_for_fluentbit_cw_log_group.name, "*")}:log-stream:*",
]
actions = [
"logs:PutLogEvents"
]
}
}
dynamic "statement" {
for_each = try(var.aws_for_fluentbit_cw_log_group.create, true) ? [1] : []
content {
sid = "CreateCWLogs"
effect = "Allow"
resources = [
"arn:${local.partition}:logs:${local.region}:${local.account_id}:log-group:${try(var.aws_for_fluentbit_cw_log_group.name, "*")}:*",
]
actions = [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:DescribeLogGroups",
"logs:DescribeLogStreams",
"logs:PutRetentionPolicy",
]
}
}
dynamic "statement" {
for_each = length(lookup(var.aws_for_fluentbit, "s3_bucket_arns", [])) > 0 ? [1] : []
content {
sid = "S3Write"
actions = [
"s3:ListBucket",
"s3:PutObject",
"s3:PutObjectAcl",
"s3:GetObject",
"s3:GetObjectAcl",
"s3:DeleteObject",
"s3:DeleteObjectVersion",
]
resources = var.aws_for_fluentbit.s3_bucket_arns
}
}
}
module "aws_for_fluentbit" {
source = "aws-ia/eks-blueprints-addon/aws"
version = "1.1.1"
create = var.enable_aws_for_fluentbit
# Disable helm release
create_release = var.create_kubernetes_resources
# https://github.com/aws/eks-charts/blob/master/stable/aws-for-fluent-bit/Chart.yaml
name = try(var.aws_for_fluentbit.name, "aws-for-fluent-bit")
description = try(var.aws_for_fluentbit.description, "A Helm chart to install the Fluent-bit Driver")
namespace = local.aws_for_fluentbit_namespace
create_namespace = try(var.aws_for_fluentbit.create_namespace, false)
chart = try(var.aws_for_fluentbit.chart, "aws-for-fluent-bit")
chart_version = try(var.aws_for_fluentbit.chart_version, "0.1.32")
repository = try(var.aws_for_fluentbit.repository, "https://aws.github.io/eks-charts")
values = try(var.aws_for_fluentbit.values, [])
timeout = try(var.aws_for_fluentbit.timeout, null)
repository_key_file = try(var.aws_for_fluentbit.repository_key_file, null)
repository_cert_file = try(var.aws_for_fluentbit.repository_cert_file, null)
repository_ca_file = try(var.aws_for_fluentbit.repository_ca_file, null)
repository_username = try(var.aws_for_fluentbit.repository_username, null)
repository_password = try(var.aws_for_fluentbit.repository_password, null)
devel = try(var.aws_for_fluentbit.devel, null)
verify = try(var.aws_for_fluentbit.verify, null)
keyring = try(var.aws_for_fluentbit.keyring, null)
disable_webhooks = try(var.aws_for_fluentbit.disable_webhooks, null)
reuse_values = try(var.aws_for_fluentbit.reuse_values, null)
reset_values = try(var.aws_for_fluentbit.reset_values, null)
force_update = try(var.aws_for_fluentbit.force_update, null)
recreate_pods = try(var.aws_for_fluentbit.recreate_pods, null)
cleanup_on_fail = try(var.aws_for_fluentbit.cleanup_on_fail, null)
max_history = try(var.aws_for_fluentbit.max_history, null)
atomic = try(var.aws_for_fluentbit.atomic, null)
skip_crds = try(var.aws_for_fluentbit.skip_crds, null)
render_subchart_notes = try(var.aws_for_fluentbit.render_subchart_notes, null)
disable_openapi_validation = try(var.aws_for_fluentbit.disable_openapi_validation, null)
wait = try(var.aws_for_fluentbit.wait, false)
wait_for_jobs = try(var.aws_for_fluentbit.wait_for_jobs, null)
dependency_update = try(var.aws_for_fluentbit.dependency_update, null)
replace = try(var.aws_for_fluentbit.replace, null)
lint = try(var.aws_for_fluentbit.lint, null)
postrender = try(var.aws_for_fluentbit.postrender, [])
set = concat([
{
name = "serviceAccount.name"
value = local.aws_for_fluentbit_service_account
},
{
name = "cloudWatch.region"
value = local.region
},
{
name = "cloudWatchLogs.logGroupName"
value = local.aws_for_fluentbit_cw_log_group_name
},
{
name = "cloudWatchLogs.logGroupTemplate"
value = ""
},
{
name = "cloudWatchLogs.autoCreateGroup"
value = false
},
{
name = "cloudWatchLogs.region"
value = local.region
}],
try(var.aws_for_fluentbit.set, [])
)
set_sensitive = try(var.aws_for_fluentbit.set_sensitive, [])
# IAM role for service account (IRSA)
set_irsa_names = [
"serviceAccount.annotations.eks\\.amazonaws\\.com/role-arn",
]
create_role = try(var.aws_for_fluentbit.create_role, true)
role_name = try(var.aws_for_fluentbit.role_name, "aws-for-fluent-bit")
role_name_use_prefix = try(var.aws_for_fluentbit.role_name_use_prefix, true)
role_path = try(var.aws_for_fluentbit.role_path, "/")
role_permissions_boundary_arn = lookup(var.aws_for_fluentbit, "role_permissions_boundary_arn", null)
role_description = try(var.aws_for_fluentbit.role_description, "IRSA for aws-for-fluent-bit")
role_policies = lookup(var.aws_for_fluentbit, "role_policies", {})
source_policy_documents = data.aws_iam_policy_document.aws_for_fluentbit[*].json
policy_statements = lookup(var.aws_for_fluentbit, "policy_statements", [])
policy_name = try(var.aws_for_fluentbit.policy_name, "aws-for-fluent-bit")
policy_name_use_prefix = try(var.aws_for_fluentbit.policy_name_use_prefix, true)
policy_path = try(var.aws_for_fluentbit.policy_path, null)
policy_description = try(var.aws_for_fluentbit.policy_description, "IAM Policy for AWS Fluentbit")
oidc_providers = {
this = {
provider_arn = local.oidc_provider_arn
# namespace is inherited from chart
service_account = local.aws_for_fluentbit_service_account
}
}
tags = var.tags
}
resource "kubernetes_config_map_v1_data" "aws_for_fluentbit_containerinsights" {
count = var.enable_aws_for_fluentbit && try(var.aws_for_fluentbit.enable_containerinsights, false) ? 1 : 0
depends_on = [module.aws_for_fluentbit]
force = true
metadata {
name = "aws-for-fluent-bit"
namespace = local.aws_for_fluentbit_namespace
}
data = {
"fluent-bit.conf" = try(
var.aws_for_fluentbit.fluentbit_conf,
<<-EOT
[SERVICE]
Flush 5
Grace 30
Log_Level info
Daemon off
Parsers_File parsers.conf
HTTP_Server On
HTTP_Listen 0.0.0.0
HTTP_Port 2020
storage.path /var/fluent-bit/state/flb-storage/
storage.sync normal
storage.checksum off
storage.backlog.mem_limit 5M
@INCLUDE application-log.conf
@INCLUDE dataplane-log.conf
@INCLUDE host-log.conf
EOT
)
"application-log.conf" = try(
var.aws_for_fluentbit.application_log_conf,
<<-EOT
[INPUT]
Name tail
Tag application.*
Exclude_Path /var/log/containers/cloudwatch-agent*, /var/log/containers/fluent-bit*, /var/log/containers/aws-node*, /var/log/containers/kube-proxy*
Path /var/log/containers/*.log
multiline.parser docker, cri
DB /var/fluent-bit/state/flb_container.db
Mem_Buf_Limit 50MB
Skip_Long_Lines On
Refresh_Interval 10
Rotate_Wait 30
storage.type filesystem
Read_from_Head Off
[INPUT]
Name tail
Tag application.*
Path /var/log/containers/fluent-bit*
multiline.parser docker, cri
DB /var/fluent-bit/state/flb_log.db
Mem_Buf_Limit 5MB
Skip_Long_Lines On
Refresh_Interval 10
Read_from_Head Off
[INPUT]
Name tail
Tag application.*
Path /var/log/containers/cloudwatch-agent*
multiline.parser docker, cri
DB /var/fluent-bit/state/flb_cwagent.db
Mem_Buf_Limit 5MB
Skip_Long_Lines On
Refresh_Interval 10
Read_from_Head Off
[FILTER]
Name kubernetes
Match application.*
Kube_URL https://kubernetes.default.svc:443
Kube_Tag_Prefix application.var.log.containers.
Merge_Log On
Merge_Log_Key log_processed
K8S-Logging.Parser On
K8S-Logging.Exclude Off
Labels Off
Annotations Off
${try(var.aws_for_fluentbit.kubelet_monitoring, false) ? "Use_Kubelet On" : ""}
${try(var.aws_for_fluentbit.kubelet_monitoring, false) ? "Kubelet_Port 10250" : ""}
Buffer_Size 0
[OUTPUT]
Name cloudwatch_logs
Match application.*
region ${local.region}
log_group_name /aws/containerinsights/${local.cluster_name}/application
log_stream_prefix $${HOSTNAME}-
auto_create_group true
extra_user_agent container-insights
workers 1
EOT
)
"dataplane-log.conf" = try(
var.aws_for_fluentbit.dataplane_log_conf,
<<-EOT
[INPUT]
Name systemd
Tag dataplane.systemd.*
Systemd_Filter _SYSTEMD_UNIT=docker.service
Systemd_Filter _SYSTEMD_UNIT=containerd.service
Systemd_Filter _SYSTEMD_UNIT=kubelet.service
DB /var/fluent-bit/state/systemd.db
Path /var/log/journal
Read_From_Tail On
[INPUT]
Name tail
Tag dataplane.tail.*
Path /var/log/containers/aws-node*, /var/log/containers/kube-proxy*
multiline.parser docker, cri
DB /var/fluent-bit/state/flb_dataplane_tail.db
Mem_Buf_Limit 50MB
Skip_Long_Lines On
Refresh_Interval 10
Rotate_Wait 30
storage.type filesystem
Read_from_Head Off
[FILTER]
Name modify
Match dataplane.systemd.*
Rename _HOSTNAME hostname
Rename _SYSTEMD_UNIT systemd_unit
Rename MESSAGE message
Remove_regex ^((?!hostname|systemd_unit|message).)*$
[FILTER]
Name aws
Match dataplane.*
imds_version v2
[OUTPUT]
Name cloudwatch_logs
Match dataplane.*
region ${local.region}
log_group_name /aws/containerinsights/${local.cluster_name}/dataplane
log_stream_prefix $${HOSTNAME}-
auto_create_group true
extra_user_agent container-insights
EOT
)
"host-log.conf" = try(
var.aws_for_fluentbit.host_log_conf,
<<-EOT
[INPUT]
Name tail
Tag host.dmesg
Path /var/log/dmesg
Key message
DB /var/fluent-bit/state/flb_dmesg.db
Mem_Buf_Limit 5MB
Skip_Long_Lines On
Refresh_Interval 10
Read_from_Head Off
[INPUT]
Name tail
Tag host.messages
Path /var/log/messages
Parser syslog
DB /var/fluent-bit/state/flb_messages.db
Mem_Buf_Limit 5MB
Skip_Long_Lines On
Refresh_Interval 10
Read_from_Head Off
[INPUT]
Name tail
Tag host.secure
Path /var/log/secure
Parser syslog
DB /var/fluent-bit/state/flb_secure.db
Mem_Buf_Limit 5MB
Skip_Long_Lines On
Refresh_Interval 10
Read_from_Head Off
[FILTER]
Name aws
Match host.*
imds_version v2
[OUTPUT]
Name cloudwatch_logs
Match host.*
region ${local.region}
log_group_name /aws/containerinsights/${local.cluster_name}/host
log_stream_prefix $${HOSTNAME}.
auto_create_group true
extra_user_agent container-insights
EOT
)
"parsers.conf" = try(
var.aws_for_fluentbit.parsers_conf,
<<-EOT
[PARSER]
Name syslog
Format regex
Regex ^(?<time>[^ ]* {1,2}[^ ]* [^ ]*) (?<host>[^ ]*) (?<ident>[a-zA-Z0-9_\/\.\-]*)(?:\[(?<pid>[0-9]+)\])?(?:[^\:]*\:)? *(?<message>.*)$
Time_Key time
Time_Format %b %d %H:%M:%S
[PARSER]
Name container_firstline
Format regex
Regex (?<log>(?<="log":")\S(?!\.).*?)(?<!\\)".*(?<stream>(?<="stream":").*?)".*(?<time>\d{4}-\d{1,2}-\d{1,2}T\d{2}:\d{2}:\d{2}\.\w*).*(?=})
Time_Key time
Time_Format %Y-%m-%dT%H:%M:%S.%LZ
[PARSER]
Name cwagent_firstline
Format regex
Regex (?<log>(?<="log":")\d{4}[\/-]\d{1,2}[\/-]\d{1,2}[ T]\d{2}:\d{2}:\d{2}(?!\.).*?)(?<!\\)".*(?<stream>(?<="stream":").*?)".*(?<time>\d{4}-\d{1,2}-\d{1,2}T\d{2}:\d{2}:\d{2}\.\w*).*(?=})
Time_Key time
Time_Format %Y-%m-%dT%H:%M:%S.%LZ
EOT
)
}
}
################################################################################
# AWS FSX CSI DRIVER
################################################################################
locals {
aws_fsx_csi_driver_controller_service_account = try(var.aws_fsx_csi_driver.controller_service_account_name, "aws-fsx-csi-controller-sa")
aws_fsx_csi_driver_node_service_account = try(var.aws_fsx_csi_driver.node_service_account_name, "aws-fsx-csi-node-sa")
aws_fsx_csi_driver_namespace = try(var.aws_fsx_csi_driver.namespace, "kube-system")
}
data "aws_iam_policy_document" "aws_fsx_csi_driver" {
count = var.enable_aws_fsx_csi_driver ? 1 : 0
source_policy_documents = lookup(var.aws_fsx_csi_driver, "source_policy_documents", [])
override_policy_documents = lookup(var.aws_fsx_csi_driver, "override_policy_documents", [])
statement {
sid = "AllowCreateServiceLinkedRoles"
resources = ["arn:${local.partition}:iam::*:role/aws-service-role/s3.data-source.lustre.fsx.${data.aws_partition.current.dns_suffix}/*"]
actions = [
"iam:CreateServiceLinkedRole",
"iam:AttachRolePolicy",
"iam:PutRolePolicy",