-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresources.tf
173 lines (154 loc) · 4.36 KB
/
resources.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
resource "tls_private_key" "private_key" {
algorithm = "RSA"
rsa_bits = 4096
}
resource "proxmox_lxc" "microk8s" {
vmid = var.vmid
target_node = var.target_node
hostname = var.node_name
ostemplate = var.ostemplate
unprivileged = false
start = false
cores = var.resources.cores
memory = var.resources.memory
onboot = true
tags = join(";", var.tags)
ssh_public_keys = join("\n", concat([tls_private_key.private_key.public_key_openssh], var.ssh_public_keys))
description = <<-EOT
## Description
MicroK8s Cluster Node
## Features
- Nesting: true
- Fuse: true
## Network
- Name: ${var.network.name}
- Bridge: ${var.network.bridge}
- IP: ${var.network.ip == "" ? "192.168.1.4${var.vmid + 1}/24" : var.network.ip}
- GW: ${var.network.gw}
- Hostname: ${var.node_name}-${var.vmid}.local
## RootFS
- Storage: ${var.rootfs.storage}
- Size: ${var.rootfs.size}
EOT
features {
nesting = true
fuse = true
}
rootfs {
storage = var.rootfs.storage
size = var.rootfs.size
}
dynamic "mountpoint" {
for_each = var.mountpoints
content {
key = tostring(mountpoint.key)
slot = mountpoint.key
storage = mountpoint.value.storage
mp = mountpoint.value.mountpoint
size = mountpoint.value.size
}
}
network {
name = var.network.name
bridge = var.network.bridge
ip = var.network.ip == "" ? "192.168.1.4${var.vmid + 1}/24" : var.network.ip
gw = var.network.gw
}
# configure LXC container
provisioner "remote-exec" {
when = create
inline = [
"pct set ${var.vmid} -swap 0",
"echo 'lxc.apparmor.profile: unconfined' >> /etc/pve/lxc/${var.vmid}.conf",
"echo 'lxc.cap.drop: ' >> /etc/pve/lxc/${var.vmid}.conf",
"echo 'lxc.mount.auto: proc:rw sys:rw' >> /etc/pve/lxc/${var.vmid}.conf",
"echo 'lxc.mount.entry: /dev/fuse dev/fuse none bind,create=file 0 0' >> /etc/pve/lxc/${var.vmid}.conf",
"echo 'lxc.mount.entry: /sys/kernel/security sys/kernel/security none bind,create=file 0 0' >> /etc/pve/lxc/${var.vmid}.conf",
"pct start ${var.vmid}",
"pct exec ${var.vmid} -- bash -c '${data.template_file.rc_local_sh.rendered}'",
"pct stop ${var.vmid}",
"pct start ${var.vmid}"
]
connection {
type = "ssh"
user = var.proxmox_ssh.username
password = var.proxmox_ssh.password
host = var.proxmox_ssh.host
}
}
# configure microk8s and addons
provisioner "remote-exec" {
when = create
inline = [
data.template_file.post_create_sh.rendered
]
connection {
type = "ssh"
user = "root"
private_key = tls_private_key.private_key.private_key_pem
host = local.host
}
}
}
resource "null_resource" "mountpoint_permission" {
count = length(var.mountpoints) > 0 ? 1 : 0
triggers = {
hash = md5(data.template_file.argocd_install.rendered),
host = local.host
}
provisioner "remote-exec" {
when = create
inline = [
for mountpoint in var.mountpoints : <<-EOT
pct exec ${var.vmid} -- bash -c "chmod 777 ${mountpoint.mountpoint}"
EOT
]
connection {
type = "ssh"
user = var.proxmox_ssh.username
password = var.proxmox_ssh.password
host = var.proxmox_ssh.host
}
}
depends_on = [
proxmox_lxc.microk8s
]
}
resource "null_resource" "argocd_install" {
count = (var.cluster_addons.argocd.enabled) ? 1 : 0
provisioner "remote-exec" {
when = create
inline = [
data.template_file.argocd_install.rendered
]
connection {
type = "ssh"
user = "root"
private_key = tls_private_key.private_key.private_key_pem
host = local.host
}
}
depends_on = [
proxmox_lxc.microk8s
]
}
resource "null_resource" "microk8s_add_node" {
count = length(var.add_cluster_nodes) > 0 ? 1 : 0
provisioner "remote-exec" {
when = create
inline = [
for token in var.add_cluster_nodes : <<-EOT
/snap/bin/${token}
EOT
]
connection {
type = "ssh"
user = "root"
private_key = tls_private_key.private_key.private_key_pem
host = local.host
}
}
depends_on = [
proxmox_lxc.microk8s
]
}