Skip to content

VM creation fails with cloud-init VM with guest agent enabled #1413

@TobiPeterG

Description

@TobiPeterG

Hi there,

when I'm trying to create a VM using this provider with Proxmox 9, opentofu/terragrunt shows this error after some time:

module.proxmox_vm.proxmox_cloud_init_disk.ci: Creation complete after 6s [id=cephfs:iso/tf-ci-test.iso]
module.proxmox_vm.proxmox_vm_qemu.vm: Creating...
module.proxmox_vm.proxmox_vm_qemu.vm: Still creating... [10s elapsed]
module.proxmox_vm.proxmox_vm_qemu.vm: Still creating... [20s elapsed]
module.proxmox_vm.proxmox_vm_qemu.vm: Still creating... [30s elapsed]
module.proxmox_vm.proxmox_vm_qemu.vm: Still creating... [40s elapsed]
module.proxmox_vm.proxmox_vm_qemu.vm: Still creating... [50s elapsed]

Error: 500 Internal Server Error

  with module.proxmox_vm.proxmox_vm_qemu.vm,
  on .terraform/modules/proxmox_vm/main.tf line 26, in resource "proxmox_vm_qemu" "vm":
  26: resource "proxmox_vm_qemu" "vm" {

time=2025-10-01T09:11:34Z level=error msg=terraform invocation failed in /app/config/data-dir/repos/sci/deployment/virtual_machines/130/pcloud_vm_configs_infrastructure_251001_test/pcloud/vm_configs/infrastructure/251001_test/.terragrunt-cache/5TQt7dDahpgne4lqy8rtTCF4r8w/YDaC2-xxFNen9AN8ugH4TCU9LyQ prefix=[/app/config/data-dir/repos/sci/deployment/virtual_machines/130/pcloud_vm_configs_infrastructure_251001_test/pcloud/vm_configs/infrastructure/251001_test] 
time=2025-10-01T09:11:34Z level=error msg=1 error occurred:
	* [/app/config/data-dir/repos/sci/deployment/virtual_machines/130/pcloud_vm_configs_infrastructure_251001_test/pcloud/vm_configs/infrastructure/251001_test/.terragrunt-cache/5TQt7dDahpgne4lqy8rtTCF4r8w/YDaC2-xxFNen9AN8ugH4TCU9LyQ] exit status 1

On this node, I see this in the logs:

sudo tail -n +1 /var/log/pveproxy/access.log
::ffff:10.124.31.44 - OpenTofu@pve!OpenTofu [01/10/2025:09:11:21 +0000] "GET /api2/json/nodes/cx39/qemu/198/agent/network-get-interfaces HTTP/1.1" 500 59
::ffff:10.124.31.44 - OpenTofu@pve!OpenTofu [01/10/2025:09:11:25 +0000] "GET /api2/json/nodes/cx39/qemu/198/agent/network-get-interfaces HTTP/1.1" 500 59
::ffff:10.124.31.44 - OpenTofu@pve!OpenTofu [01/10/2025:09:11:30 +0000] "GET /api2/json/nodes/cx39/qemu/198/agent/network-get-interfaces HTTP/1.1" 500 59
journalctl -b 0 -e
Oct 01 09:11:11 cx39 pvedaemon[3869]: <OpenTofu@pve!OpenTofu> end task UPID:cx39:000F7F51:007A8D45:68DCF02A:qmstart:198:OpenTofu@pve!OpenTofu: OK
Oct 01 09:11:21 cx39 pvedaemon[3868]: VM 198 qmp command failed - VM 198 qmp command 'guest-ping' failed - got timeout
Oct 01 09:11:25 cx39 pvedaemon[3869]: VM 198 qmp command failed - VM 198 qmp command 'guest-ping' failed - got timeout
Oct 01 09:11:30 cx39 pvedaemon[3868]: VM 198 qmp command failed - VM 198 qmp command 'guest-ping' failed - got timeout

This is the opentofu config block we use:

terraform {
  required_providers {
    proxmox = {
      source  = "registry.terraform.io/Telmate/proxmox"
      version = "3.0.2-rc04"
    }
  }
}

resource "proxmox_cloud_init_disk" "ci" {
  name           = var.nb_name
  pve_node       = var.proxmox_ci_node
  storage        = var.iso_storage
  user_data      = var.cloudinit_rendered
  network_config = var.network_cloud_init
  meta_data      = yamlencode({
    instance_id    = sha1(var.nb_name)
    local-hostname = var.nb_name
  })

  lifecycle {
    ignore_changes = all
  }
}

resource "proxmox_vm_qemu" "vm" {
  name         = var.vm_name
  protection   = var.vm_protection
  target_nodes = var.proxmox_nodes
  memory       = var.vm_memory
  scsihw       = "virtio-scsi-pci"
  clone        = var.template_name
  os_type      = var.os_type
  pool         = var.proxmox_pool
  agent        = 1
  skip_ipv6    = true

  cpu {
    cores   = var.vm_cpu
    sockets = 1
    type    = "host"
  }

  dynamic "network" {
    for_each = var.vm_networks
    content {
      id      = index(var.vm_networks, network.value)
      model   = "virtio"
      bridge  = var.vlan_configs[network.value].proxmox_bridge
      macaddr = var.mac_addresses[network.value]
      tag     = var.vlan_configs[network.value].proxmox_tag
    }
  }

  disks {
    scsi {
      scsi0 {
        disk {
          size    = var.disk_size
          storage = var.storage
        }
      }
    }
    ide {
      ide2 {
        cdrom {
          iso = proxmox_cloud_init_disk.ci.id
        }
      }
    }
  }
  lifecycle {
    ignore_changes = [
      agent_timeout,
      disks[0].ide[0].ide2[0].cdrom[0].iso,
      target_node,
      target_nodes,
      agent
    ]
  }
}

I'm not sure if this is an issue of Proxmox itself or of the provider. We have the guest agent installed and when the VM is cloned, cloud init runs through (which takes quite long, because it's complex). My guess is that the agent times out, but a more clear error message would be nice. Could that be it? Is there any way to prevent it from trying to get the network address? We want the guest agent enabled to see the IP in proxmox itself once it's ready, but it's not required in opentofu. We didn't observe this issue with Proxmox 8X and an earlier version of this provider with the same settings.

Should you need any additional information, please let me know :)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions