I have the following output example:
+ test = [
+ {
+ hostname1 = "ocid...asdf"
+ hostname2 = "ocid...fdsa"
+ {
+ hostname3 = "ocid...qwer"
+ hostname4 = "ocid...rewq"
+ {
+ hostname5 = "ocid...zxcv"
+ hostname6 = "ocid...vcxz"
I would like my output to look like this:
+ test = [
+ hostname1 = "ocid...asdf"
+ hostname2 = "ocid...fdsa"
+ hostname3 = "ocid...qwer"
+ hostname4 = "ocid...rewq"
+ hostname5 = "ocid...zxcv"
+ hostname6 = "ocid...vcxz"
I’ve tried using the merge function, but that doesn’t seem to work. Here’s the terraform code the produces the first output:
locals {
backends =
[
{
hostname1 = {
id = "ocid...asdf"
ip = "someIPAddress"
}
hostname2 = {
id = "ocid...fdsa"
ip = "someIPAddress"
}
}
{
hostname3 = {
id = "ocid...qwer"
ip = "someIPAddress"
}
hostname4 = {
id = "ocid...rewq"
ip = "someIPAddress"
}
}
{
hostname5 = {
id = "ocid...zxcv"
ip = "someIPAddress"
}
hostname6 = {
id = "ocid...vcxz"
ip = "someIPAddress"
}
}
]
output "test" {
value = flatten([ for key, value in local.backends : merge({ for k, v in value : k => v.id }) ])
}
Not sure what I’m doing wrong, I feel like I’m close but I just don’t know what I need to do next.