373 lines
9.2 KiB
HCL
373 lines
9.2 KiB
HCL
terraform {
|
|
required_providers {
|
|
proxmox = {
|
|
source = "bpg/proxmox"
|
|
version = ">=0.35.0"
|
|
}
|
|
ct = {
|
|
source = "poseidon/ct"
|
|
version = ">=0.13.0"
|
|
}
|
|
}
|
|
}
|
|
|
|
provider "proxmox" {
|
|
endpoint = "https://hyper1.undercloud.local:8006/api2/json"
|
|
api_token = "terraform@pve!terraform=5c2ec60a-5605-45cc-bffd-223eb2c487ef"
|
|
insecure = true
|
|
|
|
ssh {
|
|
agent = true
|
|
username = "root"
|
|
}
|
|
}
|
|
|
|
resource "proxmox_virtual_environment_download_file" "flatcar_image" {
|
|
content_type = "import"
|
|
datastore_id = "cephfs" # oder dein ISO-Storage
|
|
node_name = "hyper1"
|
|
|
|
url = "http://build-node.undercloud.local:3000/admin/undercloud-infrastructure/raw/branch/main/iso/flatcar_production_proxmoxve_image.img"
|
|
file_name = "flatcar_production_proxmoxve_image.qcow2" # wird als ISO gespeichert
|
|
}
|
|
|
|
# --- Butane zu Ignition ---
|
|
data "ct_config" "control_plane1_ignition" {
|
|
content = file("${path.module}/control-plane1.bu")
|
|
strict = true
|
|
pretty_print = true
|
|
}
|
|
data "ct_config" "control_plane2_ignition" {
|
|
content = file("${path.module}/control-plane2.bu")
|
|
strict = true
|
|
pretty_print = true
|
|
}
|
|
data "ct_config" "control_plane3_ignition" {
|
|
content = file("${path.module}/control-plane3.bu")
|
|
strict = true
|
|
pretty_print = true
|
|
}
|
|
data "ct_config" "worker1_ignition" {
|
|
content = file("${path.module}/worker1.bu")
|
|
strict = true
|
|
pretty_print = true
|
|
}
|
|
data "ct_config" "worker2_ignition" {
|
|
content = file("${path.module}/worker2.bu")
|
|
strict = true
|
|
pretty_print = true
|
|
}
|
|
data "ct_config" "worker3_ignition" {
|
|
content = file("${path.module}/worker3.bu")
|
|
strict = true
|
|
pretty_print = true
|
|
}
|
|
|
|
resource "proxmox_virtual_environment_file" "control_plane1_ignition" {
|
|
content_type = "snippets"
|
|
datastore_id = "cephfs" # dein Storage
|
|
node_name = "hyper1" # oder einer deiner Cluster-Nodes
|
|
source_raw {
|
|
data = data.ct_config.control_plane1_ignition.rendered
|
|
file_name = "control-plane1-ignition-user-data"
|
|
}
|
|
}
|
|
resource "proxmox_virtual_environment_file" "control_plane2_ignition" {
|
|
content_type = "snippets"
|
|
datastore_id = "cephfs" # dein Storage
|
|
node_name = "hyper1" # oder einer deiner Cluster-Nodes
|
|
source_raw {
|
|
data = data.ct_config.control_plane2_ignition.rendered
|
|
file_name = "control-plane2-ignition-user-data"
|
|
}
|
|
}
|
|
resource "proxmox_virtual_environment_file" "control_plane3_ignition" {
|
|
content_type = "snippets"
|
|
datastore_id = "cephfs" # dein Storage
|
|
node_name = "hyper1" # oder einer deiner Cluster-Nodes
|
|
source_raw {
|
|
data = data.ct_config.control_plane3_ignition.rendered
|
|
file_name = "control-plane3-ignition-user-data"
|
|
}
|
|
}
|
|
resource "proxmox_virtual_environment_file" "worker1_ignition" {
|
|
content_type = "snippets"
|
|
datastore_id = "cephfs" # dein Storage
|
|
node_name = "hyper1" # oder einer deiner Cluster-Nodes
|
|
source_raw {
|
|
data = data.ct_config.worker1_ignition.rendered
|
|
file_name = "worker1-ignition-user-data"
|
|
}
|
|
}
|
|
resource "proxmox_virtual_environment_file" "worker2_ignition" {
|
|
content_type = "snippets"
|
|
datastore_id = "cephfs" # dein Storage
|
|
node_name = "hyper1" # oder einer deiner Cluster-Nodes
|
|
source_raw {
|
|
data = data.ct_config.worker2_ignition.rendered
|
|
file_name = "worker2-ignition-user-data"
|
|
}
|
|
}
|
|
resource "proxmox_virtual_environment_file" "worker3_ignition" {
|
|
content_type = "snippets"
|
|
datastore_id = "cephfs" # dein Storage
|
|
node_name = "hyper1" # oder einer deiner Cluster-Nodes
|
|
source_raw {
|
|
data = data.ct_config.worker3_ignition.rendered
|
|
file_name = "worker3-ignition-user-data"
|
|
}
|
|
}
|
|
|
|
# --- flatcar template anlegen ---
|
|
resource "proxmox_virtual_environment_vm" "flatcar_template" {
|
|
name = "flatcar-template"
|
|
node_name = "hyper1"
|
|
template = true
|
|
started = false
|
|
stop_on_destroy = true
|
|
description = "managed by terraform - base template for flatcar"
|
|
|
|
cpu {
|
|
cores = 1
|
|
}
|
|
|
|
memory {
|
|
dedicated = 2048
|
|
floating = 2048
|
|
}
|
|
|
|
network_device {
|
|
bridge = "vmbr0"
|
|
model = "virtio"
|
|
}
|
|
|
|
# Bootdisk direkt aus dem QCOW2
|
|
disk {
|
|
datastore_id = "Pool1"
|
|
import_from = proxmox_virtual_environment_download_file.flatcar_image.id
|
|
interface = "virtio0"
|
|
discard = "on"
|
|
size = 10
|
|
}
|
|
|
|
# Cloud-Init Laufwerk hinzufügen
|
|
initialization {
|
|
datastore_id = "Pool1"
|
|
}
|
|
|
|
|
|
boot_order = ["scsi0", "ide2"]
|
|
|
|
lifecycle {
|
|
ignore_changes = [boot_order]
|
|
}
|
|
|
|
tags = ["flatcar","kubernetes","terraform"]
|
|
}
|
|
|
|
# --- control planes anlegen ---
|
|
resource "proxmox_virtual_environment_vm" "control_plane1" {
|
|
name = "control-plane1"
|
|
node_name = "hyper1"
|
|
description = "kubernetes control-plane1"
|
|
|
|
# Hardware
|
|
cpu {
|
|
cores = 2
|
|
}
|
|
memory {
|
|
dedicated = 2048
|
|
floating = 2048
|
|
}
|
|
|
|
# Netzwerk
|
|
network_device {
|
|
bridge = "vmbr0"
|
|
model = "virtio"
|
|
}
|
|
|
|
# Disk (Template klonen oder QCOW2 angeben)
|
|
clone {
|
|
vm_id = proxmox_virtual_environment_vm.flatcar_template.id
|
|
full = true
|
|
node_name = "hyper1"
|
|
}
|
|
|
|
# Ignition-Config
|
|
initialization {
|
|
user_data_file_id = "${proxmox_virtual_environment_file.control_plane1_ignition.id}"
|
|
}
|
|
tags = ["control-plane","flatcar","kubernetes","terraform"]
|
|
depends_on = [proxmox_virtual_environment_file.control_plane1_ignition]
|
|
}
|
|
resource "proxmox_virtual_environment_vm" "control_plane2" {
|
|
name = "control-plane2"
|
|
node_name = "hyper2"
|
|
description = "kubernetes control-plane2"
|
|
|
|
# Hardware
|
|
cpu {
|
|
cores = 2
|
|
}
|
|
memory {
|
|
dedicated = 2048
|
|
floating = 2048
|
|
}
|
|
|
|
# Netzwerk
|
|
network_device {
|
|
bridge = "vmbr0"
|
|
model = "virtio"
|
|
}
|
|
|
|
# Disk (Template klonen oder QCOW2 angeben)
|
|
clone {
|
|
vm_id = proxmox_virtual_environment_vm.flatcar_template.id
|
|
full = true
|
|
node_name = "hyper1"
|
|
}
|
|
|
|
# Ignition-Config
|
|
initialization {
|
|
user_data_file_id = "${proxmox_virtual_environment_file.control_plane2_ignition.id}"
|
|
}
|
|
tags = ["control-plane","flatcar","kubernetes","terraform"]
|
|
depends_on = [proxmox_virtual_environment_file.control_plane2_ignition]
|
|
}
|
|
resource "proxmox_virtual_environment_vm" "control_plane3" {
|
|
name = "control-plane3"
|
|
node_name = "hyper3"
|
|
description = "kubernetes control-plane3"
|
|
|
|
# Hardware
|
|
cpu {
|
|
cores = 2
|
|
}
|
|
memory {
|
|
dedicated = 2048
|
|
floating = 2048
|
|
}
|
|
|
|
# Netzwerk
|
|
network_device {
|
|
bridge = "vmbr0"
|
|
model = "virtio"
|
|
}
|
|
|
|
# Disk (Template klonen oder QCOW2 angeben)
|
|
clone {
|
|
vm_id = proxmox_virtual_environment_vm.flatcar_template.id
|
|
full = true
|
|
node_name = "hyper1"
|
|
}
|
|
|
|
# Ignition-Config
|
|
initialization {
|
|
user_data_file_id = "${proxmox_virtual_environment_file.control_plane3_ignition.id}"
|
|
}
|
|
tags = ["control-plane","flatcar","kubernetes","terraform"]
|
|
depends_on = [proxmox_virtual_environment_file.control_plane3_ignition]
|
|
}
|
|
resource "proxmox_virtual_environment_vm" "worker1" {
|
|
name = "worker1"
|
|
node_name = "hyper1"
|
|
description = "kubernetes worker1"
|
|
|
|
# Hardware
|
|
cpu {
|
|
cores = 2
|
|
}
|
|
memory {
|
|
dedicated = 8192
|
|
floating = 8192
|
|
}
|
|
|
|
# Netzwerk
|
|
network_device {
|
|
bridge = "vmbr0"
|
|
model = "virtio"
|
|
}
|
|
|
|
# Disk (Template klonen oder QCOW2 angeben)
|
|
clone {
|
|
vm_id = proxmox_virtual_environment_vm.flatcar_template.id
|
|
full = true
|
|
node_name = "hyper1"
|
|
}
|
|
|
|
# Ignition-Config
|
|
initialization {
|
|
user_data_file_id = "${proxmox_virtual_environment_file.worker1_ignition.id}"
|
|
}
|
|
tags = ["worker","flatcar","kubernetes","terraform"]
|
|
depends_on = [proxmox_virtual_environment_file.worker1_ignition]
|
|
}
|
|
resource "proxmox_virtual_environment_vm" "worker2" {
|
|
name = "worker2"
|
|
node_name = "hyper2"
|
|
description = "kubernetes worker2"
|
|
|
|
# Hardware
|
|
cpu {
|
|
cores = 2
|
|
}
|
|
memory {
|
|
dedicated = 8192
|
|
floating = 8192
|
|
}
|
|
|
|
# Netzwerk
|
|
network_device {
|
|
bridge = "vmbr0"
|
|
model = "virtio"
|
|
}
|
|
|
|
# Disk (Template klonen oder QCOW2 angeben)
|
|
clone {
|
|
vm_id = proxmox_virtual_environment_vm.flatcar_template.id
|
|
full = true
|
|
node_name = "hyper1"
|
|
}
|
|
|
|
# Ignition-Config
|
|
initialization {
|
|
user_data_file_id = "${proxmox_virtual_environment_file.worker2_ignition.id}"
|
|
}
|
|
tags = ["worker","flatcar","kubernetes","terraform"]
|
|
depends_on = [proxmox_virtual_environment_file.worker2_ignition]
|
|
}
|
|
resource "proxmox_virtual_environment_vm" "worker3" {
|
|
name = "worker3"
|
|
node_name = "hyper3"
|
|
description = "kubernetes worker3"
|
|
|
|
# Hardware
|
|
cpu {
|
|
cores = 2
|
|
}
|
|
memory {
|
|
dedicated = 8192
|
|
floating = 8192
|
|
}
|
|
|
|
# Netzwerk
|
|
network_device {
|
|
bridge = "vmbr0"
|
|
model = "virtio"
|
|
}
|
|
|
|
# Disk (Template klonen oder QCOW2 angeben)
|
|
clone {
|
|
vm_id = proxmox_virtual_environment_vm.flatcar_template.id
|
|
full = true
|
|
node_name = "hyper1"
|
|
}
|
|
|
|
# Ignition-Config
|
|
initialization {
|
|
user_data_file_id = "${proxmox_virtual_environment_file.worker3_ignition.id}"
|
|
}
|
|
tags = ["worker","flatcar","kubernetes","terraform"]
|
|
depends_on = [proxmox_virtual_environment_file.worker3_ignition]
|
|
}
|