Hello
I was able to make a dynamic block for the additional disks. As the iterator I used a list of strings and it worked just fine, no errors. Here the code snippet from that:
variable "additional_disks" {
type = list(string)
}
dynamic "disk" {
for_each = var.additional_disks
content {
label = "disk${sum([index(var.additional_disks, disk.value), 1])}"
size = disk.value
unit_number = sum([index(var.additional_disks, disk.value), 1])
}
}
Now what I wanna do is the same thing but instead of Dynamic Blocks I wanna use just the Meta-Argument for_each in a Data Block and here the same solution doesnβt work. Here my current code that throws an error:
variable "vm_network_interface" {
type = list(string)
}
data "vsphere_network" "network" {
for_each = var.vm_network_interface
name = each.value
datacenter_id = data.vsphere_datacenter.dc.id
}
The error I get is the following:
β Error: Invalid for_each argument
β
β on data.tf line 16, in data "vsphere_network" "network":
β 16: for_each = var.vm_network_interface
β βββββββββββββββββ
β β var.vm_network_interface is list of string with 2 elements
β
β The given "for_each" argument value is unsuitable: the "for_each" argument must be a map, or set of strings, and you
β have provided a value of type list of string.
Anyone have any experience with this? I know the workaround is just to use a map or a set but I am just confused why one works but the other doesnt. is for_each not equals for_each here?