The post below shows how to create security policy groups for NSX-T with Terraform nested for_each loop and dynamic.
The variables are made from one map of list. Each list represents one group composed of tags.
https://www.hashicorp.com/blog/hashicorp-terraform-0-12-preview-for-and-for-each
variable "mapgroups" {
type = map
default = {
NBO = ["NBO"]
NBO-PROD = ["NBO","PROD"]
}
}
resource "nsxt_policy_group" "nbogroups" {
for_each = var.mapgroups
display_name = each.key
criteria {
dynamic "condition" {
for_each = each.value
content {
key = "Tag"
member_type = "VirtualMachine"
operator = "EQUALS"
value = condition.value
}
}
}
}