forked from fvumbaca/terraform-proxmox-k3s
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsupport_node.tf
160 lines (122 loc) · 3.41 KB
/
support_node.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
resource "macaddress" "k3s-support" {}
locals {
support_node_settings = defaults(var.support_node_settings, {
cores = 2
sockets = 1
memory = 4096
storage_type = "scsi"
storage_id = "local-lvm"
disk_size = "10G"
user = "support"
network_tag = -1
db_name = "k3s"
db_user = "k3s"
network_bridge = "vmbr0"
})
support_node_ip = cidrhost(var.control_plane_subnet, 0)
}
locals {
lan_subnet_cidr_bitnum = split("/", var.lan_subnet)[1]
}
resource "proxmox_vm_qemu" "k3s-support" {
target_node = var.proxmox_node
name = join("-", [var.cluster_name, "support"])
clone = var.node_template
pool = var.proxmox_resource_pool
# cores = 2
cores = local.support_node_settings.cores
sockets = local.support_node_settings.sockets
memory = local.support_node_settings.memory
agent = 1
disk {
type = local.support_node_settings.storage_type
storage = local.support_node_settings.storage_id
size = local.support_node_settings.disk_size
}
network {
bridge = local.support_node_settings.network_bridge
firewall = true
link_down = false
macaddr = upper(macaddress.k3s-support.address)
model = "virtio"
queues = 0
rate = 0
tag = local.support_node_settings.network_tag
}
lifecycle {
ignore_changes = [
ciuser,
sshkeys,
disk,
network
]
}
os_type = "cloud-init"
ciuser = local.support_node_settings.user
ipconfig0 = "ip=${local.support_node_ip}/${local.lan_subnet_cidr_bitnum},gw=${var.network_gateway}"
sshkeys = file(var.authorized_keys_file)
nameserver = var.nameserver
connection {
type = "ssh"
user = local.support_node_settings.user
host = local.support_node_ip
}
provisioner "file" {
destination = "/tmp/install.sh"
content = templatefile("${path.module}/scripts/install-support-apps.sh.tftpl", {
root_password = random_password.support-db-password.result
k3s_database = local.support_node_settings.db_name
k3s_user = local.support_node_settings.db_user
k3s_password = random_password.k3s-master-db-password.result
http_proxy = var.http_proxy
})
}
provisioner "remote-exec" {
inline = [
"chmod u+x /tmp/install.sh",
"/tmp/install.sh",
"rm -r /tmp/install.sh",
]
}
}
resource "random_password" "support-db-password" {
length = 16
special = false
override_special = "_%@"
}
resource "random_password" "k3s-master-db-password" {
length = 16
special = false
override_special = "_%@"
}
resource "null_resource" "k3s_nginx_config" {
depends_on = [
proxmox_vm_qemu.k3s-support
]
triggers = {
config_change = filemd5("${path.module}/config/nginx.conf.tftpl")
}
connection {
type = "ssh"
user = local.support_node_settings.user
host = local.support_node_ip
}
provisioner "file" {
destination = "/tmp/nginx.conf"
content = templatefile("${path.module}/config/nginx.conf.tftpl", {
k3s_server_hosts = [for ip in local.master_node_ips :
"${ip}:6443"
]
k3s_nodes = concat(local.master_node_ips, [
for node in local.listed_worker_nodes :
node.ip
])
})
}
provisioner "remote-exec" {
inline = [
"sudo mv /tmp/nginx.conf /etc/nginx/nginx.conf",
"sudo systemctl restart nginx.service",
]
}
}