Reputation: 179
In the below terraform code I am trying to create groups with single block. Now I am using 0,1 2 separate blocks to create. Is there any other method to create group with single block. I tried with flatten but of no luck
locals {
instances = [
{
instance = "test1"
baseUrl = "url"
subDomain = "sd"
groups = [
"app1",
"app2",
"app3",
]
},
{
instance = "test2"
baseUrl = "url2"
subDomain = "sd2"
groups = [
"t1",
"t2",
"t3",
]
},
]
}
resource "okta_group" "press" {
for_each = { for k, instance in local.instances[0].groups : k => instance ]
name = each.value
}
resource "okta_group" "press1" {
for_each = { for k, instance in local.instances[1].groups : k => instance ]
name = each.value
}
Upvotes: 1
Views: 12973
Reputation: 103
I got the same result as if I were using flatten:
for_each = { for k, instance in local.instances[*].groups : k => instance }
Upvotes: 0
Reputation: 24251
In simple terms: You need to provide a single (flat) list to for_each
. It doesn't accept list of lists or any other data structure.
Try:
for_each = { for k, instance in flatten(local.instances[*].groups) : k => instance}
which uses:
flatten
- an operation to convert list of lists to a list[*]
- what they call a splat expressionI suggest reading up on these.
Upvotes: 4