Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idempotent disk change plan / apply - v3.0.1-rc6 #1207

Open
eferrandi31 opened this issue Dec 20, 2024 · 2 comments
Open

Idempotent disk change plan / apply - v3.0.1-rc6 #1207

eferrandi31 opened this issue Dec 20, 2024 · 2 comments
Labels
issue/not-a-bug The reported issue is the intended behavior or the problem is not inside this project

Comments

@eferrandi31
Copy link

Hello,

First of all, thanks for your job, it's well described and works fine !

However, there is a problem of idempotence in the declaration of disks.

When I create my VM, all disks are correctly declared:

  • 2 SCSI disks: VM
  • 1 IDE disk: cloud-init

image

When I run terraform again, the plan shows me these changes:

Terraform will perform the following actions:

  # module.vm_minimal_config.proxmox_vm_qemu.vm will be updated in-place
  ~ resource "proxmox_vm_qemu" "vm" {
        id                     = "proxmox-1/qemu/103"
        name                   = "vm-example-minimal"
        # (43 unchanged attributes hidden)

      ~ disk {
          ~ discard              = false -> true
            id                   = 0
          ~ iothread             = false -> true
          + size                 = "50G"
          ~ slot                 = "ide2" -> "scsi0"
          ~ type                 = "cloudinit" -> "disk"
            # (17 unchanged attributes hidden)
        }
      ~ disk {
          - format               = "raw" -> null
            id                   = 0
          ~ slot                 = "scsi0" -> "scsi1"
            # (21 unchanged attributes hidden)
        }
      ~ disk {
          - discard              = true -> null
          - format               = "raw" -> null
            id                   = 1
          - iothread             = true -> null
          ~ slot                 = "scsi1" -> "ide2"
          ~ type                 = "disk" -> "cloudinit"
            # (18 unchanged attributes hidden)
        }
        # (4 unchanged blocks hidden)
    }

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

Whereas when I do an apply, no changes are made, but I get this warning:

module.vm_minimal_config.proxmox_vm_qemu.vm: Modifying... [id=proxmox-1/qemu/103]
module.vm_minimal_config.proxmox_vm_qemu.vm: Modifications complete after 1s [id=proxmox-1/qemu/103]
│ Warning: slot: ide2 size is ignored when type = cloudinit
│
│   with module.vm_minimal_config.proxmox_vm_qemu.vm,
│   on .terraform/modules/vm_minimal_config/main.tf line 11, in resource "proxmox_vm_qemu" "vm":
│   11: resource "proxmox_vm_qemu" "vm" {
│
Apply complete! Resources: 0 added, 1 changed, 0 destroyed.

Could you correct this idempotence issue ?

@eferrandi31
Copy link
Author

Here is my main code :

module "vm_minimal_config" {
...
  data_disks      = [{ "id": 0, "size": 50, "disk_pool": "local-lvm"},{ "id": 1, "size": 50, "disk_pool": "local-lvm"}]
...
}

variable "data_disks" {
  type    = list(object({
    id = number
    size = number
    disk_pool = string
  }))
  description = "Size of data disk with GB"
  default = [{ "id":1, "size": 50, "disk_pool": "local-lvm" }]
}

resource "proxmox_vm_qemu" "vm" {
...
  dynamic "disk" {
    for_each = [ for disk in var.data_disks: disk ]
    content {
      type     = "disk"
      slot     = "scsi${disk.value.id}"
      storage  = "${disk.value.disk_pool}"
      size     = "${disk.value.size}G"
      iothread  = true
      discard   = true
    }
  }
  disk{ 
    type    = "cloudinit"
    slot    = "ide2"
    storage = "local-lvm"
  }
...

@Tinyblargon
Copy link
Collaborator

@eferrandi31 Due to limitations in Terraform, we can't fix this behavior. The disk is an ordered list, as an unordered list has different behaviors. The solution is to put the disks by slot in alphanumeric order in your configuration.

@Tinyblargon Tinyblargon added the issue/not-a-bug The reported issue is the intended behavior or the problem is not inside this project label Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue/not-a-bug The reported issue is the intended behavior or the problem is not inside this project
Projects
None yet
Development

No branches or pull requests

2 participants