# ============ Deployment of the K8s cluster ============== # = by Sebastian Gurlin for Undercloud = # ========================================================= 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" } } # ============ Download Flatcar QCOW ============== resource "proxmox_virtual_environment_download_file" "flatcar_image" { content_type = "import" datastore_id = "cephfs" # oder dein ISO-Storage node_name = "hyper1" url = "http://git.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 = false pretty_print = true } data "ct_config" "control_plane2_ignition" { content = file("${path.module}/control-plane2.bu") strict = false pretty_print = true } data "ct_config" "control_plane3_ignition" { content = file("${path.module}/control-plane3.bu") strict = false pretty_print = true } data "ct_config" "worker1_ignition" { content = file("${path.module}/worker1.bu") strict = false pretty_print = true } data "ct_config" "worker2_ignition" { content = file("${path.module}/worker2.bu") strict = false pretty_print = true } data "ct_config" "worker3_ignition" { content = file("${path.module}/worker3.bu") strict = false pretty_print = true } data "ct_config" "worker4_ignition" { content = file("${path.module}/worker4.bu") strict = false 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" } } resource "proxmox_virtual_environment_file" "worker4_ignition" { content_type = "snippets" datastore_id = "cephfs" # dein Storage node_name = "hyper1" # oder einer deiner Cluster-Nodes source_raw { data = data.ct_config.worker4_ignition.rendered file_name = "worker4-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" tags = ["flatcar","kubernetes","terraform"] lifecycle { ignore_changes = [ boot_order, disk, # ignore disk drift like ssd flag ] } agent { enabled = true } cpu { type = "host" 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 = 50 cache = "writeback" ssd = true } # Cloud-Init Laufwerk hinzufügen initialization { datastore_id = "Pool1" } boot_order = ["virtio0", "ide2"] } resource "null_resource" "wait_for_cp1_api" { depends_on = [proxmox_virtual_environment_vm.control_plane1] provisioner "local-exec" { interpreter = ["/bin/bash", "-lc"] environment = { CP1 = "control-plane1.undercloud.local" # <-- set this } command = <