bpg / terraform-provider-proxmox

Terraform / OpenTofu Provider for Proxmox VE
https://registry.terraform.io/providers/bpg/proxmox
Mozilla Public License 2.0
896 stars 140 forks source link

Container volume mount backup flag defaults to true in provider but false in Proxmox, so volume mounts are created with the flag missing. #1323

Closed rjshep closed 6 months ago

rjshep commented 6 months ago

Describe the bug When creating a container with a volume mount, the provider code defaults the backup option to true, and omits it from the API call to Proxmox.

Proxmox's docs say:

"By default additional mount points besides the Root Disk mount point are not included in backups. For volume mount points you can set the Backup option to include the mount point in the backup. Device and bind mounts are never backed up as their content is managed outside the Proxmox VE storage library."

To Reproduce Steps to reproduce the behaviour:

  1. Create a resource of type proxmox_virtual_environment_container, specifying with a volume mount, and backup = true set.

  2. Apply the terraform, then look in Proxmox and not that the volume mount does not have backup=1 specified.

    Screenshot 2024-05-25 at 19 12 28
  3. Destroy the resource and create again, with backup = false

  4. Apply the terraform, in Proxmox the volume mount now says backup=0.

    Screenshot 2024-05-25 at 19 13 02
  5. Change backup = false to backup = true.

  6. Apply the terraform, in Proxmox the volume mount now says backup=1, along various other options set.

    Screenshot 2024-05-25 at 19 14 30

Please also provide a minimal Terraform configuration that reproduces the issue.

resource "proxmox_virtual_environment_container" "test" {
  node_name = "pve1"
  vm_id     = 101

  initialization {
    hostname = "test"

    user_account {
      password = "password"
    }

  }

  disk {
    datastore_id = "local-zfs"
    size         = 1
  }

  operating_system {
    template_file_id = "local:vztmpl/debian-12-standard_12.2-1_amd64.tar.zst"
    type             = "debian"
  }

  mount_point {
    volume = "local-zfs"
    size   = "1G"
    path   = "/mnt"
    backup = "true"
  }
}

Expected behavior When creating a new proxmox_virtual_environment_container resource, with a volume mount and backup=true (or absent), volume mounted in the container should have backup=1 set.

When modifying an existing resource, changing the state of backup=false to backup=true and applying the TF the expected backup=1 appears. Subsequent switch of backup is also correct, it's just the initial creation that doesn't appear correct.

If you agree with my understanding of the expected behaviour then I'm happy to look at a PR to fix.

Screenshots See above.

Additional context Add any other context about the problem here.

bpg commented 6 months ago

Hi @rjshep! 👋🏼

Yes, you're right, and thanks for reporting this 👍🏼 I've made a small fix in #1327 that should solve the problem.