Output values expose the attributes stored in local resources for external consumption. This can be a confusing process at first glance.

Uses of output values

Let’s look at a few uses for outputs.

  • A child module can use outputs to expose a subset of its resource attributes to a calling module.
  • A root module can use outputs to print certain values in the CLI output after running terraform apply.
  • When using a remote state, root module outputs can be accessed by other configurations via a terraform_remote_state data source.

When we create a resource in a module, the attributes of that resource can be referenced throughout the rest of that module. However, those attributes aren’t directly available for consumption by other modules or as a data source when using remote state. Output values are a way to name, transform, and expose the information stored in attributes to the consumer of our module. If an attribute isn’t exposed as an output, it’s not available to a calling module.

An output value exported by a module is declared using an output block. The example below shows one of the outputs of the official vpc module.

Get hands-on with 1200+ tech skills courses.