With this variable:
variable "slo_groups" {
description = "Groups and values"
default = {
"group1" = { sev = ["10", "20", "30"], group = "group1" }
"group2" = { sev = ["10", "20", "40"], group = "group2" }
}
}
I would like to use one resource declaration to create 6 resources, 3 for group1, 3 for group2. With a local variable named slo_pairs, a resouce would look a bit like:
resource "my_resource" "iop_mttr_slos" {
for_each = local.slo_pairs
query = "... ${each.key}}) ... ${each.value} "
}
I’ve been trying to use a nested loop to create a list of maps like:
group1 = 10
group1 = 20
gruop1 = 30
...
If I use this:
locals {
slo_pairs = flatten([
for assignment_group in var.slo_groups : [
for sev in assignment_group.sev : {
group = assignment_group.group
slo_target = assignment_group.sev
}
]
])
group_slo_list = {
for k in local.slo_pairs : k.group => k.slo_target...
}
}
I end up with a tuple, I think like:
{
group1 = [10, 20, 30]
gruop2 = [10,20,30]
}
in which case my tf plan only tries to create 2, rather than 6 values & fails with:
| each.value is tuple with 3 elements
without the elipses, the tf-plan returns duplicate key errors:
Error: Duplicate object key
Seems like what I want to do is possible, but I just don’t see the path. I want to hand the resource a list of pairs. Is this possible?
I’d be happy to work with a more simple variable as well, like:
variable "slo_groups" {
default = {
"group1" = ["10", "20", "30"]
"group2" = ["10", "20", "30"]
}
but trying to work with mapping has seemed to overcomplicate things.