-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.tf
97 lines (80 loc) · 2.61 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
# Computed variables
locals {
validity_period = 2562047
region_suffix = "${var.region}.brightbox.com"
template_path = "${path.root}/templates"
service_cidr = "172.30.0.0/16,fd00:ac1e::/112"
cluster_cidr = "192.168.0.0/16,fd00:c0a8::/48"
cluster_fqdn = "${var.cluster_name}.${var.cluster_domainname}"
service_port = "6443"
worker_node_ids = module.k8s_worker.servers[*].id
storage_node_ids = module.k8s_storage.servers[*].id
worker_label_script = <<EOT
%{if var.worker_count != 0~}
kubectl label --overwrite ${join(" ", formatlist("node/%s", local.worker_node_ids))} 'node-role.kubernetes.io/worker=' 'node-role.kubernetes.io/storage-'
%{~endif}
EOT
storage_label_script = <<EOT
%{if var.storage_count != 0~}
kubectl label --overwrite ${join(" ", formatlist("node/%s", local.storage_node_ids))} 'node-role.kubernetes.io/storage=' 'node-role.kubernetes.io/worker-'
%{~endif}
EOT
disable_scale_down_script = <<EOT
kubectl annotate --overwrite -l node-role.kubernetes.io/worker nodes cluster-autoscaler.kubernetes.io/scale-down-disabled=true
kubectl annotate --overwrite -l node-role.kubernetes.io/storage nodes cluster-autoscaler.kubernetes.io/scale-down-disabled=true
EOT
}
resource "null_resource" "spread_deployments" {
depends_on = [
module.k8s_worker,
module.k8s_storage,
module.k8s_master,
]
connection {
user = module.k8s_master.bastion_user
host = module.k8s_master.bastion
}
provisioner "remote-exec" {
script = "${local.template_path}/spread-deployments"
}
}
resource "null_resource" "label_nodes" {
depends_on = [
module.k8s_worker,
module.k8s_storage,
module.k8s_master,
]
triggers = {
worker_script = local.worker_label_script
storage_script = local.storage_label_script
disable_script = local.disable_scale_down_script
}
connection {
user = module.k8s_master.bastion_user
host = module.k8s_master.bastion
}
provisioner "remote-exec" {
inline = [
local.worker_label_script,
local.storage_label_script,
local.disable_scale_down_script,
]
}
}
resource "tls_private_key" "k8s_ca" {
algorithm = "RSA"
}
resource "tls_self_signed_cert" "k8s_ca" {
private_key_pem = tls_private_key.k8s_ca.private_key_pem
subject {
common_name = "apiserver"
organizational_unit = local.cluster_fqdn
}
validity_period_hours = local.validity_period
allowed_uses = [
"key_encipherment",
"digital_signature",
"cert_signing",
]
is_ca_certificate = true
}