[SOLVED] Proxmox VE Problems Cloud Init Terraform

nozomi

New Member
Apr 22, 2025
2
0
1
Hi. I'm having problems cloning with Terraform my template I did following this video: https://www.youtube.com/watch?v=MJgIm03Jxdo&ab_channel=LearnLinuxTV
The template works fine, as in Proxmox GUI I can clone as many VMs as I want and it works perfectly. However, when I try doing it with Terraform, it either doesn't have cloudinit, or the console can't connect to server. My provider is telmate and the version is 3.0.1-rc8.

I appreciate any help I could get.

Thank you,


Code:
resource "proxmox_vm_qemu" "VM" {
  name         = "VM"
  target_node  = var.proxmox_node
  clone        = var.templateVM
  vmid         = 400
  full_clone   = true
  agent        = 1
  os_type      = "cloud-init"
  cores        = 2
  memory       = 2048
  scsihw       = "virtio-scsi-single"
  disk {
    size     = "32G"
    slot     = "scsi0"
    storage  = "secondHDD"
    //discard  = false
  }
  network {
    id         = 0
    model      = "virtio"
    bridge     = "vmbr0"
    firewall   = false
    link_down  = false # disables network on boot
  }
  ciuser = var.user
  cipassword = var.password
  ipconfig0   = "ip=192.168.128.10/24,gw=192.168.128.1"
  sshkeys = <<EOF
  ${var.ssh_public_key}
  EOF
}

I may even dare to say, that at first it clones correctly but then it does something that makes it not work. + When doing terraform apply it doesnt finish applying it...
 
Hi @nozomi, welcome to the forum.

Tools like Terraform, Ansible, etc., that manipulate VMs externally are developed and maintained by third parties. Their configuration options don’t always translate directly to native PVE configurations. Some entries can trigger multiple API calls under the hood, and may not map one-to-one.

To understand what’s happening, you’ll want to either increase verbosity/debug logging in Terraform or trace the API activity directly. Watching logs on the PVE side might help too, i.e. "journalctl -f".

Another option is to start with the most minimal working config and build up from there, step-by-step.

As an example of "proprietary" configuration option - PVE doesn’t have an os_type field. There is "ostype" field, and cloud-init isn’t a valid value for it.



Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
 
I now followed the "Preparing Cloud Init temples" https://pve.proxmox.com/wiki/Cloud-Init_Support section in this link. I used the cloud image https://cloud-images.ubuntu.com/min...lease/ubuntu-22.04-minimal-cloudimg-amd64.img. The VM is 9000. This is the code updated:

Code:
resource "proxmox_vm_qemu" "VM" {
  name         = "VM"
  target_node  = var.proxmox_node
  clone        = "VM 9000"
  vmid         = 410
  full_clone   = true

  agent        = 1

  cores        = 2
  memory       = 2048
  os_type     = "cloud-init"

  scsihw       = "virtio-scsi-pci" # Matches your template
  cpu_type     = "host"
  vcpus        = 0

  disks {
    ide {
      ide2 {
        cloudinit {
          storage = "local-lvm"
        }
      }
    }

     scsi {
      scsi0 {
        disk {
          size         = 32
          storage      = "secondHDD"
          cache        = "writeback"
          iothread     = true
          discard      = true
        }
      }
    }
  }

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

  # ciuser = var.user
  # cipassword = var.password

  ipconfig0   = "ip=192.168.128.10/24,gw=192.168.128.1"

  sshkeys = <<EOF
  ${var.ssh_public_key}
  EOF

}

It now works. I based my template from https://github.com/Telmate/terraform-provider-proxmox/blob/master/examples/cloudinit_example.tf. The only thing I don't understand yet is why in the PROXMOX VE GUI, the console can't connect to server, however when I ssh from outside doing ssh user@ip it works.

I'm not sure what could I do to make the GUI work, and also to improve the security of the VM, as I want to make it a honeypot. If anyone has any suggestions I would appreciate it a lot. :)
 
The only thing I don't understand yet is why in the PROXMOX VE GUI, the console can't connect to server, however when I ssh from outside doing ssh user@ip it works.
The GUI opens a Console window that connects to a Serial interface, not SSH. Your TF template has no mention of the serial console. Perhaps your VM Template does, we don't know since you have not posted what you are actually cloning.

Now that you created a template - clone it manually via PVE, boot the clone and see if it works to your satisfaction. If something is not working - continue working on it, without TF, until your are happy. When you know that manual clone works, then TF clone should work too.

Good luck


Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox