Hello Terraform community,
I am trying to workaround the known limitations with terraform for_each arguments by using a Map instead of a Set. I have found this suggested and have done this several times already but currently I am facing the problem that my workaround seems fine with a single Set element but does not work with multiple elements.
This is the HCL code I am using.
variable "allowed_groups" {
type = set(string)
}
locals {
allowed_groups_map = { for idx, val in tolist(var.allowed_groups) : idx => val }
}
resource "test_resrouce" {
for_each = length(local.allowed_groups_map) != 0 ? local.allowed_groups_map : map("0", data.okta_group.everyone.id)
}
I created Outputs to debug this behaviour:
# 1 String item in the given Set
allowed_groups_map = {
+ "0" = (known after apply)
}
# 2 string items in the given Set
allowed_groups_map = (known after apply)
What I would have expected and I do not understand why I do not get this result with 2 Set elements:
allowed_groups_map = {
+ "0" = (known after apply)
+ "1" = (known after apply)
}
Does anybody know what I am doing wrong here?
Or is this actual a bug/known behaviour?
Any input appreciated!
Thanks