This commit is contained in:
Sivert V. Sæther 2024-10-16 11:13:28 +02:00
commit 9718b947bc
10 changed files with 208 additions and 0 deletions

5
.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
*.tfstate.backup
.terraform
*.tfstate
*.log
.env

44
.terraform.lock.hcl Normal file
View File

@ -0,0 +1,44 @@
# This file is maintained automatically by "terraform init".
# Manual edits may be lost in future updates.
provider "registry.terraform.io/hashicorp/external" {
version = "2.3.3"
constraints = "2.3.3"
hashes = [
"h1:H+3QlVPs/7CDa3I4KU/a23wYeGeJxeBlgvR7bfK1t1w=",
"zh:03d81462f9578ec91ce8e26f887e34151eda0e100f57e9772dbea86363588239",
"zh:37ec2a20f6a3ec3a0fd95d3f3de26da6cb9534b30488bc45723e118a0911c0d8",
"zh:4eb5b119179539f2749ce9de0e1b9629d025990f062f4f4dddc161562bb89d37",
"zh:5a31bb58414f41bee5e09b939012df5b88654120b0238a89dfd6691ba197619a",
"zh:6221a05e52a6a2d4f520ffe7cbc741f4f6080e0855061b0ed54e8be4a84eb9b7",
"zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3",
"zh:8bb068496b4679bef625e4710d9f3432e301c3a56602271f04e60eadf7f8a94c",
"zh:94742aa5378bab626ce34f79bcef6a373e4f86ea7a8b762e9f71270a899e0d00",
"zh:a485831b5a525cd8f40e8982fa37da40ff70b1ae092c8b755fcde123f0b1238d",
"zh:a647ff16d071eabcabd87ea8183eb90a775a0294ddd735d742075d62fff09193",
"zh:b74710c5954aaa3faf262c18d36a8c2407862d9f842c63e7fa92fa4de3d29df6",
"zh:fa73d83edc92af2e551857594c2232ba6a9e3603ad34b0a5940865202c08d8d7",
]
}
provider "registry.terraform.io/telmate/proxmox" {
version = "2.9.14"
constraints = "2.9.14"
hashes = [
"h1:H/f+LbVyPOLslHLAYnGuMMRqWFZ65K6E3V+MCYgfAyk=",
"zh:0d049d33f705e5b814d30028770c084151218439424e99684ce31d7e26a720b5",
"zh:20b1c64ed56d81de95f3f37b82b45b4654c0de26670c0e87a474c5cce13cd015",
"zh:2946058abd1d8e50e475b9ec39781eb02576b40dbd80f4653fade4493a4514c6",
"zh:29e50a25c456f040ce072f23ac57b5b82ebd3b916ca5ae6688332b5ec62adc4a",
"zh:3612932306ce5f08db94868f526cbb8c56d0d3c6ebe1c11a83f92bbf94354296",
"zh:42d1699b0abebaac82ea5a19f4393541d8bb2741bde204a8ac1028cdc29d1b14",
"zh:5ffd5dc567262eb8aafdf2f6eac63f7f21361da9c5d75a3c36b479638a0001b0",
"zh:6692ef323e3b89de99934ad731f6a1850525bf8142916ae28ea4e4048d73a787",
"zh:a5afc98e9a4038516bb58e788cb77dea67a60dce780dfcd206d7373c5a56b776",
"zh:bf902cded709d84fa27fbf91b589c241f2238a6c4924e4e479eebd74320b93a5",
"zh:cab0e1e72c9cebcf669fc6f35ec28cb8ab2dffb0237afc8860aa40d23bf8a49f",
"zh:e523b99a48beec83d9bc04b2d336266044f9f53514cefb652fe6768611847196",
"zh:f593915e8a24829d322d2eaeedcb153328cf9042f0d84f66040dde1be70ede04",
"zh:fba1aff541133e2129dfda0160369635ab48503d5c44b8407ce5922ecc15d0bd",
]
}

6
data-sources.tf Normal file
View File

@ -0,0 +1,6 @@
data "external" "master_kube" {
program = ["sh", "${path.module}/ext/name-gen.sh", "kube", "master"]
}
data "external" "worker_kube" {
program = ["sh", "${path.module}/ext/name-gen.sh", "kube", "worker"]
}

9
ext/id-gen.py Normal file
View File

@ -0,0 +1,9 @@
from json import dumps
start = 666
name = {
'name': start
}
print(dumps(name))

10
ext/name-gen.py Normal file
View File

@ -0,0 +1,10 @@
from datetime import datetime
from json import dumps
from sys import argv
name = argv[1]
type = argv[2]
timestamp = datetime.now().strftime('%d.%m.%Y-%H:%M:%S')
name = f'{name}-{type}-{timestamp}'
print(dumps({'name': name}))

2
ext/name-gen.sh Executable file
View File

@ -0,0 +1,2 @@
#/bin/sh
echo {\"name\":\"$1-$2-`date +'%d.%m.%Y-%H:%M:%S'`\"}

80
kubes.tf Normal file
View File

@ -0,0 +1,80 @@
resource "proxmox_vm_qemu" "kube-masters" {
count = var.master_count
# name = "kube-master-${count.index + 1}"
name = data.external.master_kube.result.name
vmid = var.vmid + count.index
target_node = var.proxmox_host
clone = var.template_name
sshkeys = var.ssh_keys
agent = 1
os_type = "cloud-init"
sockets = 1
cores = 1
cpu = "host"
memory = 2048
# scsihw = "virtio-scsi-pci"
bootdisk = "virtio0"
disk {
slot = 0
size = "8G"
type = "virtio"
storage = "thic"
iothread = 1
}
network {
model = "virtio"
bridge = "vmbr0"
}
lifecycle {
ignore_changes = [
network,
]
}
provisioner "remote-exec" {
inline = [
"apt update",
"apt upgrade -y"
]
}
}
resource "proxmox_vm_qemu" "kube-workers" {
count = var.worker_count
# name = "kube-worker-${count.index + 1}"
name = data.external.worker_kube.result.name
vmid = var.vmid + 100 + count.index
target_node = var.proxmox_host
clone = var.template_name
agent = 1 # QEMU Guest Agent
os_type = "cloud-init"
sockets = 1
cores = 2
cpu = "host"
memory = 4096
# scsihw = "virtio-scsi-pci"
bootdisk = "virtio0"
disk {
slot = 0
size = "8G"
type = "virtio"
storage = "thic"
iothread = 1
}
network {
model = "virtio"
bridge = "vmbr0"
}
lifecycle {
ignore_changes = [
network,
]
}
sshkeys = var.ssh_keys
provisioner "remote-exec" {
inline = [
"apt update",
"apt upgrade -y"
]
}
}

14
provider.tf Normal file
View File

@ -0,0 +1,14 @@
variable "pm_token_secret" {}
variable "pm_token_id" {}
provider "proxmox" {
pm_api_url = "https://172.31.71.69:8006/api2/json"
pm_api_token_secret = var.pm_token_secret
pm_api_token_id = var.pm_token_id
pm_tls_insecure = true
pm_parallel = 3
pm_log_enable = true
# pm_log_file = "terraform-proxmox-plugin.log"
pm_log_levels = {
_default = "info"
}
}

25
variables.tf Normal file
View File

@ -0,0 +1,25 @@
variable "master_count" {
default = 1
}
variable "worker_count" {
default = 2
}
variable "vmid" {
type = number
default = 500
}
variable "proxmox_host" {
default = "papp-bunt"
}
variable "template_name" {
default = "kube-template"
}
variable "ssh_keys" {
default = <<EOF
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDqXa9fIVrQTGV4PMTn7ZyyeTLDVC+H4kV6zJzWBGGZf6DSoumJtbTaD6Ob3Czsf/NZ35iCPy2yrar3/Z7ccDrcfpxlNvj9l3NphEdXIebyQ8VmMWBy4pDPjE1erIEaL+J5RfjidB7xauticUIuNj0vtuvum/f09vGsohys+/llU7T+M42AeCTT5omw0DD8DPIUGxFwsgg0RxtD5ol1i3v0zVqwlbc7gnHws9/JCJZrhdHZWWkqvVQLCbRRCq4ZvRBcMdwJsBOeJpM9tkeJ7peZjAnPh7EIPkWh79+S65m6bsBe9N4lX5Qf2jxMSzgGeHhfJmd5O7UVqxH1a4M10e+CZOsWdTbMFEn+pcA04gehV9mL5gazZTMSjVFRzd/NUWi0Z6kecXW0HvxWzvKs+iZgaqL7qsDQUb23nMyvtiRO7JeTfdlo/dpb3Uz12VfwcHWAw1DpyJk3Sd1xV4sLke34F67e141ed72Piig6UuX2/aXm5Due781zIS8zBKBl4vXORbGjLLBo72RctB3xU9nJmkttdeSSF/yRbY7H3+bsvno/VUSAhnYWlGNrZBc+tTtqjYEQ3k/G8I8nwO4e1GDfo6w5G9dZQQ4YyV4v41NRp0TrtuGBpvGf9anMWUcp63f+fXMOZAnSVg42oZZUYWSPQTnoY1E5I3A6K4wrqEHt4w== siv@craptop
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCTFuQdp7JJzasMztOyvATBTXCuXE8SC39K7ap0K9hwdNNDl6oeM6jSv3KiL6AFGqjWHWrwpNaAPgM7FSXz9KJDixD0gx1nxfcTcF3nmbu3pCzgqRKdYZqvBlH6C+FRBC467MTBlxm8a5Ov5bKT0diseO4mG2Av+G7917mKvcgazfI95RxlllS3tD26xIloqCDutEMRL53rkzSYdaF3RPqLr4WmF7i7zk8I7H2EmreP4ZxUXoXEIV1LbQfgDErPWUishg0ivjR3eL0mKzq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F75wMZ8HLs1iTm2kDHWSkweNsGts/YR9jFojQoZo7S5xyb/dq66xhUZIjQ== siv@proggnuc
EOF
}

13
versions.tf Normal file
View File

@ -0,0 +1,13 @@
terraform {
required_providers {
proxmox = {
source = "telmate/proxmox"
version = "2.9.14"
}
external = {
source = "hashicorp/external"
version = "2.3.3"
}
}
}