data "local_file" "ssh_public_key" { filename = "/home/ryuuji/.ssh/id_rsa.pub" } resource "proxmox_virtual_environment_download_file" "ubuntu_cloud_image" { content_type = "iso" datastore_id = "storage" node_name = "talos" url = "https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img" file_name = "k3s-noble-server-cloudimg-amd64.img" } resource "proxmox_virtual_environment_file" "k3s_user_data_cloud_config" { for_each = var.k3s_vm_config content_type = "snippets" datastore_id = "storage" node_name = "talos" source_raw { data = <<-EOF #cloud-config hostname: ${each.value.name} users: - default - name: ubuntu groups: - sudo shell: /bin/bash ssh_authorized_keys: - ${trimspace(data.local_file.ssh_public_key.content)} sudo: ALL=(ALL) NOPASSWD:ALL runcmd: - apt update - apt install -y qemu-guest-agent net-tools - timedatectl set-timezone America/Santiago - systemctl enable qemu-guest-agent - systemctl start qemu-guest-agent - echo "done" > /tmp/cloud-config.done EOF file_name = "${each.value.name}-k3s-cloud-config.yaml" } } resource "proxmox_virtual_environment_vm" "k3s_ubuntu_vm" { for_each = var.k3s_vm_config name = each.value.name node_name = "talos" agent { enabled = true } cpu { cores = 4 type = "host" } memory { dedicated = each.value.ram } disk { datastore_id = "storage-lvm" file_id = proxmox_virtual_environment_download_file.ubuntu_cloud_image.id interface = "virtio0" iothread = true discard = "on" size = 50 } disk { datastore_id = "storage-lvm" iothread = true interface = "virtio1" discard = "on" file_format = "raw" size = 200 } network_device { bridge = "vmbr0" } initialization { datastore_id = "storage-lvm" ip_config { ipv4 { address = "${each.value.ip}/${each.value.cidr}" gateway = "192.168.1.1" } } user_data_file_id = proxmox_virtual_environment_file.k3s_user_data_cloud_config[each.key].id } }