Hi all,
I’m trying to iterate 2x variables and turn them into something that is suitable for another resource I have to use in a for_each/dynamic block. I think I’m getting lost because of the different types - one is a map containing lists of objects, the other is a map of objects containing various types.
Here’s an example:
targets = {
functions = [
{
name = "f1"
group = "rgp3"
},
{
name = "f2"
group = "rgp3"
}
]
databases = [
{
name = "sql1"
group = "rgp1"
}
{
name = "sql2"
group = "rgp1"
}
]
}
metrics = {
functions = {
folder = "Tests"
panels = [
{
alert = true
metric = "executionCount"
},
{
alert = true
metric = "Connections"
}
]
},
databases = {
folder = "Tests"
panels = [
{
alert = true
metric = "CPU%"
},
{
alert = true
metric = "Memory%"
}
]
}
I’m trying to get to a point where I have an element to iterate over for each individual target in var.targets
that also contains info about each of the corresponding metrics it has for var.metrics
.
For example, something like this:
new_var = [
{
name = "f1"
resource_group = "rgp3"
type = "functions"
metric = "executionCount"
},
{
name = "f1"
resource_group = "rgp3"
type = "functions"
metric = "Connections"
},
{
name = "f2"
resource_group = "rgp3"
type = "functions"
metric = "executionCount"
},
{
name = "f2"
resource_group = "rgp3"
type = "functions"
metric = "Connections"
},
{
name = "sql1"
resource_group = "rgp1"
type = "databases"
metric = "CPU%"
},
{
name = "sql1"
resource_group = "rgp1"
type = "databases"
metric = "Memory%"
},
etc...
]
I can get pretty close but I’m reaching my terraform expression knowledge limit