From 326572de4d0557f465006d6d566f0eefff135810 Mon Sep 17 00:00:00 2001 From: Iurii Anfinogenov Date: Mon, 4 May 2026 06:30:51 +0000 Subject: [PATCH] add rocky image --- cluster/cloud-config/rocky.yml | 16 ++----- cluster/locals.tf | 79 +++++++++++++++++----------------- modules/node/main.tf | 17 +++++++- modules/node/variables.tf | 1 + 4 files changed, 60 insertions(+), 53 deletions(-) diff --git a/cluster/cloud-config/rocky.yml b/cluster/cloud-config/rocky.yml index 0a31466..7309db3 100644 --- a/cluster/cloud-config/rocky.yml +++ b/cluster/cloud-config/rocky.yml @@ -2,11 +2,11 @@ timezone: Europe/Moscow users: - - name: rocky + - name: iurii groups: [wheel] shell: /bin/bash lock_passwd: false - passwd: "$6$M8xzsYT0lwWjlcdH$HJRhw0rBb2WowCbqg03/WvMUlte0j5SLs9tAVCxCukEqWAt7XG0ceWYc5GRUBmRxFRTbcEDrdCVTXu5jIxN2f0" + passwd: "$6$Zc8nwvtw0Kns5.sD$FpQ4aBSeGogefqjM4we4U5QQd4YBtC98tuG3rR4j9ZmbtC1kyFf2sY/IodYW3wG.U81aEntlZrtOTOqw3ZcOc0" sudo: ["ALL=(ALL) NOPASSWD:ALL"] ssh_authorized_keys: - ${ssh_key} @@ -18,14 +18,4 @@ packages: runcmd: - systemctl enable --now qemu-guest-agent - - hostnamectl set-hostname ${hostname} - - systemctl disable --now packagekit || true - - systemctl disable --now ModemManager || true - - systemctl disable --now multipathd || true - -write_files: - - path: /etc/motd - content: | - Managed by OpenTofu - -final_message: "cloud-init finished" \ No newline at end of file + - hostnamectl set-hostname ${hostname} \ No newline at end of file diff --git a/cluster/locals.tf b/cluster/locals.tf index 1606811..ad0b759 100644 --- a/cluster/locals.tf +++ b/cluster/locals.tf @@ -99,7 +99,8 @@ locals { nodes = { k8s-master-1 = { - cloudinit = "master.yml" + cloudinit = "rocky.yml" + image_file = "import/rocky9.qcow2" index = 1 cpu = var.worker_cpu memory = 4092 @@ -115,45 +116,45 @@ locals { gateway = "192.168.20.1" } ] - }, - k8s-worker-1 = { - cloudinit = "worker.yml" - index = 2 - cpu = var.worker_cpu - memory = 8192 - disk = var.worker_disk - datastore = var.worker_datastore + } + # k8s-worker-1 = { + # cloudinit = "worker.yml" + # index = 2 + # cpu = var.worker_cpu + # memory = 8192 + # disk = var.worker_disk + # datastore = var.worker_datastore - network_devices = [ - { - bridge = var.node_bridge - vlan_id = 20 - ip = "192.168.20.22" - cidr = 24 - gateway = "192.168.20.1" - } - ] - }, - k8s-worker-2 = { - cloudinit = "worker.yml" - index = 3 - cpu = var.worker_cpu - memory = 8192 - disk = var.worker_disk - datastore = var.worker_datastore + # network_devices = [ + # { + # bridge = var.node_bridge + # vlan_id = 20 + # ip = "192.168.20.22" + # cidr = 24 + # gateway = "192.168.20.1" + # } + # ] + # }, + # k8s-worker-2 = { + # cloudinit = "worker.yml" + # index = 3 + # cpu = var.worker_cpu + # memory = 8192 + # disk = var.worker_disk + # datastore = var.worker_datastore - network_devices = [ - { - bridge = var.node_bridge - vlan_id = 20 - ip = "192.168.20.23" - cidr = 24 - gateway = "192.168.20.1" - }, - { - bridge = "vmbr0" - } - ] - } + # network_devices = [ + # { + # bridge = var.node_bridge + # vlan_id = 20 + # ip = "192.168.20.23" + # cidr = 24 + # gateway = "192.168.20.1" + # }, + # { + # bridge = "vmbr0" + # } + # ] + # } } } \ No newline at end of file diff --git a/modules/node/main.tf b/modules/node/main.tf index 319b0bb..f836341 100644 --- a/modules/node/main.tf +++ b/modules/node/main.tf @@ -32,6 +32,7 @@ resource "proxmox_virtual_environment_file" "cloudinit" { resource "proxmox_virtual_environment_vm" "nodes" { for_each = local.nodes + tags = ["tofu"] name = local.hostname_map[each.key] node_name = var.proxmox_node @@ -48,6 +49,8 @@ resource "proxmox_virtual_environment_vm" "nodes" { cpu { cores = each.value.cpu + type = "host" + } memory { @@ -63,12 +66,24 @@ resource "proxmox_virtual_environment_vm" "nodes" { } } - disk { +dynamic "clone" { + for_each = try(each.value.template_id, null) == null ? [] : [each.value.template_id] + + content { + vm_id = clone.value + } +} + +dynamic "disk" { + for_each = try(each.value.template_id, null) == null ? [1] : [] + + content { datastore_id = each.value.datastore import_from = "${var.image_datastore}:${var.image_file}" interface = var.disk_interface size = each.value.disk } +} dynamic "disk" { for_each = try([each.value.data_disk], []) diff --git a/modules/node/variables.tf b/modules/node/variables.tf index c2fc9af..dfe1b79 100644 --- a/modules/node/variables.tf +++ b/modules/node/variables.tf @@ -12,6 +12,7 @@ variable "nodes" { vmid = optional(number) data_disk = optional(number) cloudinit = optional(string) + template_id = optional(number) network_devices = list(object({ bridge = string