-
-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathvariables.tf
More file actions
2455 lines (2069 loc) · 97.5 KB
/
Copy pathvariables.tf
File metadata and controls
2455 lines (2069 loc) · 97.5 KB
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
# Cluster Configuration
variable "cluster_name" {
type = string
description = "Specifies the name of the cluster. This name is used to identify the cluster within the infrastructure and should be unique across all deployments."
validation {
condition = can(regex("^[a-z0-9](?:[a-z0-9-]{0,30}[a-z0-9])?$", var.cluster_name))
error_message = "The cluster name must start and end with a lowercase letter or number, can contain hyphens, and must be no longer than 32 characters."
}
}
variable "cluster_domain" {
type = string
default = "cluster.local"
description = "Specifies the domain name used by the cluster. This domain name is integral for internal networking and service discovery within the cluster. The default is 'cluster.local', which is commonly used for local Kubernetes clusters."
validation {
condition = can(regex("^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)*(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)$", var.cluster_domain))
error_message = "The cluster domain must be a valid domain: each segment must start and end with a letter or number, can contain hyphens, and each segment must be no longer than 63 characters."
}
}
variable "cluster_rdns" {
type = string
default = null
description = "Specifies the general reverse DNS FQDN for the cluster, used for internal networking and service discovery. Supports dynamic substitution with placeholders: {{ cluster-domain }}, {{ cluster-name }}, {{ hostname }}, {{ id }}, {{ ip-labels }}, {{ ip-type }}, {{ pool }}, {{ role }}."
validation {
condition = var.cluster_rdns == null || can(regex("^(?:(?:[a-z0-9{} ](?:[a-z0-9-{} ]{0,61}[a-z0-9{} ])?\\.)*(?:[a-z0-9{} ](?:[a-z0-9-{} ]{0,61}[a-z0-9{} ])?))$", var.cluster_rdns))
error_message = "The reverse DNS domain must be a valid domain: each segment must start and end with a letter or number, can contain hyphens, and each segment must be no longer than 63 characters."
}
}
variable "cluster_rdns_ipv4" {
type = string
default = null
description = "Defines the IPv4-specific reverse DNS FQDN for the cluster, crucial for network operations and service discovery. Supports dynamic placeholders: {{ cluster-domain }}, {{ cluster-name }}, {{ hostname }}, {{ id }}, {{ ip-labels }}, {{ ip-type }}, {{ pool }}, {{ role }}."
validation {
condition = var.cluster_rdns_ipv4 == null || can(regex("^(?:(?:[a-z0-9{} ](?:[a-z0-9-{} ]{0,61}[a-z0-9{} ])?\\.)*(?:[a-z0-9{} ](?:[a-z0-9-{} ]{0,61}[a-z0-9{} ])?))$", var.cluster_rdns_ipv4))
error_message = "The reverse DNS domain must be a valid domain: each segment must start and end with a letter or number, can contain hyphens, and each segment must be no longer than 63 characters."
}
}
variable "cluster_rdns_ipv6" {
type = string
default = null
description = "Defines the IPv6-specific reverse DNS FQDN for the cluster, crucial for network operations and service discovery. Supports dynamic placeholders: {{ cluster-domain }}, {{ cluster-name }}, {{ hostname }}, {{ id }}, {{ ip-labels }}, {{ ip-type }}, {{ pool }}, {{ role }}."
validation {
condition = var.cluster_rdns_ipv6 == null || can(regex("^(?:(?:[a-z0-9{} ](?:[a-z0-9-{} ]{0,61}[a-z0-9{} ])?\\.)*(?:[a-z0-9{} ](?:[a-z0-9-{} ]{0,61}[a-z0-9{} ])?))$", var.cluster_rdns_ipv6))
error_message = "The reverse DNS domain must be a valid domain: each segment must start and end with a letter or number, can contain hyphens, and each segment must be no longer than 63 characters."
}
}
variable "cluster_access" {
type = string
default = "public"
description = "Defines how the cluster is accessed externally. Specifies if access should be through public or private IPs."
validation {
condition = contains(["public", "private"], var.cluster_access)
error_message = "Invalid value for 'cluster_access'. Valid options are 'public' or 'private'."
}
}
variable "cluster_kubeconfig_path" {
type = string
default = null
description = "If not null, the kubeconfig will be written to a file speficified."
}
variable "cluster_talosconfig_path" {
type = string
default = null
description = "If not null, the talosconfig will be written to a file speficified."
}
variable "cluster_healthcheck_enabled" {
type = bool
default = true
description = "Determines whether are executed during cluster deployment and upgrade."
}
variable "cluster_delete_protection" {
type = bool
default = true
description = "Adds delete protection for resources that support it."
}
variable "cluster_allow_scheduling_on_control_planes" {
type = bool
default = null
description = "Allow scheduling on control plane nodes. If this is false, scheduling on control plane nodes is explicitly disabled. Defaults to true if there are no workers present."
}
# Client Tools
variable "client_prerequisites_check_enabled" {
type = bool
default = true
description = "Controls whether a preflight check verifies that required client tools are installed before provisioning."
}
variable "talosctl_version_check_enabled" {
type = bool
default = true
description = "Controls whether a preflight check verifies the local talosctl client version before provisioning."
}
variable "talosctl_retries" {
type = number
default = 100
description = "Specifies how many times talosctl operations should retry before failing. This setting helps improve resilience against transient network issues or temporary API unavailability."
validation {
condition = var.talosctl_retries >= 0
error_message = "The talosctl retries value must be at least 0."
}
}
# Network Configuration
variable "network_ipv4_cidr" {
type = string
default = "10.0.0.0/16"
description = "Specifies the main IPv4 CIDR block for the network. This CIDR block is used to allocate IP addresses within the network."
}
variable "network_node_ipv4_cidr" {
type = string
default = null # 10.0.64.0/19 when network_ipv4_cidr is 10.0.0.0/16
description = "Specifies the Node IPv4 CIDR used for allocating IP addresses to both Control Plane and Worker nodes within the cluster. If not explicitly provided, a default subnet is dynamically calculated from the specified network_ipv4_cidr."
}
variable "network_node_ipv4_subnet_mask_size" {
type = number
default = null # /25 when network_pod_ipv4_cidr is 10.0.128.0/17
description = "Specifies the IPv4 subnet mask size used for node pools within the cluster. This setting determines the network segmentation precision, with a smaller mask size allowing more IP addresses per subnet. If not explicitly provided, an optimal default size is dynamically calculated from the network_pod_ipv4_cidr."
}
variable "network_service_ipv4_cidr" {
type = string
default = null # 10.0.96.0/19 when network_ipv4_cidr is 10.0.0.0/16
description = "Specifies the Service IPv4 CIDR block used for allocating ClusterIPs to services within the cluster. If not provided, a default subnet is dynamically calculated from the specified network_ipv4_cidr."
}
variable "network_pod_ipv4_cidr" {
type = string
default = null # 10.0.128.0/17 when network_ipv4_cidr is 10.0.0.0/16
description = "Defines the Pod IPv4 CIDR block allocated for use by pods within the cluster. This CIDR block is essential for internal pod communications. If a specific subnet is not provided, a default is dynamically calculated from the network_ipv4_cidr."
}
variable "network_native_routing_ipv4_cidr" {
type = string
default = null
description = "Specifies the IPv4 CIDR block that the CNI assumes will be routed natively by the underlying network infrastructure without the need for SNAT. When omitted, this defaults to network_pod_ipv4_cidr if bare metal servers are enabled, otherwise network_ipv4_cidr."
}
# Firewall Configuration
variable "firewall_use_current_ipv4" {
type = bool
default = null
description = "Determines whether the current IPv4 address is used for Talos and Kube API firewall rules. If `cluster_access` is set to `public`, the default is true."
}
variable "firewall_use_current_ipv6" {
type = bool
default = null
description = "Determines whether the current IPv6 /64 CIDR is used for Talos and Kube API firewall rules. Set to true to require IPv6 or false to disable it. When omitted, IPv6 is used only if it is detected automatically."
}
variable "firewall_extra_rules" {
type = list(object({
description = string
direction = string
source_ips = optional(list(string), [])
destination_ips = optional(list(string), [])
protocol = string
port = optional(string)
}))
default = []
description = "Additional firewall rules to apply to the cluster."
validation {
condition = alltrue([
for rule in var.firewall_extra_rules : (
rule.direction == "in" || rule.direction == "out"
)
])
error_message = "Each rule must specify 'direction' as 'in' or 'out'."
}
validation {
condition = alltrue([
for rule in var.firewall_extra_rules : (
rule.protocol == "tcp" || rule.protocol == "udp" || rule.protocol == "icmp" ||
rule.protocol == "gre" || rule.protocol == "esp"
)
])
error_message = "Each rule must specify 'protocol' as 'tcp', 'udp', 'icmp', 'gre', or 'esp'."
}
validation {
condition = alltrue([
for rule in var.firewall_extra_rules : (
(rule.direction == "in" && rule.source_ips != null && (rule.destination_ips == null || length(rule.destination_ips) == 0)) ||
(rule.direction == "out" && rule.destination_ips != null && (rule.source_ips == null || length(rule.source_ips) == 0))
)
])
error_message = "For 'in' direction, 'source_ips' must be provided and 'destination_ips' must be null or empty. For 'out' direction, 'destination_ips' must be provided and 'source_ips' must be null or empty."
}
validation {
condition = alltrue([
for rule in var.firewall_extra_rules : (
(rule.protocol != "icmp" && rule.protocol != "gre" && rule.protocol != "esp") || (rule.port == null)
)
])
error_message = "Port must not be specified when 'protocol' is 'icmp', 'gre', or 'esp'."
}
// Validation to ensure port is specified for protocols that have ports
validation {
condition = alltrue([
for rule in var.firewall_extra_rules : (
rule.protocol == "tcp" || rule.protocol == "udp" ? rule.port != null : true
)
])
error_message = "Port must be specified when 'protocol' is 'tcp' or 'udp'."
}
}
variable "firewall_api_source" {
type = list(string)
default = null
description = "Source networks that have access to Kube and Talos API. If set, this overrides the firewall_use_current_ipv4 and firewall_use_current_ipv6 settings."
}
variable "firewall_kube_api_source" {
type = list(string)
default = null
description = "Source networks that have access to Kube API. If set, this overrides the firewall_use_current_ipv4 and firewall_use_current_ipv6 settings."
}
variable "firewall_talos_api_source" {
type = list(string)
default = null
description = "Source networks that have access to Talos API. If set, this overrides the firewall_use_current_ipv4 and firewall_use_current_ipv6 settings."
}
variable "firewall_id" {
type = number
default = null
description = "ID of an existing Hetzner Cloud Firewall to use instead of creating a new one. When set, firewall management is delegated to an external resource and this module will only attach the firewall to servers."
}
# Control Plane
variable "control_plane_public_vip_ipv4_enabled" {
type = bool
default = false
description = "If true, a floating IP will be created and assigned to the Control Plane nodes."
}
variable "control_plane_public_vip_ipv4_id" {
type = number
default = null
description = "Specifies the Floating IP ID for the Control Plane nodes. A new floating IP will be created if this is set to null."
}
variable "control_plane_private_vip_ipv4_enabled" {
type = bool
default = true
description = "If true, an alias IP will be created and assigned to the Control Plane nodes."
}
variable "kube_api_admission_control" {
type = list(any)
default = []
description = "List of admission control settings for the Kube API. If set, this overrides the default admission control."
}
variable "control_plane_nodepools" {
type = list(object({
name = string
location = string
type = string
backups = optional(bool, false)
keep_disk = optional(bool, false)
labels = optional(map(string), {})
annotations = optional(map(string), {})
taints = optional(list(string), [])
count = optional(number, 1)
rdns = optional(string)
rdns_ipv4 = optional(string)
rdns_ipv6 = optional(string)
}))
description = "Configures the number and attributes of Control Plane nodes."
validation {
condition = length(var.control_plane_nodepools) == length(distinct([for np in var.control_plane_nodepools : np.name]))
error_message = "Control Plane nodepool names must be unique to avoid configuration conflicts."
}
validation {
condition = sum([for np in var.control_plane_nodepools : np.count]) <= 9
error_message = "The total count of all nodes in Control Plane nodepools must not exceed 9."
}
validation {
condition = sum([for np in var.control_plane_nodepools : np.count]) % 2 == 1
error_message = "The sum of all Control Plane nodes must be odd to ensure high availability."
}
validation {
condition = alltrue([
for np in var.control_plane_nodepools : contains([
"fsn1", "nbg1", "hel1", "ash", "hil", "sin"
], np.location)
])
error_message = "Each nodepool location must be one of: 'fsn1' (Falkenstein), 'nbg1' (Nuremberg), 'hel1' (Helsinki), 'ash' (Ashburn), 'hil' (Hillsboro), 'sin' (Singapore)."
}
validation {
condition = alltrue([
for np in var.control_plane_nodepools : length(var.cluster_name) + length(np.name) <= 56
])
error_message = "The combined length of the cluster name and any Control Plane nodepool name must not exceed 56 characters."
}
validation {
condition = alltrue([
for np in var.control_plane_nodepools : np.rdns == null || can(regex("^(?:(?:[a-z0-9{} ](?:[a-z0-9-{} ]{0,61}[a-z0-9{} ])?\\.)*(?:[a-z0-9{} ](?:[a-z0-9-{} ]{0,61}[a-z0-9{} ])?))$", np.rdns))
])
error_message = "The reverse DNS domain must be a valid domain: each segment must start and end with a letter or number, can contain hyphens, and each segment must be no longer than 63 characters. Supports dynamic substitution with placeholders: {{ cluster-domain }}, {{ cluster-name }}, {{ hostname }}, {{ id }}, {{ ip-labels }}, {{ ip-type }}, {{ pool }}, {{ role }}."
}
validation {
condition = alltrue([
for np in var.control_plane_nodepools : np.rdns_ipv4 == null || can(regex("^(?:(?:[a-z0-9{} ](?:[a-z0-9-{} ]{0,61}[a-z0-9{} ])?\\.)*(?:[a-z0-9{} ](?:[a-z0-9-{} ]{0,61}[a-z0-9{} ])?))$", np.rdns_ipv4))
])
error_message = "The rdns_ipv4 must be a valid IPv4 reverse DNS domain: each segment must start and end with a letter or number, can contain hyphens, and each segment must be no longer than 63 characters. Supports dynamic substitution with placeholders: {{ cluster-domain }}, {{ cluster-name }}, {{ hostname }}, {{ id }}, {{ ip-labels }}, {{ ip-type }}, {{ pool }}, {{ role }}."
}
validation {
condition = alltrue([
for np in var.control_plane_nodepools : np.rdns_ipv6 == null || can(regex("^(?:(?:[a-z0-9{} ](?:[a-z0-9-{} ]{0,61}[a-z0-9{} ])?\\.)*(?:[a-z0-9{} ](?:[a-z0-9-{} ]{0,61}[a-z0-9{} ])?))$", np.rdns_ipv6))
])
error_message = "The rdns_ipv6 must be a valid IPv6 reverse DNS domain: each segment must start and end with a letter or number, can contain hyphens, and each segment must be no longer than 63 characters. Supports dynamic substitution with placeholders: {{ cluster-domain }}, {{ cluster-name }}, {{ hostname }}, {{ id }}, {{ ip-labels }}, {{ ip-type }}, {{ pool }}, {{ role }}."
}
}
variable "control_plane_config_patches" {
type = any
default = []
description = "List of configuration patches applied to the Control Plane nodes."
}
# Worker
variable "worker_nodepools" {
type = list(object({
name = string
location = string
type = string
backups = optional(bool, false)
keep_disk = optional(bool, false)
labels = optional(map(string), {})
annotations = optional(map(string), {})
taints = optional(list(string), [])
count = optional(number, 1)
subnet = optional(string)
rdns = optional(string)
rdns_ipv4 = optional(string)
rdns_ipv6 = optional(string)
placement_group = optional(bool, true)
}))
default = []
description = "Defines configuration settings for Worker node pools within the cluster."
validation {
condition = length(var.worker_nodepools) == length(distinct([for np in var.worker_nodepools : np.name]))
error_message = "Worker nodepool names must be unique to avoid configuration conflicts."
}
validation {
condition = sum(concat(
[for worker_nodepool in var.worker_nodepools : coalesce(worker_nodepool.count, 1)],
[for control_nodepool in var.control_plane_nodepools : coalesce(control_nodepool.count, 1)]
)) <= 100
error_message = "The total count of nodes in both worker and Control Plane nodepools must not exceed 100 to ensure manageable cluster size."
}
validation {
condition = alltrue([
for np in var.worker_nodepools : contains([
"fsn1", "nbg1", "hel1", "ash", "hil", "sin"
], np.location)
])
error_message = "Each nodepool location must be one of: 'fsn1' (Falkenstein), 'nbg1' (Nuremberg), 'hel1' (Helsinki), 'ash' (Ashburn), 'hil' (Hillsboro), 'sin' (Singapore)."
}
validation {
condition = alltrue([
for np in var.worker_nodepools : length(var.cluster_name) + length(np.name) <= 56
])
error_message = "The combined length of the cluster name and any Worker nodepool name must not exceed 56 characters."
}
validation {
condition = length([
for np in var.worker_nodepools : np.subnet if np.subnet != null
]) == length(distinct([
for np in var.worker_nodepools : np.subnet if np.subnet != null
]))
error_message = "Worker nodepool subnets must be unique."
}
validation {
condition = alltrue([
for np in var.worker_nodepools : np.subnet == null || contains(local.network_pinned_worker_ipv4_cidrs, np.subnet)
])
error_message = "Worker nodepool subnet must be one of the calculated pinned worker subnets."
}
validation {
condition = alltrue([
for np in var.worker_nodepools : np.rdns == null || can(regex("^(?:(?:[a-z0-9{} ](?:[a-z0-9-{} ]{0,61}[a-z0-9{} ])?\\.)*(?:[a-z0-9{} ](?:[a-z0-9-{} ]{0,61}[a-z0-9{} ])?))$", np.rdns))
])
error_message = "The reverse DNS domain must be a valid domain: each segment must start and end with a letter or number, can contain hyphens, and each segment must be no longer than 63 characters. Supports dynamic substitution with placeholders: {{ cluster-domain }}, {{ cluster-name }}, {{ hostname }}, {{ id }}, {{ ip-labels }}, {{ ip-type }}, {{ pool }}, {{ role }}."
}
validation {
condition = alltrue([
for np in var.worker_nodepools : np.rdns_ipv4 == null || can(regex("^(?:(?:[a-z0-9{} ](?:[a-z0-9-{} ]{0,61}[a-z0-9{} ])?\\.)*(?:[a-z0-9{} ](?:[a-z0-9-{} ]{0,61}[a-z0-9{} ])?))$", np.rdns_ipv4))
])
error_message = "The rdns_ipv4 must be a valid IPv4 reverse DNS domain: each segment must start and end with a letter or number, can contain hyphens, and each segment must be no longer than 63 characters. Supports dynamic substitution with placeholders: {{ cluster-domain }}, {{ cluster-name }}, {{ hostname }}, {{ id }}, {{ ip-labels }}, {{ ip-type }}, {{ pool }}, {{ role }}."
}
validation {
condition = alltrue([
for np in var.worker_nodepools : np.rdns_ipv6 == null || can(regex("^(?:(?:[a-z0-9{} ](?:[a-z0-9-{} ]{0,61}[a-z0-9{} ])?\\.)*(?:[a-z0-9{} ](?:[a-z0-9-{} ]{0,61}[a-z0-9{} ])?))$", np.rdns_ipv6))
])
error_message = "The rdns_ipv6 must be a valid IPv6 reverse DNS domain: each segment must start and end with a letter or number, can contain hyphens, and each segment must be no longer than 63 characters. Supports dynamic substitution with placeholders: {{ cluster-domain }}, {{ cluster-name }}, {{ hostname }}, {{ id }}, {{ ip-labels }}, {{ ip-type }}, {{ pool }}, {{ role }}."
}
}
variable "worker_config_patches" {
type = any
default = []
description = "List of configuration patches applied to the Worker nodes."
}
variable "bare_metal_config_patches" {
type = any
default = []
description = "List of configuration patches applied to the bare metal Worker nodes."
}
variable "bare_metal_nodepools" {
type = list(object({
name = string
architecture = optional(string, "amd64")
servers = list(object({
number = number
private_ipv4 = string
install_disk = optional(string)
}))
labels = optional(map(string), {})
annotations = optional(map(string), {})
taints = optional(list(string), [])
rdns = optional(string)
rdns_ipv4 = optional(string)
rdns_ipv6 = optional(string)
}))
default = []
description = "Defines configuration settings for Hetzner bare metal Worker node pools."
validation {
condition = length(var.bare_metal_nodepools) == length(distinct([for np in var.bare_metal_nodepools : np.name]))
error_message = "Bare metal nodepool names must be unique to avoid configuration conflicts."
}
validation {
condition = length(var.bare_metal_nodepools) == 0 || (var.hcloud_robot_user != null && var.hcloud_robot_password != null)
error_message = "hcloud_robot_user and hcloud_robot_password must be set when bare metal nodepools are configured."
}
validation {
condition = alltrue([
for np in var.bare_metal_nodepools : contains(["amd64", "arm64"], np.architecture)
])
error_message = "Bare metal nodepool architecture must be one of: amd64, arm64."
}
validation {
condition = length(flatten([
for np in var.bare_metal_nodepools : [for server in np.servers : server.number]
])) == length(distinct(flatten([
for np in var.bare_metal_nodepools : [for server in np.servers : server.number]
])))
error_message = "Bare metal server numbers must be unique to avoid configuration conflicts."
}
validation {
condition = length(flatten([
for np in var.bare_metal_nodepools : [for server in np.servers : server.private_ipv4]
])) == length(distinct(flatten([
for np in var.bare_metal_nodepools : [for server in np.servers : server.private_ipv4]
])))
error_message = "Bare metal server private IPv4 addresses must be unique to avoid configuration conflicts."
}
validation {
condition = alltrue(flatten([
for np in var.bare_metal_nodepools : [
for server in np.servers : can(cidrhost("${server.private_ipv4}/32", 0))
]
]))
error_message = "Bare metal server private_ipv4 values must be valid IPv4 addresses."
}
validation {
condition = alltrue(flatten([
for np in var.bare_metal_nodepools : [
for server in np.servers : server.install_disk == null || can(regex("^[0-9A-Za-z#+.:=@_-]+$", server.install_disk))
]
]))
error_message = "Bare metal server install_disk values must be disk IDs from /dev/disk/by-id and match ^[0-9A-Za-z#+.:=@_-]+$."
}
validation {
condition = alltrue(flatten([
for np in var.bare_metal_nodepools : [
for server in np.servers : try(cidrcontains(local.network_bare_metal_shared_ipv4_cidr, server.private_ipv4), false)
]
]))
error_message = "Bare metal server private_ipv4 values must be inside the shared bare metal subnet."
}
validation {
condition = alltrue(flatten([
for np in var.bare_metal_nodepools : [
for server in np.servers : !contains([
cidrhost(local.network_bare_metal_shared_ipv4_cidr, 0),
cidrhost(local.network_bare_metal_shared_ipv4_cidr, 1),
cidrhost(local.network_bare_metal_shared_ipv4_cidr, -1)
], server.private_ipv4)
]
]))
error_message = "Bare metal server private_ipv4 values must not use the network address, the first usable IP reserved as the vSwitch gateway, or the broadcast address of the shared bare metal subnet."
}
validation {
condition = alltrue([
for np in var.bare_metal_nodepools : length(var.cluster_name) + length(np.name) <= 56
])
error_message = "The combined length of the cluster name and any bare metal nodepool name must not exceed 56 characters."
}
validation {
condition = alltrue([
for np in var.bare_metal_nodepools : np.rdns == null || can(regex("^(?:(?:[a-z0-9{} ](?:[a-z0-9-{} ]{0,61}[a-z0-9{} ])?\\.)*(?:[a-z0-9{} ](?:[a-z0-9-{} ]{0,61}[a-z0-9{} ])?))$", np.rdns))
])
error_message = "The reverse DNS domain must be a valid domain: each segment must start and end with a letter or number, can contain hyphens, and each segment must be no longer than 63 characters. Supports dynamic substitution with placeholders: {{ cluster-domain }}, {{ cluster-name }}, {{ hostname }}, {{ id }}, {{ ip-labels }}, {{ ip-type }}, {{ pool }}, {{ role }}."
}
validation {
condition = alltrue([
for np in var.bare_metal_nodepools : np.rdns_ipv4 == null || can(regex("^(?:(?:[a-z0-9{} ](?:[a-z0-9-{} ]{0,61}[a-z0-9{} ])?\\.)*(?:[a-z0-9{} ](?:[a-z0-9-{} ]{0,61}[a-z0-9{} ])?))$", np.rdns_ipv4))
])
error_message = "The rdns_ipv4 must be a valid IPv4 reverse DNS domain: each segment must start and end with a letter or number, can contain hyphens, and each segment must be no longer than 63 characters. Supports dynamic substitution with placeholders: {{ cluster-domain }}, {{ cluster-name }}, {{ hostname }}, {{ id }}, {{ ip-labels }}, {{ ip-type }}, {{ pool }}, {{ role }}."
}
validation {
condition = alltrue([
for np in var.bare_metal_nodepools : np.rdns_ipv6 == null || can(regex("^(?:(?:[a-z0-9{} ](?:[a-z0-9-{} ]{0,61}[a-z0-9{} ])?\\.)*(?:[a-z0-9{} ](?:[a-z0-9-{} ]{0,61}[a-z0-9{} ])?))$", np.rdns_ipv6))
])
error_message = "The rdns_ipv6 must be a valid IPv6 reverse DNS domain: each segment must start and end with a letter or number, can contain hyphens, and each segment must be no longer than 63 characters. Supports dynamic substitution with placeholders: {{ cluster-domain }}, {{ cluster-name }}, {{ hostname }}, {{ id }}, {{ ip-labels }}, {{ ip-type }}, {{ pool }}, {{ role }}."
}
}
# Cluster Autoscaler
variable "cluster_autoscaler_helm_repository" {
type = string
default = "https://kubernetes.github.io/autoscaler"
description = "URL of the Helm repository where the Cluster Autoscaler chart is located."
}
variable "cluster_autoscaler_helm_chart" {
type = string
default = "cluster-autoscaler"
description = "Name of the Helm chart used for deploying Cluster Autoscaler."
}
variable "cluster_autoscaler_helm_version" {
type = string
default = "9.53.0"
description = "Version of the Cluster Autoscaler Helm chart to deploy."
}
variable "cluster_autoscaler_helm_values" {
type = any
default = {}
description = "Custom Helm values for the Cluster Autoscaler chart deployment. These values will merge with and will override the default values provided by the Cluster Autoscaler Helm chart."
}
variable "cluster_autoscaler_enabled" {
type = bool
default = false
description = "Enables the Cluster Autoscaler deployment."
}
variable "cluster_autoscaler_image_tag" {
type = string
default = "v1.34.5"
description = "Version of the Cluster Autoscaler Image."
}
variable "cluster_autoscaler_nodepools" {
type = list(object({
name = string
location = string
type = string
labels = optional(map(string), {})
annotations = optional(map(string), {})
taints = optional(list(string), [])
subnet = optional(string)
min = optional(number, 0)
max = number
}))
default = []
description = "Defines configuration settings for Autoscaler node pools within the cluster."
validation {
condition = var.cluster_autoscaler_enabled || length(var.cluster_autoscaler_nodepools) == 0
error_message = "cluster_autoscaler_enabled must be true when cluster_autoscaler_nodepools are configured."
}
validation {
condition = length(var.cluster_autoscaler_nodepools) == length(distinct([for np in var.cluster_autoscaler_nodepools : np.name]))
error_message = "Autoscaler nodepool names must be unique to avoid configuration conflicts."
}
validation {
condition = alltrue([
for np in var.cluster_autoscaler_nodepools : np.max >= coalesce(np.min, 0)
])
error_message = "Max size of a nodepool must be greater than or equal to its Min size."
}
validation {
condition = length([
for np in var.cluster_autoscaler_nodepools : np.subnet if np.subnet != null
]) == length(distinct([
for np in var.cluster_autoscaler_nodepools : np.subnet if np.subnet != null
]))
error_message = "Cluster Autoscaler nodepool subnets must be unique."
}
validation {
condition = alltrue([
for np in var.cluster_autoscaler_nodepools : np.subnet == null || contains(local.network_pinned_worker_ipv4_cidrs, np.subnet)
])
error_message = "Cluster Autoscaler nodepool subnet must be one of the calculated pinned worker subnets."
}
validation {
condition = alltrue([
for np in var.cluster_autoscaler_nodepools : np.subnet == null || !contains([
for worker_nodepool in var.worker_nodepools : worker_nodepool.subnet
], np.subnet)
])
error_message = "Cluster Autoscaler nodepool subnets must not be used by Worker nodepools."
}
validation {
condition = alltrue([
for np in var.cluster_autoscaler_nodepools : contains([
"fsn1", "nbg1", "hel1", "ash", "hil", "sin"
], np.location)
])
error_message = "Each nodepool location must be one of: 'fsn1' (Falkenstein), 'nbg1' (Nuremberg), 'hel1' (Helsinki), 'ash' (Ashburn), 'hil' (Hillsboro), 'sin' (Singapore)."
}
validation {
condition = alltrue([
for np in var.cluster_autoscaler_nodepools : length(var.cluster_name) + length(np.name) <= 56
])
error_message = "The combined length of the cluster name and any Cluster Autoscaler nodepool name must not exceed 56 characters."
}
}
variable "cluster_autoscaler_config_patches" {
type = any
default = []
description = "List of configuration patches applied to the Cluster Autoscaler nodes."
}
variable "cluster_autoscaler_discovery_enabled" {
type = bool
default = true
description = "Enable rolling upgrades of Cluster Autoscaler nodes during Talos OS upgrades and Talos configuration changes."
}
variable "cluster_autoscaler_cleanup_enabled" {
type = bool
default = false
description = "Enables cleanup of Hetzner Cloud servers created by Cluster Autoscaler during Terraform destroy. When enabled, matching autoscaler nodes are deleted before managed cluster resources are removed. Warning: disable this option before changing hcloud_token; otherwise Terraform may delete all Cluster Autoscaler nodes."
}
# Packer
variable "packer_amd64_builder" {
type = object({
server_type = optional(string, "cpx11")
server_location = optional(string, "ash")
})
default = {}
description = "Configuration for the server used when building the Talos AMD64 image with Packer."
validation {
condition = contains([
"fsn1", "nbg1", "hel1", "ash", "hil", "sin"
], var.packer_amd64_builder.server_location)
error_message = "The server_location must be one of: 'fsn1' (Falkenstein), 'nbg1' (Nuremberg), 'hel1' (Helsinki), 'ash' (Ashburn), 'hil' (Hillsboro), 'sin' (Singapore)."
}
}
variable "packer_arm64_builder" {
type = object({
server_type = optional(string, "cax11")
server_location = optional(string, "nbg1")
})
default = {}
description = "Configuration for the server used when building the Talos ARM64 image with Packer."
validation {
condition = contains([
"fsn1", "nbg1", "hel1", "ash", "hil", "sin"
], var.packer_arm64_builder.server_location)
error_message = "The server_location must be one of: 'fsn1' (Falkenstein), 'nbg1' (Nuremberg), 'hel1' (Helsinki), 'ash' (Ashburn), 'hil' (Hillsboro), 'sin' (Singapore)."
}
}
variable "talos_cloud_amd64_image_build_enabled" {
type = bool
default = true
description = "Controls whether the module builds a missing Talos AMD64 cloud image with Packer. Disable this only when a suitable snapshot already exists in the Hetzner Cloud project."
}
variable "talos_cloud_amd64_image_selector" {
type = string
default = "exact"
description = "Selects the Talos AMD64 cloud image. 'exact' requires labels matching the cluster, Talos version, and schematic ID. WARNING: 'latest' selects the newest image for the cluster and architecture without matching the Talos version or schematic ID. It is strongly discouraged, entirely unsupported, and not an officially supported mechanism."
validation {
condition = contains(["exact", "latest"], var.talos_cloud_amd64_image_selector)
error_message = "The talos_cloud_amd64_image_selector value must be one of: 'exact' or 'latest'."
}
}
variable "talos_cloud_arm64_image_build_enabled" {
type = bool
default = true
description = "Controls whether the module builds a missing Talos ARM64 cloud image with Packer. Disable this only when a suitable snapshot already exists in the Hetzner Cloud project."
}
variable "talos_cloud_arm64_image_selector" {
type = string
default = "exact"
description = "Selects the Talos ARM64 cloud image. 'exact' requires labels matching the cluster, Talos version, and schematic ID. WARNING: 'latest' selects the newest image for the cluster and architecture without matching the Talos version or schematic ID. It is strongly discouraged, entirely unsupported, and not an officially supported mechanism."
validation {
condition = contains(["exact", "latest"], var.talos_cloud_arm64_image_selector)
error_message = "The talos_cloud_arm64_image_selector value must be one of: 'exact' or 'latest'."
}
}
# Talos
variable "talos_version" {
type = string
default = "v1.13.9" # https://github.com/siderolabs/talos
description = "Specifies the version of Talos to be used in generated machine configurations."
}
variable "talos_schematic_id" {
type = string
default = null
description = "Specifies the Talos schematic ID used for selecting cloud image and installer versions. Bare metal servers always use generated metal schematics because their initial network configuration is server-specific. This has precedence over `talos_image_extensions` for cloud servers."
}
variable "talos_image_extensions" {
type = list(string)
default = []
description = "Specifies Talos image extensions for additional functionality on top of the default Talos Linux capabilities. See: https://github.com/siderolabs/extensions"
}
variable "talos_upgrade_debug" {
type = bool
default = false
description = "Enable debug operation from kernel logs during Talos upgrades. When true, --wait is set to true by talosctl."
}
variable "talos_upgrade_force" {
type = bool
default = false
description = "Force the Talos upgrade by skipping etcd health and member checks."
}
variable "talos_upgrade_insecure" {
type = bool
default = false
description = "Upgrade using the insecure (no auth) maintenance service."
}
variable "talos_upgrade_reboot_mode" {
type = string
default = null
description = "Select the reboot mode during upgrade. Mode \"powercycle\" bypasses kexec. Valid values: \"default\" or \"powercycle\"."
validation {
condition = var.talos_upgrade_reboot_mode == null || contains(["default", "powercycle"], var.talos_upgrade_reboot_mode)
error_message = "The talos_upgrade_reboot_mode must be \"default\" or \"powercycle\"."
}
}
variable "talos_reboot_debug" {
type = bool
default = false
description = "Enable debug operation from kernel logs during Talos reboots. When true, --wait is set to true by talosctl."
}
variable "talos_reboot_mode" {
type = string
default = null
description = "Select the reboot mode. Mode \"powercycle\" bypasses kexec, and mode \"force\" skips graceful teardown. Valid values: \"default\", \"powercycle\", or \"force\"."
validation {
condition = var.talos_reboot_mode == null || contains(["default", "powercycle", "force"], var.talos_reboot_mode)
error_message = "The talos_reboot_mode must be \"default\", \"powercycle\", or \"force\"."
}
}
variable "talos_upgrade_stage" {
type = bool
default = false
description = "Stage the Talos upgrade to perform it after a reboot."
}
variable "talos_discovery_kubernetes_enabled" {
type = bool
default = false
description = "Enable or disable Kubernetes-based Talos discovery service. Deprecated as of Kubernetes v1.32, where the AuthorizeNodeWithSelectors feature gate is enabled by default."
}
variable "talos_discovery_service_enabled" {
type = bool
default = true
description = "Enable or disable Sidero Labs public Talos discovery service."
}
variable "talos_cri_discard_unpacked_layers" {
type = bool
default = true
description = "Determines whether containerd discards unpacked image layers on all Talos nodes. Set to false to retain unpacked image layers. Attention: Changing this value forces all Talos nodes to reboot and should be performed with `talos_machine_configuration_apply_mode = \"staged\"`."
}
variable "talos_kubelet_extra_mounts" {
type = list(object({
source = string
destination = optional(string)
type = optional(string, "bind")
options = optional(list(string), ["bind", "rshared", "rw"])
}))
default = []
description = "Defines extra kubelet mounts for Talos with configurable 'source', 'destination' (defaults to 'source' if unset), 'type' (defaults to 'bind'), and 'options' (defaults to ['bind', 'rshared', 'rw'])"
validation {
condition = (
length(var.talos_kubelet_extra_mounts) ==
length(toset([for mount in var.talos_kubelet_extra_mounts : coalesce(mount.destination, mount.source)])) &&
(!var.longhorn_enabled || !contains([for mount in var.talos_kubelet_extra_mounts : coalesce(mount.destination, mount.source)], "/var/lib/longhorn"))
)
error_message = "Each destination in talos_kubelet_extra_mounts must be unique and cannot include the Longhorn default data path if Longhorn is enabled."
}
}
variable "talos_extra_kernel_args" {
type = list(string)
default = []
description = "Defines a list of extra kernel commandline parameters."
}
variable "talos_kernel_modules" {
type = list(object({
name = string
parameters = optional(list(string))
}))
default = null
description = "Defines a list of kernel modules to be loaded during system boot, along with optional parameters for each module. This allows for customized kernel behavior in the Talos environment."
}
variable "talos_machine_configuration_apply_mode" {
type = string
default = "auto"
description = "Determines how changes to Talos machine configurations are applied. 'auto' (default) applies changes immediately and reboots if necessary. 'reboot' applies changes and then reboots the node. 'no_reboot' applies changes immediately without a reboot, failing if a reboot is required. 'staged' stages changes to apply on the next reboot. 'staged_if_needing_reboot' performs a dry-run and uses 'staged' mode if reboot is needed, 'auto' otherwise."
validation {
condition = contains(["auto", "reboot", "no_reboot", "staged", "staged_if_needing_reboot"], var.talos_machine_configuration_apply_mode)
error_message = "The talos_machine_configuration_apply_mode must be 'auto', 'reboot', 'no_reboot', 'staged', or 'staged_if_needing_reboot'."
}
}
variable "talos_staged_configuration_automatic_reboot_enabled" {
type = bool
default = true
description = "Determines whether nodes are rebooted automatically after Talos machine configuration changes are applied in 'staged' mode, or when 'staged_if_needing_reboot' resolves to 'staged' mode."
}
variable "talos_sysctls_extra_args" {
type = map(string)
default = {}
description = "Specifies a map of sysctl key-value pairs for configuring additional kernel parameters. These settings allow for detailed customization of the operating system's behavior at runtime."
}
variable "talos_state_partition_encryption_enabled" {
type = bool
default = true
description = "Enables or disables encryption for the state (`/system/state`) partition. Attention: Changing this value for an existing cluster requires manual actions as per Talos documentation (https://www.talos.dev/latest/talos-guides/configuration/disk-encryption). Ignoring this may break your cluster."
}
variable "talos_ephemeral_partition_encryption_enabled" {
type = bool
default = true
description = "Enables or disables encryption for the ephemeral (`/var`) partition. Attention: Changing this value for an existing cluster requires manual actions as per Talos documentation (https://www.talos.dev/latest/talos-guides/configuration/disk-encryption). Ignoring this may break your cluster."
}
variable "talos_ipv6_enabled" {
type = bool
default = true
description = "Determines whether IPv6 is enabled for the Talos operating system. Enabling this setting configures the Talos OS to support IPv6 networking capabilities."
}
variable "talos_public_ipv4_enabled" {
type = bool
default = true
description = "Determines whether public IPv4 addresses are enabled for nodes the cluster. If true, each node is assigned a public IPv4 address."
}
variable "talos_public_ipv6_enabled" {
type = bool
default = true
description = "Determines whether public IPv6 addresses are enabled for nodes in the cluster. If true, each node is assigned a public IPv4 address."
}
variable "talos_extra_routes" {
type = list(string)
default = []
description = "Specifies CIDR blocks to be added as extra routes for the internal network interface, using the Hetzner router (first usable IP in the network) as the gateway."
validation {
condition = alltrue([for cidr in var.talos_extra_routes : can(regex("^(?:[0-9]{1,3}\\.){3}[0-9]{1,3}/[0-9]{1,2}$", cidr))])
error_message = "All entries in extra_routes must be valid CIDR notations."
}
}
variable "talos_certificates" {
type = any
default = {}
description = <<-EOF
Additional trusted CA certificates to be added to the Talos configuration.
Map keys are used as names for the TrustedRootsConfig documents.
Values can be either a single PEM-encoded string containing one or more certificates (inline or from file), or a list of PEM-encoded strings.
Example:
```hcl
talos_certificates = {
# Inline string (single certificate)
"inline-ca" = "-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----"
# Single certificate from file
"file-ca" = [file("ca.crt")]
# Multiple certificates from files (chain)
"corporate-chain" = [file("root.crt"), file("intermediate.crt")]
# Multiple inline certificates in a single string (backward compatible)
"legacy-ca" = <<-EOT
-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----
-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----
EOT