So we take a variable such as var.node_name and allow the users to input as many node names to build out the vms using for_each. But now we have to add availability zones as an option, the regions we work in azure allow 1,2,3. We need to find a way to assign one zone per vm and if they create more than 3 vms to cycle through the numbers, if that makes sense.
variable "node_name" {}
variable "av_zones" {}
locals {
name = split(",", var.node_name)
}
module "winvm_module" {
for_each = toset(local.name)
source = "../modules/winvm_module"
node_name = each.key
av_zones = var.av_zones
}
I found this article “Using some loop with count and for_each. Availability zones and server count” that looks like I could use range maybe.
locals {
# (I renamed the zones to letters so that they'd
# be more distinct from the instance indices.)
zones = ["a", "b", "c"]
instance_idxs = range(var.itemcount)
instances = flatten([
for z in local.zones : [
for i in local.instance_idxs : {
zone = z
index = i
}
]
])
}
In the example here is there a way to get the range in var.node_names?