terraform-provider-proxmox: [3.0.1-rc1] Proxmox 8.1.4 Cloud init not working

When provisioning a virtual machine (VM) using the Telmate Terraform plugin for Proxmox, with a base on a pre-configured cloud-init template, the resulting VM loses all its configuration settings, such as boot disk, RAM, and core allocations.

Environment Details Proxmox version: 8.1.4 Telmate Terraform plugin version: 3.0.1-rc1 Terraform version: v1.7.1 on linux_amd64 Cloud-init template settings taken from Proxmox Documentation

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

provider "proxmox" {
  # Configuration options
   pm_api_url = "https://127.0.0.1:8006/api2/json"
}

resource "proxmox_vm_qemu" "test" {
   name        = "test"
   target_node = "pve"
   clone       = "focal64"
}

The resource example is take from plugin documentation

Another strange behaviour is that as soon as start all works 2024-02-11-15:16:56-screenshot

After some times all configuration disappear 2024-02-11-15:17:07-screenshot

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 22 (2 by maintainers)

Commits related to this issue

Most upvoted comments

I’ve had the same problem - here’s what I did to fix it

* On your Proxmox server, run the following to create your cloud-init template VM

* In my case I'm using the latest Ubuntu 22.04 cloud-init image

* Note as well that I'm using virt-customize to install the qemu guest agent to the VM as it's required for `terraform destroy` and to confirm that the agent is installed
wget https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img
apt install guestfs-tools
virt-customize -a jammy-server-cloudimg-amd64.img --install qemu-guest-agent
qm create 9000 --name ci-template --memory 2048 --net0 virtio,bridge=vmbr2 --scsihw virtio-scsi-pci
qm set 9000 --scsi0 local-lvm:0,import-from=/root/jammy-server-cloudimg-amd64.img
qm set 9000 --ide2 local-lvm:cloudinit
qm set 9000 --boot order=scsi0
qm set 9000 --serial0 socket --vga serial0
qm template 9000
* The docs for this next part are wrong
cloudinit_cdrom_storage - string - Set the storage location for the cloud-init drive. Required when specifying cicustom.
* This isn't true and needs to be defined in your Terraform config even if you're not using `cicustom`

* In my case I just needed to define the variable `cloudinit_cdrom_storage ` as `local-lvm`

After doing all of this, my Terraform applies now work

Thank you very much for this, I’ve been looking everywhere for this answer… Everything clicked in place with this setting. For future reference and to facilitate google searches, here are the keywords I’ve been typing the past day :

  • No CloudInit Drive found
  • CloudInit configuration ignored
  • Terraform doesn’t attributes an IP to my VM

And here is my Terraform config :

terraform {
  required_providers {
    proxmox = {
      source = "telmate/proxmox"
      version = "3.0.1-rc1"
    }
  }
}

provider "proxmox" {
  pm_api_url = "https://192.168.1.20:8006/api2/json"

  pm_api_token_id = "XXX@pve!XXX"
  pm_api_token_secret = "XXXXXX"
  pm_tls_insecure = true
}

resource "proxmox_vm_qemu" "test_server" {
  count = 1 
  name = "test-vm-${count.index + 1}"
  target_node = var.proxmox_host
  clone = var.template_name
  agent = 1
  os_type = "cloud-init"
  cloudinit_cdrom_storage = "local-lvm"
  cores = 2
  sockets = 1
  cpu = "host"
  memory = 1024
  scsihw = "virtio-scsi-pci"
  bootdisk = "scsi0"

  disks {
    scsi {
      scsi0 {
        disk {
          size = 10
          storage = "local-lvm"
        }
      }
    }
  }

  network {
    model = "virtio"
    bridge = "vmbr0"
  }

  ipconfig0 = "ip=192.168.1.9/24,gw=192.168.1.1"

  ssh_user = "root"
  sshkeys = <<EOF
  ${var.ssh_key}
  EOF
}

And for completness’ sake, here is how I create my template

wget https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-genericcloud-amd64.qcow2
virt-customize -a debian-12-genericcloud-amd64.qcow2 --install qemu-guest-agent --run-command 'systemctl start qemu-guest-agent.service && systemctl enable qemu-guest-agent.service'
virt-customize -a debian-12-genericcloud-amd64.qcow2 --truncate /etc/machine-id
qm create 8100 --memory 2048 --name debian-cloud --net0 virtio,bridge=vmbr0 --scsihw virtio-scsi-pci
qm importdisk 8100 debian-12-genericcloud-amd64.qcow2 local-lvm
qm set 8100 --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-8100-disk-0   
qm set 8100 --ide2 local-lvm:cloudinit
qm set 8100 --boot order=scsi0
qm set 8100 --serial0 socket --vga serial0
qm set 8100 --agent enabled=1
qm template 8100

I’ve had the same problem - here’s what I did to fix it

  • On your Proxmox server, run the following to create your cloud-init template VM
  • In my case I’m using the latest Ubuntu 22.04 cloud-init image
  • Note as well that I’m using virt-customize to install the qemu guest agent to the VM as it’s required for terraform destroy and to confirm that the agent is installed
wget https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img
apt install guestfs-tools
virt-customize -a jammy-server-cloudimg-amd64.img --install qemu-guest-agent
qm create 9000 --name ci-template --memory 2048 --net0 virtio,bridge=vmbr2 --scsihw virtio-scsi-pci
qm set 9000 --scsi0 local-lvm:0,import-from=/root/jammy-server-cloudimg-amd64.img
qm set 9000 --ide2 local-lvm:cloudinit
qm set 9000 --boot order=scsi0
qm set 9000 --serial0 socket --vga serial0
qm template 9000
  • The docs for this next part are wrong
cloudinit_cdrom_storage - string - Set the storage location for the cloud-init drive. Required when specifying cicustom.
  • This isn’t true and needs to be defined in your Terraform config even if you’re not using cicustom
  • In my case I just needed to define the variable cloudinit_cdrom_storage as local-lvm

After doing all of this, my Terraform applies now work

To whoever is on the latest terraform provider, cloudinit_cdrom_storage has been deprecated

https://github.com/Telmate/terraform-provider-proxmox/pull/1008/files

use disks/ide/ide3/cloudinit instead

Does anyone have been able to deploy a VM successfully using Packer (create template with cloud-init enabled) + v3.0.1-rc[12] + Proxmox v8.1.4? In case you did it, would you mind to share the config files and the steps? I’ve been working on this for a few days now but so far no luck… I can boot the VM but the cloud-init is not applied (not even the ip address indicated by

ipconfig0 = “ip=192.168.20.27/23,gw=192.168.20.1”

I haven’t tried @leogout’s solution yet (I need to create my image with Packer)

@USBAkimbo you are referring to this https://github.com/Telmate/terraform-provider-proxmox/pull/937 ? I hope this will help as it removes that damn ISO which is so useless.