Terraform - Create output from a resource's metadata attribute

Viewed 141

I have a resource which is currently using a for_each statement to loop through values in a variable.

I am attempting to take the metadata attributes and create an output value but I can't seem to properly index the objects from the metadata. The only thing I have gotten to work is below but there is excess data that is not needed.

Outputs.tf

 output "namespace" {
 value = [for namespace in helm_release.jupyterhub[*]: namespace]
 }

This outputs a list of two objects.

namespace = [
  {
    "class1" = {
      "namespace" = "name1"
    }
    "class2" = {
      "namespace" = "name2"
    }
  },
]

I have tried to figure this out for a bit but can't seem to properly get just the namespace value. Is this a nested map that I need more indexing logic on with my for loop?

1 Answers

Figured this out after some more trial and error with a nested for loop.

 value = [for namespace in helm_release.jupyterhub[*]:
           for i in namespace: i.namespace]

This should output ["name1", "name2"].

Related