bpg / terraform-provider-proxmox

Terraform Provider for Proxmox
https://registry.terraform.io/providers/bpg/proxmox
Mozilla Public License 2.0
793 stars 132 forks source link

Weird behaviour with `file_format` vs. multiple disks #1458

Open morsik opened 2 months ago

morsik commented 2 months ago

Describe the bug Proxmox API complains about using qcow2 with Thin-LVM storage after trying to create VM with 2 disks...

Or rather I should say: Provider does something magical and NOT COMPLAIN when creating first boot disk with wrong qcow2.

To Reproduce This might be kinda hard to explain, as we're using our own module that uses dynamic function, but as a result we're doing this:

  1. Create a resource proxmox_virtual_environment_vm with 1 disk on datastore_id that uses Thin-LVM.
  2. Run terraform apply.
  3. Runs perfectly fine, even thought IT SHOULDN'T because you can't use default qcow2 as file format for Thin-LVM. And disk is actually created as RAW. What's weirder, is that second terraform apply doesn't show any difference even though provider tries to use qcow2 and Proxmox has set raw anyway.
  4. Run terraform destroy (IMPORTANT! as there's no errors when running consecutive applies!).
  5. Add second disk to proxmox_virtual_environment_vm definition.
  6. Run terraform apply again to create everything from scratch with 2 disks (one boot, and second for data).
  7. See (perfectly valid) error this time:
    ╷
    │ Error: error updating VM: received an HTTP 500 response - Reason: unsupported format 'qcow2' at /usr/share/perl5/PVE/Storage/LvmThinPlugin.pm line 87.
    │
    │   with proxmox_virtual_environment_vm.vms["qdrant-3"],
    │   on proxmox.tf line 18, in resource "proxmox_virtual_environment_vm" "vms":
    │   18: resource "proxmox_virtual_environment_vm" "vms" {
    │
    ╵

Manually specifying file_format = "raw" of course works, the issue is not with wrong file_format interpretation, it's about incorrect behaviour with first disk.

Expected behavior Provider should fail at the beginning when boot disk was trying to create with wrong setting.

Additional context

bpg commented 2 months ago

Hi @morsik 👋🏼

  1. Create a resource proxmox_virtual_environment_vm with 1 disk on datastore_id that uses Thin-LVM.

Are you creating an empty disk, or importing some existing disk image via file_id, similar to https://github.com/bpg/terraform-provider-proxmox/blob/76ce03f6142f5811400ba3f3724a9a35decbefc3/docs/resources/virtual_environment_vm.md?plain=1#L40

morsik commented 2 months ago

@bpg great question! I totally forgot about this important detail!

We're cloning VM Template which already contains disk image with Debian and it's correctly resized later to desired size specified in first disk. VM Template disk is on Thin LVM pool.

And no warning/error about wrong format for that disk.