Generate blocks dynamically #2318
Replies: 3 comments 1 reply
-
Hi @StoffelCPR you could use a |
Beta Was this translation helpful? Give feedback.
-
I don't think that would work, what @StoffelCPR wants to achieve is to have dynamically generated block names. As far as I'm aware, you can't use count like This solution is by no means pretty, but given the data structure of proxmox vm it's probably the only solution aside from making a PR to them to introduce alternative structure based on properties, not blocks. variable "additional_disks" {
type = map(object({ size = string }))
default = {
"scsi1" = { size = "20G" },
"scsi2" = { size = "15G" }
}
}
resource "proxmox_vm_qemu" "virtualmachine" {
# ...
disks {
scsi0 {
size = var.main_disk_size
storage = var.storage
}
dynamic "scsi1" {
for_each = { for k, v in var.dynamic_disks : k => v if k == "scsi1" }
content {
size = scsi1.value.size
}
}
dynamic "scsi2" {
for_each = { for k, v in var.dynamic_disks : k => v if k == "scsi2" }
content {
size = scsi2.value.size
}
}
# ...
dynamic "scsi20" {
for_each = { for k, v in var.dynamic_disks : k => v if k == "scsi20" }
content {
size = scsi20.value.size
}
}
}
} |
Beta Was this translation helpful? Give feedback.
-
Take a look at bgp/terraform-provider-proxmox, I find it to be a lot more extensible than the other proxmox providers |
Beta Was this translation helpful? Give feedback.
-
Introduction
Hello together,
I'm struggling with something and I can't find a solution in the documentation nor can ChatGPT.
I've written my own module to generate virtualmachines inside a Proxmox cluster.
Code basis
My question is about the
disks{}
I have my main disk and a possible cloudinit disk set up for all VMs. They will always be the same.
Some VMs will receive multiple disks for LVM encryption so I need to generate these.
Question
Can I somehow generate additional SCSI disks here with tofu code that depend on a variable?
e.g.
With this variable I'd like to have
scsi1
,scsi2
andscsi3
generated if they're present in theadditional_disks
variable.Any ideas?
Beta Was this translation helpful? Give feedback.
All reactions