terraform-provider-proxmox: VM is not created properly or completely, no Cloud-init drive after creation

Hi! I have no prior knowledge related to any of this, so I may have made many mistakes. Please help me out with this. I’m using an Ubuntu 24.04 VM template to create VMs using Terraform, followed this tutorial to create the VM template https://tcude.net/creating-a-vm-template-in-proxmox/. My main.tf is as follows -

terraform {
required_providers {
proxmox = {
source = "Telmate/proxmox"
version = "3.0.1-rc3"
}
}
}
provider "proxmox" {
pm_api_url = "https://xxxxx:8006/api2/json"
pm_user = "xyz@pve"
pm_password = "xyz" # Or use an API token
pm_tls_insecure = true
pm_debug = true
pm_log_enable = true
}

resource "proxmox_vm_qemu" "my_test_vms" {
count = 1
name = "Test-vm-${count.index + 1}"

onboot = true
vm_state = "running"

target_node = "xxx"
memory = 2048
cores = 2
sockets = 1
clone = "template-name"
network {
model = "virtio"
bridge = "vmbr0"
}

ipconfig0 = "ip=dhcp"

}

This gives me a VM with no cloud-init drive and a state of continuous boots like the pic attached. The Ubuntu OS doesn’t startup. image image

Now , if I remove bridge=“vmbr0” and ipconfig0=“ip=dhcp”. This creates a VM with the following error. It starts once manually started though.

proxmox_vm_qemu.my_test_vms[0]: Creating… proxmox_vm_qemu.my_test_vms[0]: Still creating… [10s elapsed] ╷ │ Error: error updating VM: 500 no sdn vnet ID specified, error status: {“data”:null} (params: map[agent:0 bios:seabios cores:2 cpu:host delete:ide2,scsi0 hotplug:network,disk,usb kvm:true memory:2048 name:Test-vm-1 net0:virtio=5E:74:ED:5A:07:CC numa:false onboot:true protection:false scsihw:lsi sockets:1 tablet:true vmid:102]) │ │ with proxmox_vm_qemu.my_test_vms[0], │ on main.tf line 20, in resource “proxmox_vm_qemu” “my_test_vms”: │ 20: resource “proxmox_vm_qemu” “my_test_vms” { │

If I remove just the line “bridge=vmbr0”, it gives a similar error and starts when started. Error: error updating VM: 500 no sdn vnet ID specified, error status: {“data”:null} (params: map[agent:0 balloon:0 bios:seabios cicustom: cipassword: ciupgrade:0 cores:2 cpu:host delete:ide0,ide2,scsi0,ciuser,searchdomain,nameserver,shares,serial0 hotplug:network,disk,usb ipconfig0:ip=dhcp kvm:true memory:4096 name:induz-memcache-vm-1 net0:virtio=CE:F6:F8:EA:5F:B9 numa:0 onboot:true protection:false scsihw:lsi sockets:1 sshkeys:%0A tablet:true vmid:100])

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 27 (1 by maintainers)

Most upvoted comments

Finally got a working setup - I think the issue was tied to EFI. So the heavy lifting was done by the template creation script, but I had to make sure my disks section matched the new template setup. Before I was using ide and scsi but now I’m using scsi and virtio (I’m still new to all this so I can’t tell you exactly why this worked but I’m happy it does!). Here’s a working setup for me for future documentation.

One bug with the current setup is that any updates to these resources trigger a reboot on PVE and that never completes. I have to manually stop the resources first. I’m okay with that for now but would be good to look into if possible.

Cloud Init Template Create

taken from https://github.com/UntouchedWagons/Ubuntu-CloudInit-Docs/blob/main/samples/ubuntu/ubuntu-noble-cloudinit.sh

#! /bin/bash

VMID=8000
STORAGE=local-lvm

set -x
rm -f noble-server-cloudimg-amd64.img
wget -q https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img
qemu-img resize noble-server-cloudimg-amd64.img 8G
qm destroy $VMID
qm create $VMID --name "ubuntu-noble-template" --ostype l26 \
    --memory 1024 --balloon 0 \
    --agent 1 \
    --bios ovmf --machine q35 --efidisk0 $STORAGE:0,pre-enrolled-keys=0 \
    --cpu host --cores 1 --numa 1 \
    --vga serial0 --serial0 socket  \
    --net0 virtio,bridge=vmbr0,mtu=1
qm importdisk $VMID noble-server-cloudimg-amd64.img $STORAGE
qm set $VMID --scsihw virtio-scsi-pci --virtio0 $STORAGE:vm-$VMID-disk-1,discard=on
qm set $VMID --boot order=virtio0
qm set $VMID --scsi1 $STORAGE:cloudinit

cat << EOF | tee /var/lib/vz/snippets/ubuntu.yaml
#cloud-config
runcmd:
    - apt-get update
    - apt-get install -y qemu-guest-agent
    - systemctl enable ssh
    - reboot
# Taken from https://forum.proxmox.com/threads/combining-custom-cloud-init-with-auto-generated.59008/page-3#post-428772
EOF

qm set $VMID --cicustom "vendor=local:snippets/ubuntu.yaml"
qm set $VMID --tags ubuntu-template,noble,cloudinit
# qm set $VMID --ciuser serveradmin
# qm set $VMID --sshkeys ~/.ssh/authorized_keys
qm set $VMID --ipconfig0 ip=dhcp
qm template $VMID

TF Provider

terraform {
  required_providers {
    proxmox = {
      source  = "Telmate/proxmox"
      version = "3.0.1-rc4"
    }
  }
}

provider "proxmox" {
  pm_api_url          = "${var.PM_BASE_URI}/api2/json"
  pm_api_token_id     = var.PM_API_TOKEN_ID
  pm_api_token_secret = var.PM_API_TOKEN_SECRET
}

vms.tf

resource "proxmox_vm_qemu" "resource-name" {
  count       = 1
  name        = "vm-name"
  target_node = "pve-node-name"
  agent       = 1
  memory      = 6144 // 6Gb
  tags        = "iac,terraform"
  ipconfig0   = "ip=192.168.1.100/32,gw=192.168.1.1"
  os_type     = "cloud-init"
  clone       = "ubuntu-noble-template"
  sockets     = 1
  cores       = 1
  scsihw      = "virtio-scsi-pci"
  onboot      = true
  ciuser      = "serveradmin"
  sshkeys     = var.ssh_keys
  serial {
    id = 0
    type = "socket"
  }
  network {
    bridge    = "vmbr0"
    firewall  = false
    link_down = false
    model     = "virtio"
  }
  disks {
    scsi {
      scsi1 {
        cloudinit {
          storage = "local-lvm"
        }
      }
    }
    virtio {
      virtio0 {
        disk {
          storage = "local-lvm"
          size    = "30G"
        }
      }
    }
  }
}