add rocky image

This commit is contained in:
Iurii Anfinogenov
2026-05-04 06:30:51 +00:00
parent 40694927c8
commit 326572de4d
4 changed files with 60 additions and 53 deletions

View File

@@ -2,11 +2,11 @@
timezone: Europe/Moscow timezone: Europe/Moscow
users: users:
- name: rocky - name: iurii
groups: [wheel] groups: [wheel]
shell: /bin/bash shell: /bin/bash
lock_passwd: false lock_passwd: false
passwd: "$6$M8xzsYT0lwWjlcdH$HJRhw0rBb2WowCbqg03/WvMUlte0j5SLs9tAVCxCukEqWAt7XG0ceWYc5GRUBmRxFRTbcEDrdCVTXu5jIxN2f0" passwd: "$6$Zc8nwvtw0Kns5.sD$FpQ4aBSeGogefqjM4we4U5QQd4YBtC98tuG3rR4j9ZmbtC1kyFf2sY/IodYW3wG.U81aEntlZrtOTOqw3ZcOc0"
sudo: ["ALL=(ALL) NOPASSWD:ALL"] sudo: ["ALL=(ALL) NOPASSWD:ALL"]
ssh_authorized_keys: ssh_authorized_keys:
- ${ssh_key} - ${ssh_key}
@@ -18,14 +18,4 @@ packages:
runcmd: runcmd:
- systemctl enable --now qemu-guest-agent - systemctl enable --now qemu-guest-agent
- hostnamectl set-hostname ${hostname} - 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"

View File

@@ -99,7 +99,8 @@
locals { locals {
nodes = { nodes = {
k8s-master-1 = { k8s-master-1 = {
cloudinit = "master.yml" cloudinit = "rocky.yml"
image_file = "import/rocky9.qcow2"
index = 1 index = 1
cpu = var.worker_cpu cpu = var.worker_cpu
memory = 4092 memory = 4092
@@ -115,45 +116,45 @@ locals {
gateway = "192.168.20.1" gateway = "192.168.20.1"
} }
] ]
}, }
k8s-worker-1 = { # k8s-worker-1 = {
cloudinit = "worker.yml" # cloudinit = "worker.yml"
index = 2 # index = 2
cpu = var.worker_cpu # cpu = var.worker_cpu
memory = 8192 # memory = 8192
disk = var.worker_disk # disk = var.worker_disk
datastore = var.worker_datastore # datastore = var.worker_datastore
network_devices = [ # network_devices = [
{ # {
bridge = var.node_bridge # bridge = var.node_bridge
vlan_id = 20 # vlan_id = 20
ip = "192.168.20.22" # ip = "192.168.20.22"
cidr = 24 # cidr = 24
gateway = "192.168.20.1" # gateway = "192.168.20.1"
} # }
] # ]
}, # },
k8s-worker-2 = { # k8s-worker-2 = {
cloudinit = "worker.yml" # cloudinit = "worker.yml"
index = 3 # index = 3
cpu = var.worker_cpu # cpu = var.worker_cpu
memory = 8192 # memory = 8192
disk = var.worker_disk # disk = var.worker_disk
datastore = var.worker_datastore # datastore = var.worker_datastore
network_devices = [ # network_devices = [
{ # {
bridge = var.node_bridge # bridge = var.node_bridge
vlan_id = 20 # vlan_id = 20
ip = "192.168.20.23" # ip = "192.168.20.23"
cidr = 24 # cidr = 24
gateway = "192.168.20.1" # gateway = "192.168.20.1"
}, # },
{ # {
bridge = "vmbr0" # bridge = "vmbr0"
} # }
] # ]
} # }
} }
} }

View File

@@ -32,6 +32,7 @@ resource "proxmox_virtual_environment_file" "cloudinit" {
resource "proxmox_virtual_environment_vm" "nodes" { resource "proxmox_virtual_environment_vm" "nodes" {
for_each = local.nodes for_each = local.nodes
tags = ["tofu"]
name = local.hostname_map[each.key] name = local.hostname_map[each.key]
node_name = var.proxmox_node node_name = var.proxmox_node
@@ -48,6 +49,8 @@ resource "proxmox_virtual_environment_vm" "nodes" {
cpu { cpu {
cores = each.value.cpu cores = each.value.cpu
type = "host"
} }
memory { 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 datastore_id = each.value.datastore
import_from = "${var.image_datastore}:${var.image_file}" import_from = "${var.image_datastore}:${var.image_file}"
interface = var.disk_interface interface = var.disk_interface
size = each.value.disk size = each.value.disk
} }
}
dynamic "disk" { dynamic "disk" {
for_each = try([each.value.data_disk], []) for_each = try([each.value.data_disk], [])

View File

@@ -12,6 +12,7 @@ variable "nodes" {
vmid = optional(number) vmid = optional(number)
data_disk = optional(number) data_disk = optional(number)
cloudinit = optional(string) cloudinit = optional(string)
template_id = optional(number)
network_devices = list(object({ network_devices = list(object({
bridge = string bridge = string