infrastructure/pve01.wheatley.in/templates/talos/main.tf

97 lines
2.3 KiB
Terraform
Raw Normal View History

2025-11-15 20:49:31 +01:00
provider "proxmox" {
endpoint = var.proxmox_endpoint
api_token = var.proxmox_api_token
insecure = true
}
locals {
talos_versions = ["1.11.4", "1.11.5"]
}
data "http" "schematic" {
url = "https://factory.talos.dev/schematics"
method = "POST"
request_body = file("${path.module}/schematic.yaml")
request_headers = {
"Content-Type" = "application/x-yaml"
}
}
locals {
schematic_id = jsondecode(data.http.schematic.response_body)["id"]
storagepool = "nvme-fastpool"
}
resource "null_resource" "local_download_talos_image" {
for_each = toset(local.talos_versions)
provisioner "local-exec" {
command = <<EOT
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
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"
content_type = "import"
datastore_id = "local"
overwrite = true
source_file {
path = "${path.module}/talos-${each.value}-nocloud-amd64-secureboot.raw"
}
}
resource "proxmox_virtual_environment_vm" "talos-template" {
depends_on = [proxmox_virtual_environment_file.talos-image]
for_each = toset(local.talos_versions)
template = true
vm_id = 10000 + tonumber(replace(each.value, ".", ""))
name = "talos-template-${each.value}"
node_name = "pve01"
tags = ["tofu"]
bios = "ovmf"
on_boot = true
machine = "q35"
operating_system {
type = "l26"
}
agent {
enabled = true
}
cpu {
cores = 2
sockets = 1
type = "x86-64-v2-AES"
}
memory {
dedicated = 2048
}
disk {
datastore_id = local.storagepool
interface = "virtio0"
import_from = proxmox_virtual_environment_file.talos-image[each.value].id
size = 10
file_format = "raw"
}
efi_disk {
datastore_id = local.storagepool
file_format = "raw"
type = "4m"
}
tpm_state {
datastore_id = local.storagepool
version = "v2.0"
}
network_device {
bridge = "vmbr1"
}
}