How to merge dynamic and static configuration?

I use the telmate/proxmox module to roll out hosts on Proxmox servers. I would now like to make this more flexible, but I have a problem.:

I have the following block within a proxmox_vm_qemu resource:

     disks {
        ide {
            ide3 {
                cloudinit {
                    storage = "${each.value.vm_storage_name}"
                }
            }
        }
        scsi {
             scsi0 {
                 disk {
                    storage = "${each.value.vm_storage_name}"
                    size = each.value.vm_disk_size
                    size = each.value.vm_disks.0.size
                    format = "${each.value.vm_storage_name}" == "local" ? "qcow2" : null
                }
            }
        }
     }

Now I want to flexibilize it, which would work in my specific case with the following block:

    dynamic "disk" {
        for_each = [ for disk in each.value.vm_disks: disk ]

        content {
            slot = disk.value.slot
            size = disk.value.size
            storage = "${each.value.vm_storage_name}"
            format = "${each.value.vm_storage_name}" == "local" ? "qcow2" : null
        }
    }

Now I have the problem that I have to add the cloud init again. In previous modul versions, I would have done this using the cloudinit_cdrom_storage key, but this has been removed in the current module version.

How can I bring the static and dynamic parts together? If I mix the two, I get an error message from Terraform.

Hi @mb-scwi,

I think we’re going to need a more complete example in order to understand what you’re asking. For starters you mention the cloudinit_cdrom_storage key, but it’s not in the configuration you’ve presented, so it’s not apparent what you want to do with that key. You also mention an error from Terraform, but you did not show what the error was or how you got that error.

Hey :slight_smile:

The merror i has mentioned is a message, which tells me, that dynamic and static configuration can’t be mixed.

To simplify my request:

I have an object with values (size drive, type etc.) which are set in a configuration file per host, this is ${each.value}. In addition to this, I would like to create a cloud init drive for each host in any case. However, I don’t want to store the values for this as a configuration for each host, because the drive is always needed anyway and should therefore also be set. I would therefore like to mix a static configuration with a dynamic configuration.

The key cloudinit_cdrom_storage from the Proxmox module would have made it easier for me, but in the end it is not so relevant for my question here. In the end, I just want to know how I can combine a dynamic part with a static part for the disks section.

Sorry, I’m not able to understand what the issue might be, the exact config and error would be very helpful. You can have a combination of dynamic and single block declarations in the configuration, or you could combine the static data into the for_each argument of the dynamic block, but either way allows to to mix two input sources.

If we could see what you tried, and the error it causes, it would help determine why Terraform isn’t allowing you to proceed.

Now, I tried this:


    dynamic "disk" {
        for_each = [ for disk in each.value.vm_disks: disk ]

        content {
            slot = disk.value.slot
            size = disk.value.size
            storage = "${each.value.vm_storage_name}"
            format = "${each.value.vm_storage_name}" == "local" ? "qcow2" : null
        }
    }

    disks {
        ide {
            ide3 {
                cloudinit {
                    storage = "${each.value.vm_storage_name}"
                }
            }
        }
    }

and got this error:

│ Error: Conflicting configuration arguments
│
│   with proxmox_vm_qemu.kubernetes["k8s-wrk-04"],
│   on main.tf line 1, in resource "proxmox_vm_qemu" "kubernetes":
│    1: resource "proxmox_vm_qemu" "kubernetes" {
│
│ "disk": conflicts with disks

It seems, the definition of multiple resources of same type is not possible

"disk": conflicts with disks

Is an error returned by the provider, which means your configuration was evaluated correctly but the provider has rejected it. Peeking at the provider docs, I don’t even see a disks block, so perhaps you have an old provider version and they have since deprecated and removed disks.

Since you can declare multiple disk blocks, and the dynamic block is working, have you tried using that for all your data?

Thank you! So far it wasn’t really to recognice, what is a terraform and what a module function because I’m still new to terraform. But I unterstand it now, thats was a problem with my module code. So far I found now also a working solution:

    dynamic "disk" {
        for_each = each.value.vm_disks
        content {
            slot = disk.value.slot
            size = disk.value.size
            storage = "${each.value.vm_storage_name}"
            format = "${each.value.vm_storage_name}" == "local" ? "qcow2" : null
        }
    }

    disk {
        type = "cloudinit"
        slot = "ide2"
        storage = "local"
    }