liveBook · Manning

Terraform output

As explained in Infrastructure as Code, Patterns and Practices: With examples in Python and Terraform

A Terraform output is a named value exported by a module for access by other configurations or users.

A Terraform output is a named value exported by a module so dependent configurations or users can retrieve selected resource attributes. Outputs create an interface between infrastructure components without requiring direct references to internal resources. section 4.2.1 section 4.3

Use outputs to:

  • Pass a network name, subnet address range, bucket name, or other required attribute to dependent resources. section 4.2.1
  • Limit the information returned by a low-level module while improving composability and evolvability. section 4.2.1
  • Provide an abstraction between high-level and low-level resources through module outputs or infrastructure state. section 4.2.2

Connecting a server to a network

A network module exports its subnet name in terraform.tfstate. A server module reads that output and uses the value to create the server on the correct network. If a queue later needs the subnet IP range, the network module can add that attribute to its outputs. section 4.2.1

Figure 4.8 The facade simplifies attributes to the name of the storage bucket for use by the access control module.

Shows outputs simplifying a storage bucket’s attributes for an access-control module. section 4.3

How Infrastructure as Code, Patterns and Practices: With examples in Python and Terraform covers it

How deep it goes
Explains outputs through dependency patterns, state JSON, and implementation examples, including abstraction trade-offs between modules.
Examples
Uses network names, subnet ranges, server creation, storage buckets, access-control rules, and Terraform state JSON.
What it assumes
Assumes familiarity with modules and resources, while defining inversion of control, dependency inversion, and dependency injection.
What you can do after
Apply it via module outputs to pass infrastructure attributes while reducing direct references between resources.
How it connects
Ties outputs to inversion of control, dependency inversion, dependency injection, facade pattern, and infrastructure state.

Also explained in

Compare how 2 books explain Terraform output →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Infrastructure as Code, Patterns and Practices: With examples in Python and Terraform. The section links point to the parts of the book it draws on.