Before one asks why not change the output to be more friendly or uniform, I would if it came down to it but it will take a lot of effort to change across the board for our environment considering its dealing with terraform states
I'm returning state output from consul for various instances as defined by a variable with values set. The return is giving me this:
"instances" = [
{
"details" = {
"controllers" = {
"pri" = {
"hostname" = "XXXXXXXXXdc001"
"id" = "some_long_ocid_1"
"ip" = "xxx.xxx.xxx.xxx"
}
"sec" = {
"hostname" = "XXXXXXXXXdc002"
"id" = "some_long_ocid_2"
"ip" = "xxx.xxx.xxx.xxx"
}
}
"domain" = "xxxxxxxxxxxxx.org"
"smbdomain" = "XXXXX"
}
},
{
"xxxxxxxxxxxx000" = {
"id" = "some_long_ocid_3"
"ip" = "xxx.xxx.xxx.xxx"
}
},
{
"xxxxxxxxxxxx001" = {
"id" = "some_long_ocid_4"
"ip" = "xxx.xxx.xxx.xxx"
}
}
]
Each of the objects are individual terraform state outputs for instances. What I'm trying to do (without having to just grab everything from OCI and store all of that into my state file) is grab the attribute "id" from each state file, however whoever designed the domain controller state file output did not consider other sources using the state file for cohesion and so now I'm left to try and figure this out and be somewhat uniform across the board. Is there a way within terraform to pull this data in, and massage it in such a way to which I can store the output in a local variable like this:
"instances" = [
"some_long_ocid_1",
"some_long_ocid_2",
"some_long_ocid_3",
"some_long_ocid_4"
]
Any help on this would be greatly appreciated