Telmate / terraform-provider-proxmox

Terraform provider plugin for proxmox
MIT License
2.13k stars 513 forks source link

`proxmox_cloud_init_disk` update fails after `*_data` file changes #1048

Open maksimsamt opened 3 months ago

maksimsamt commented 3 months ago

System details:

New resource creation works as expected, as per cloud_init_disk.md.

When trying to update some data in *_data, for example, in user_data package_upgrade parameter, terraform apply fails:

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  ~ update in-place
-/+ destroy and then create replacement

Terraform will perform the following actions:

  # proxmox_cloud_init_disk.ci must be replaced
-/+ resource "proxmox_cloud_init_disk" "ci" {
      ~ id             = "cephfs:iso/tf-ci-***.iso" -> (known after apply)
        name           = "***"
      ~ sha256         = "***" -> (known after apply)
      ~ size           = "44K" -> (known after apply)
      ~ user_data      = <<-EOT # forces replacement
            #cloud-config
            users:
              - default
            manage_etc_hosts: true
            user: ***
            password: ***
            chpasswd:
              expire: false
          - package_upgrade: true
          + package_upgrade: false
        EOT
        # (4 unchanged attributes hidden)
    }

  # proxmox_vm_qemu.cloud_vm_from_packer_template will be updated in-place
  ~ resource "proxmox_vm_qemu" "cloud_vm_from_packer_template" {
        id                     = "***/qemu/***"
        name                   = "***"
        tags                   = "***"
        # (67 unchanged attributes hidden)

      ~ disks {
          ~ scsi {
              ~ scsi11 {
                  ~ cdrom {
                      ~ iso         = "cephfs:iso/tf-ci-***.iso" -> (known after apply)
                        # (1 unchanged attribute hidden)
                    }
                }

                # (1 unchanged block hidden)
            }
        }

        # (3 unchanged blocks hidden)
    }

Plan: 1 to add, 1 to change, 1 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

proxmox_cloud_init_disk.ci: Destroying... [id=cephfs:iso/tf-ci-***.iso]
proxmox_cloud_init_disk.ci: Destruction complete after 0s
proxmox_cloud_init_disk.ci: Creating...
╷
│ Error: import failed: cp: cannot create regular file '/mnt/pve/cephfs/template/iso/tf-ci-***.iso': File exists
│ 
│   with proxmox_cloud_init_disk.ci,
│   on main.tf line 19, in resource "proxmox_cloud_init_disk" "ci":
│   19: resource "proxmox_cloud_init_disk" "ci" {

There seems to be some a wrong logic/order in the update operation.

Now it looks like:

But should be:

maksimsamt commented 3 months ago

@Tinyblargon, Please take a look on this issue.