TheGameProfi / terraform-provider-proxmox

Terraform provider plugin for proxmox
MIT License
32 stars 1 forks source link

Version 2.10.0 drops template cloud-init disk #7

Open D-J-See opened 7 months ago

D-J-See commented 7 months ago

Hi there @TheGameProfi. Appreciate your work on this fork! I have tried to get version 2.10.0 working, but the provider does not carry over the cloud-init disk (ide0) from the template. Works fine on 2.9.16. I am not sure if this is expected behavior and the cloud-init disk needs to be defined in terraform instead of from the template? Incase you need more details: PVE version 8.1.4 Template is AlmaLinux 9.3 built using Packer with create cloud-init option set.

main.tf:

resource "proxmox_vm_qemu" "proxmox_vm" {
  for_each = var.buildhost

  agent       = 1
  vmid        = each.value.id
  name        = each.key
  target_node = each.value.target_node
  clone       = var.build_common.template
  onboot      = var.build_common.autostart
  cores       = each.value.cores
  sockets     = each.value.sockets
  cpu         = "host"
  os_type     = "cloud-init"
  memory      = each.value.memory
  scsihw      = "virtio-scsi-pci"
  bootdisk    = "scsi0"
  disks {
    scsi {
      scsi0 {
        disk {
          size    = each.value.disk_1_size_gb
          storage = each.value.datastore
          format  = "raw"
        }
      }
      scsi1 {
        disk {
          size    = each.value.disk_2_size_gb
          storage = each.value.datastore
        }
      }
    }
  }
  network {
    model   = "virtio"
    bridge  = "vmbr0"
    macaddr = each.value.mac_address
  }
  lifecycle {
    ignore_changes = [
      network,
    ]
  }
  ipconfig0 = "ip=${each.value.ipv4}/24,gw=${each.value.gateway}"
  sshkeys   = module.global.secret.ssh_ed25519_key

  provisioner "local-exec" {
    command = "ansible-playbook /root/admin/config/playbooks/${each.key}.yml --extra-vars='target_host=${each.key}'"
  }
  provisioner "remote-exec" {
    inline     = ["shutdown now"]
    on_failure = continue
    connection {
      type        = "ssh"
      user        = "root"
      private_key = file("/root/.ssh/id_ed25519")
      host        = each.key
    }
  } 
}

EDIT: Have updated the template config to not add the cloud-init disk and instead set cloudinit_cdrom_storage in the vm resource. Personally happy to stick with this configuration, as at the end of the day doesn't really matter at what stage the cloud-init disk is added, and is not the untidiest workaround :)

TheGameProfi commented 7 months ago

I can also replicate the issue. And i am currently trying to find out how and why its happening.

For reference on the original repo is a issue referring the same issue Telmate/terraform-provider-proxmox#901

TheGameProfi commented 7 months ago

I was able to get a closer look whats happening.

There is some kind of update of the VM after the rezize: update VM 104: -agent 1 -bios seabios -cores 1 -cpu host -description terraform test -hotplug network,disk,usb -ide2 none,media=cdrom -kvm 1 -memory 2048 -name Could be related to the changes of this commit: 90e6dba2013de3aeb4db8395daa3fad371b9d621

JuSchi89 commented 7 months ago

same problem with cloud-init, I get an error that cloud init drive is already attached to scsi1 (thats correct for my template, but didn't tell terraform about any location. Result is that I get an unused disk.

interestingly, when I put:

    scsi {
      scsi1 {
        cdrom {
        }
      }
    }

Then, I don't get any error. But even though I set cloudinit_cdrom_storage and efidisk storage to my desired storage, it's ignored and the efi+cloudinit drives appear on my local storage (this is where my template points).

Then I thought ok I change my template to my desired storage but this also didn't work. Results are kinda weird, EFI drive was fine but now I have 2 unused disks, my disk image and interestingly another EFI disk, cloudinit drive not visible at all.

For now going back to v2.9.16, here everything works for me.

TheEmpty commented 7 months ago

To cross-pollinate here- for those looking for a quick-fix and willing to make changes, from the Discord server,

I am using 2.10 release the work around for cloud init was just to delete the cloud init drive from the temple before using it to create vms with terraform. Since I have a backup of the template it wasn't a big deal. Just glad to see the community solve these issues. I have very limited programming skills but I've wanted to learn go and this project added a reason to the list!

ManCreature @ 01/20/2024 11:58 AM


I confirmed this on my end as well, removing cloud drive from the template causes the host to start its boot process. For me the issue was with no DHCP it was unable to reach out to the timeserver and continue (and I'm alright waiting awhile for a fix so I didn't go any further down this).

TheGameProfi commented 7 months ago

Since the Telmate Repo has a new release, I would archive this repo. The new Release should also a fix for that