-
Notifications
You must be signed in to change notification settings - Fork 556
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
[Question] How to use new disk definition format in variable e.g. module #907
Comments
When using resource directly its ok, but when trying to pass it from variable to module and create the disks block - new structure is horrible to work with. It would be nice to include it in documentation. Yes, its a little out of scope of a provider, but I believe it would really help some people, including me. |
Hi, Today I tried to write a terraform module for the new version of the provider, but, unfortunately, I could not bypass all types of disks through dynamic, since it does not know how to work with dynamic variables. Tell me, are there any solutions to be able to remove this lamp into variables? This cannot currently be used to create terraform modules. |
You can take a look at the |
@clincha Unfortunatelly, thats not the solution I, and I think neither @Korney95 are looking for. When you use resource only, as shown in the example you posted - it works as intended, without issues. disks is a block, not a variable to which you would assign another variable from module instance. Thats what makes this hard to do. Define dynamic disks block
Define variable:
And then do use the variable in the module:
Which would then be "parsed" to correct disks block. There is currently no other way to pass it to the resource in the module and its imposible for me to do it correctly. I've spend quite a lot of hours rying to make itwork somehow. |
@hagaram did something happen? Unfortunately, I don't have working examples either. I've tried a lot of things |
Same problem. TF Modulevariables.tf: variable "disks" {
type = map(any)
default = {}
} main.tf: resource "proxmox_vm_qemu" "proxmox_vm" {
....
dynamic "disk" {
for_each = var.disks
content {
size = disk.value.size
type = disk.value.type
storage = disk.value.storage
backup = disk.value.backup
cache = disk.value.cache
}
}
} Module Inputmodule "test-vm" {
source = "git::https://....."
disks = {
"disk1" = {
size = "20G",
type = "virtio",
storage = "datastore_name",
backup = 1,
cache = "directsync",
}
"disk2" = {
size = "30G"
type = "virtio"
storage = "vdatastore_name"
backup = 1
cache = "directsync"
}
}
} |
I have the same problem. I tried to upgrade my code to use the new |
I thought #794 had some insight on how to do this in the comments. |
@Tinyblargon Could you point me to where exactly? From my understanding, the overhaul of the disks block doesn't support dynamic disks based on your comment here: #794 (comment) |
@comminutus it doesn't support dynamic blocks in the traditional sense, but this #794 (comment) explains how you could do it when you use it in a module. |
Thanks for everyone's efforts to progress the Proxmox provider. I'm keen to use the newer v3 release. I've been using the provider to deploy Flatcar Linux VMs with Butane/Ignition configurations. I can see the provider can be used directly in a Terraform script, except I (and others) seem to be using the provider in a Terraform module. I'm thinking the design has been driven by the underlying QEMU/Proxmox Go API, rather than a combination of this and typical uses of the provider. It would be great if there was a test case/example of this (I was trying to get an example of my module deploying and have become stuck). IMHO the new disk configuration is too complex. Looking at the code base, there is a large and deep schema definition for the disks parameter. That said - the design is highly orthogonal. I tried to get ChatGPT to write a definition for a module variable definition given the schema, but it all got too big and repetitive. I know there are design constraints with Proxmox (and QEMU), but it would be great if the disks were a separate resource to the VM. Provisioning disks shouldn't be so coupled to compute resources. I would really like to be able to have disks that have a lifecycle that is independent to the VM - so I can mark them as 'prevent_destroy'. I'm stuck providing an interface to my module to allow the usage of the Proxmox provider. How are people getting this working today? Has anyone written a huge definition for a |
It's technically possible, but you have to code every single possible block with a A friendlier way would have been to flatten it out to an extent, for example instead of
@gbrackley I just hacked it by copy pasting the configuration to the extent that I'm using it. It's ugly but it works... Let's hope this change gets reverted. |
Hi. I too ran into this problem when I decided to upgrade my home lab to version 8, and with it terraform provider. Spent several hours experimenting with dynamic block. But I couldn't think of a better solution than adding an if condition to the block. It forces to use code repetitions, looks not elegant, shame to show such a thing=). But it works. I will show only an example with 4 disks.
That is, in the module you need to describe all 15 potentially used disks, or as many as you plan to use in the VM. |
yuck, I'd much rather stick with the older version with much simpler code. |
I tried to create a few VMs and I wanted have vars like: vm_configs = {
group1 = {
instances = 2
cores = 1
....
disks = {
disk1 = {...}
disk2 = {...}
}
}
group2 = {
instances = 4
cores = 2
....
disks = {
disk1 = {...}
disk2 = {...}
}
}
} and it's not possible with new struct because of |
I have spent 4 days solving this problem and have not come to a normal variant. I can't use disk creation as before without writing a large piece of code, which kills flexibility when using the module. Maybe to return the work with disks as it was before? |
@Tinyblargon As I understand it, you were the initiator of this innovation of working with disks, judging by "Pull requests". And judging by your description in "Bio", then you can suggest the right solution to this problem, which will help a lot of people. |
Any update guys ? |
My two cents, I do not agree with this statement:
Please don't do this! And as proof of concept, below is my example of how dynamic disk blocks can be handled with the latest version of the provider. Implemented and tested on:
Terraform code examples with snippets:
Hope these examples helps you achieve your goals. |
Hey @maksimsamt, I ended up doing a module using dynamics and conditionals, it works indead but it add (i believe) a lot of duplications in the module. |
@maksimsamt , would you mind to share your packer configuration? (I'm stuck in my deployment and I suspect that Iḿ missing something in packer) |
Unfortunately, I don’t think this is the right place to share information about the Packer code/configuration. This is a completely different topic and requires a separate discussion, probably in Hashicorp Packer discussion hub, not here. |
A slightly different approach than #907 (comment), to cover dynamic functionality of
|
up |
@arsensimonyanpicsart |
Hi @Tinyblargon and @maksimsamt, I've been using the Proxmox Terraform provider for a while (I have several github projects using it), and I appreciate the work that goes into maintaining it. However, the recent changes to how disks are defined have significantly complicated my workflow. Previously, I could define disks in a much simpler and more concise way: disk {
type = "scsi"
size = "18G"
storage = "vg_nvme"
ssd = 1
} Or when using dynamic "disk" {
for_each = var.disks
content {
type = disk.value.type
size = disk.value.size
storage = disk.value.storage
ssd = disk.value.ssd
}
} Now, the new structure requires something like this: disks {
scsi {
scsi0 {
disk {
size = 18
storage = "vg_nvme"
emulatessd = true
}
}
}
} When using These changes feel like a step backward in terms of usability. The new approach is more verbose, less intuitive, and makes managing multiple disks a real challenge. It almost feels like the provider isn't being tested in real-world scenarios where simplicity and maintainability are key. I'd like to request a reconsideration of this change or, at the very least, some discussion around making the provider more Thank you for your hard work, and I hope we can find a middle ground that satisfies both usability and the new features. Best regards, |
@lsampaioweb #986 addresses this and how we are planning to change it. A lot of the code is done for it. Hopefully, i can get it ready before the end of the month. |
This issue is stale because it has been open for 60 days with no activity. Please update the provider to the latest version and, in the issue persist, provide full configuration and debug logs |
This issue was closed because it has been inactive for 5 days since being marked as stale. |
Reopen |
@hagaram for the use of disks in modules, we reintroduced the |
Hi, I have terraform proxmox module based on this provider and I have trouble to modify the module definition of a VM resource to work correctly with new disks layout --> #892
How should I correctly define disks block in variable to be able to pass it verbatim, or at least provide such structure, to be able to parse/create the corrects disks block in resource definition inside of the module?
The text was updated successfully, but these errors were encountered: