Skip to content

Commit

Permalink
fix(talos-proxmox): remove dynamic part of schematic for proxmox_virt…
Browse files Browse the repository at this point in the history
…ual_environment_download_file

this commit implements solution option #4 for circumventing vehagn/homelab#106
  • Loading branch information
sebiklamar committed Nov 17, 2024
1 parent 8597ca7 commit 03b3bfd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 42 deletions.
55 changes: 16 additions & 39 deletions modules/talos-proxmox/image.tf
Original file line number Diff line number Diff line change
@@ -1,60 +1,37 @@
locals {
version = var.image.version
version = var.image.version
schematic = file("${path.module}/image/schematic.yaml")
image_id = "${talos_image_factory_schematic.this.id}_${local.version}"
image_id = "${talos_image_factory_schematic.this.id}_${local.version}"

update_version = coalesce(var.image.update_version, var.image.version)
update_version = coalesce(var.image.update_version, var.image.version)
update_schematic = coalesce(var.image.update_schematic, local.schematic)
update_image_id = "${talos_image_factory_schematic.updated.id}_${local.update_version}"
update_image_id = "${talos_image_factory_schematic.updated.id}_${local.update_version}"
}

resource "talos_image_factory_schematic" "this" {
schematic = local.schematic
}

# not used (see https://github.com/vehagn/homelab/issues/106)
# TODO: support change of schematic upon update
resource "talos_image_factory_schematic" "updated" {
schematic = local.update_schematic
}

resource "proxmox_virtual_environment_download_file" "orig-image" {
for_each = toset(distinct([for i in var.nodes : "${i.host_node}_no-schematic-id_${local.version}"]))
resource "proxmox_virtual_environment_download_file" "this" {
# this.id format: <node>_<schematic>_<version>
# for_each = toset(distinct([for k, v in var.nodes : "${v.host_node}_${v.update == true ? local.update_image_id : local.image_id}"]))
# this.id format: <node>_<version>
for_each = toset(distinct([for k, v in var.nodes : "${v.host_node}_${v.update == true ? local.update_version : local.version}"]))

node_name = split("_", each.key)[0]
content_type = "iso"
datastore_id = var.image.proxmox_datastore

file_name = "talos-${talos_image_factory_schematic.this.id}-${split("_", each.key)[2]}-${var.image.platform}-${var.image.arch}.img"
url = "${var.image.factory_url}/image/${talos_image_factory_schematic.this.id}/${split("_", each.key)[2]}/${var.image.platform}-${var.image.arch}.raw.gz"
# ex.: talos-ce4c980550dd2ab1b17bbf2b08801c7eb59418eafe8f279833297925d67c7515-v1.8.1-nocloud-amd64.img
file_name = "talos-${talos_image_factory_schematic.this.id}-${split("_", each.key)[1]}-${var.image.platform}-${var.image.arch}.img"
url = "${var.image.factory_url}/image/${talos_image_factory_schematic.this.id}/${split("_", each.key)[1]}/${var.image.platform}-${var.image.arch}.raw.gz"
decompression_algorithm = "gz"
overwrite = false
}

resource "proxmox_virtual_environment_download_file" "updated-image" {
for_each = toset(distinct([for i in var.nodes : "${i.host_node}_no-schematic-id_${local.version}"]))

node_name = split("_", each.key)[0]
content_type = "iso"
datastore_id = var.image.proxmox_datastore

file_name = "talos-${talos_image_factory_schematic.updated.id}-${split("_", each.key)[2]}-${var.image.platform}-${var.image.arch}.img"
url = "${var.image.factory_url}/image/${talos_image_factory_schematic.updated.id}/${split("_", each.key)[2]}/${var.image.platform}-${var.image.arch}.raw.gz"
decompression_algorithm = "gz"
overwrite = false
}

# resource "proxmox_virtual_environment_download_file" "this" {
# # for_each = toset(distinct([for k, v in var.nodes : "${v.host_node}_${v.update == true ? local.update_image_id : local.image_id}"]))
# for_each = toset(distinct([for k, v in var.nodes : "${v.host_node}_${v.update == true ? local.skl_workaround_orig_key : local.skl_workaround_updated_key}"]))
# # for_each = toset([ "pve2_${local.image_id}", "pve2_${local.update_image_id}" ])
# # for_each = toset([ "pve2_orig_1.2.3", "pve2_update_3.2.1}" ])

# node_name = split("_", each.key)[0]
# content_type = "iso"
# datastore_id = var.image.proxmox_datastore

# # ex.: talos-ce4c980550dd2ab1b17bbf2b08801c7eb59418eafe8f279833297925d67c7515-v1.8.1-nocloud-amd64.img
# file_name = "talos-${split("_", each.key)[1]}-${split("_", each.key)[2]}-${var.image.platform}-${var.image.arch}.img"
# url = "${var.image.factory_url}/image/${split("_", each.key)[1]}/${split("_", each.key)[2]}/${var.image.platform}-${var.image.arch}.raw.gz"
# decompression_algorithm = "gz"
# overwrite = false
# }
overwrite_unmanaged = true
}
4 changes: 1 addition & 3 deletions modules/talos-proxmox/virtual-machines.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
resource "proxmox_virtual_environment_vm" "this" {
depends_on = [proxmox_virtual_environment_download_file.orig-image]
for_each = var.nodes

node_name = each.value.host_node
Expand Down Expand Up @@ -42,8 +41,7 @@ resource "proxmox_virtual_environment_vm" "this" {
ssd = true
file_format = "raw"
size = 20
file_id = each.value.update == true ? proxmox_virtual_environment_download_file.updated-image["${each.value.host_node}_no-schematic-id_${local.update_version}"].id : proxmox_virtual_environment_download_file.orig-image["${each.value.host_node}_no-schematic-id_${local.version}"].id
# file_id = proxmox_virtual_environment_download_file.this["${each.value.host_node}_${each.value.update == true ? local.update_image_id : local.image_id}"].id
file_id = proxmox_virtual_environment_download_file.this["${each.value.host_node}_${each.value.update == true ? local.update_version : local.version}"].id
}

boot_order = ["scsi0"]
Expand Down

0 comments on commit 03b3bfd

Please sign in to comment.