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

Disk support using blocks #1198

Open
k0eff opened this issue Dec 8, 2024 · 2 comments
Open

Disk support using blocks #1198

k0eff opened this issue Dec 8, 2024 · 2 comments
Labels
resource/qemu Issue or PR related to Qemu resource type/question Issue needs no code to be fixed, only a description on how to fix it yourself

Comments

@k0eff
Copy link

k0eff commented Dec 8, 2024

Hi,

I have the following architecture:

  • a vm that I use as a template. it contains a single small disk that is cloned when a new vm is created.
  • a config of what VMs I need to create - which is similar to this one
proxmox_virtual_machines = {
    testvm1 = {
        name = "vm500"
        vmid = 500
        target_node = "proxmox"
        clone = "vm200"
        memory = 3072
        balloon = 1024
        sockets = 1
        cores = 1
        vcpus = 1
        disks = {
            scsi1 = {
                size = "40G"
                storage = "local-lvm"
            }
            scsi2 = {
                size = "45G"
                storage = "local-lvm"
            }
        }
    }
}

By design the module looks like:

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

    name = each.value.name
    vmid = each.value.vmid
    target_node = each.value.target_node
    clone = each.value.clone
    memory = each.value.memory
    balloon = each.value.balloon
    sockets = each.value.sockets
    cores = each.value.cores
    vcpus = each.value.vcpus
    cpu_type = "host"
    vm_state = "started"

    disks {
      scsi {
        scsi0 {
          passthrough {
            file = each.value.clone != null ? "local-lvm:vm-${each.value.vmid}-disk-0" : null
          }
        }
        scsi1 {
          disk {
            size = "40G"
            storage = "local-lvm"
          }
        }
        scsi2 {
          disk {
            size = "45G"
            storage = "local-lvm"
          }
        }
      }
    }

    boot = "order=scsi0"

}

terraform {
  required_providers {
    proxmox = {
      source  = "Telmate/proxmox"
      version = "3.0.1-rc6"
    }
  }
}

The first disk will always be the cloned one. The other disks will always be attached at other scsi ports.
In order to achieve this, a dynamic block of "scsiX" needs to be used, however Terraform has the limitation that dynamic blocks can't have a dynamic name.

Do you have any suggestions to how to overcome this limitation?
My opinion is these should become resources rather than blocks. Blocks are not consistently supported at language level in Terraform. You can't have blocks with dynamic names. You can't have empty blocks due to having required parameters in them. It's just not very well supported.
Will be happy to hear other opinions or suggestions.

@Tinyblargon
Copy link
Collaborator

@k0eff specifically for this use case we have the disk property. It essentially puts all disk related settings in a single item. The downside of this is that it doesn't diff as neatly as the disks property.

@Tinyblargon Tinyblargon added type/question Issue needs no code to be fixed, only a description on how to fix it yourself resource/qemu Issue or PR related to Qemu resource labels Dec 8, 2024
@k0eff
Copy link
Author

k0eff commented Dec 10, 2024

Thanks @Tinyblargon - I read the documentation quite a few times, noticed those fields and never realized these have been part of another block.
#1200

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
resource/qemu Issue or PR related to Qemu resource type/question Issue needs no code to be fixed, only a description on how to fix it yourself
Projects
None yet
Development

No branches or pull requests

2 participants