chore: Refactor talos image creation

This commit is contained in:
Peter 2025-11-27 16:37:46 +01:00
parent de4faf86ca
commit 1a791f6c37
Signed by: Peter
SSH key fingerprint: SHA256:B5tYaxBExaDm74r1px9iVeZ6F/ZDiyiy9SbBqfZYrvg
3 changed files with 27 additions and 48 deletions

View file

@ -40,20 +40,3 @@ provider "registry.opentofu.org/hashicorp/http" {
"zh:f1c9d2eb1a6b618ae77ad86649679241bd8d6aacec06d0a68d86f748687f4eb3", "zh:f1c9d2eb1a6b618ae77ad86649679241bd8d6aacec06d0a68d86f748687f4eb3",
] ]
} }
provider "registry.opentofu.org/hashicorp/null" {
version = "3.2.4"
hashes = [
"h1:i+WKhUHL2REY5EGmiHjfUljJB8UKZ9QdhdM5uTeUhC4=",
"zh:1769783386610bed8bb1e861a119fe25058be41895e3996d9216dd6bb8a7aee3",
"zh:32c62a9387ad0b861b5262b41c5e9ed6e940eda729c2a0e58100e6629af27ddb",
"zh:339bf8c2f9733fce068eb6d5612701144c752425cebeafab36563a16be460fb2",
"zh:36731f23343aee12a7e078067a98644c0126714c4fe9ac930eecb0f2361788c4",
"zh:3d106c7e32a929e2843f732625a582e562ff09120021e510a51a6f5d01175b8d",
"zh:74bcb3567708171ad83b234b92c9d63ab441ef882b770b0210c2b14fdbe3b1b6",
"zh:90b55bdbffa35df9204282251059e62c178b0ac7035958b93a647839643c0072",
"zh:ae24c0e5adc692b8f94cb23a000f91a316070fdc19418578dcf2134ff57cf447",
"zh:b5c10d4ad860c4c21273203d1de6d2f0286845edf1c64319fa2362df526b5f58",
"zh:e05bbd88e82e1d6234988c85db62fd66f11502645838fff594a2ec25352ecd80",
]
}

View file

@ -1,8 +1,13 @@
provider "proxmox" { provider "proxmox" {
endpoint = var.proxmox_endpoint endpoint = var.proxmox_endpoint
api_token = var.proxmox_api_token api_token = var.proxmox_api_token
ssh {
agent = true
username = "root"
}
} }
locals { locals {
talos_versions = ["1.11.5"] talos_versions = ["1.11.5"]
} }
@ -22,43 +27,31 @@ locals {
storagepool = "nvme-fastpool" storagepool = "nvme-fastpool"
} }
resource "null_resource" "local_download_talos_image" { resource "proxmox_virtual_environment_download_file" "talos-image" {
for_each = toset(local.talos_versions) for_each = toset(local.talos_versions)
provisioner "local-exec" { node_name = "pve01"
command = <<EOT datastore_id = "local"
curl -L https://factory.talos.dev/image/${local.schematic_id}/v${each.value}/nocloud-amd64-secureboot.raw.xz -o ${path.module}/talos-${each.value}-nocloud-amd64-secureboot.raw.xz content_type = "iso"
xz -d ${path.module}/talos-${each.value}-nocloud-amd64-secureboot.raw.xz
EOT
}
}
resource "proxmox_virtual_environment_file" "talos-image" {
depends_on = [null_resource.local_download_talos_image]
for_each = toset(local.talos_versions)
node_name = "pve01" url = "https://factory.talos.dev/image/${local.schematic_id}/v${each.value}/nocloud-amd64-secureboot.raw.gz"
content_type = "import" file_name = "talos-${each.value}-nocloud-amd64-secureboot.img"
datastore_id = "local" decompression_algorithm = "gz"
overwrite = true
source_file {
path = "${path.module}/talos-${each.value}-nocloud-amd64-secureboot.raw"
}
} }
resource "proxmox_virtual_environment_vm" "talos-template" { resource "proxmox_virtual_environment_vm" "talos-template" {
depends_on = [proxmox_virtual_environment_file.talos-image] depends_on = [proxmox_virtual_environment_download_file.talos-image]
for_each = toset(local.talos_versions) for_each = toset(local.talos_versions)
template = true template = true
vm_id = 10000 + tonumber(replace(each.value, ".", "")) vm_id = 10000 + tonumber(replace(each.value, ".", ""))
name = "talos-template-${each.value}" name = "talos-template-${each.value}"
node_name = "pve01" node_name = "pve01"
tags = ["tofu"] tags = ["tofu"]
bios = "ovmf" bios = "ovmf"
on_boot = true on_boot = true
machine = "q35" machine = "q35"
operating_system { operating_system {
type = "l26" type = "l26"
} }
@ -76,8 +69,7 @@ resource "proxmox_virtual_environment_vm" "talos-template" {
disk { disk {
datastore_id = local.storagepool datastore_id = local.storagepool
interface = "virtio0" interface = "virtio0"
import_from = proxmox_virtual_environment_file.talos-image[each.value].id file_id = proxmox_virtual_environment_download_file.talos-image[each.value].id
size = 10
file_format = "raw" file_format = "raw"
} }
efi_disk { efi_disk {

View file

@ -4,5 +4,9 @@ terraform {
source = "bpg/proxmox" source = "bpg/proxmox"
version = "0.86.0" version = "0.86.0"
} }
http = {
source = "hashicorp/http"
version = "3.5.0"
}
} }
} }