Output

The output resource allows you to define output variables which can be used to return values from modules. These output resources are module scoped so can be specified in multiple modules without affecting each other.

output "KUBECONFIG" {
  value = resource.kubernetes_cluster.dev.kubeconfig
}

Outputs can contain any type of value. The following output sets a list of numbers.

output "list" {
  value = [1,2,3] 
}

This can be consumed using the following interpolation. Note: Indexes for lists are 0 based.

output "list_value" {
  value = output.list.2 // 3
}

The following output sets a map of values.

output "map" {
  value = {
    list = [1,2,3]
    string = "hello world"
    submap = {
      foo = "bar"
    }
  }
}

This can be consumed using the following interpolation.

output "map_value_1" {
  value = output.map.list.2 // 3
}

output "map_value_2" {
  value = output.map.string // hello world
}

output "map_value_3" {
  value = output.map.submap.foo // bar
}

Last updated