liveBook · Manning

Graph

As explained in Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu

A graph is a representation of entities and the relationships between them as vertices and edges.

A graph represents entities as nodes and their relationships as edges. Edges may be directed, showing one-way relationships, or undirected; graphs may also be acyclic or cyclic. section 5.1.1

Terraform uses directed acyclic graphs (DAGs) to model resource dependencies and plans. A dependency edge indicates which resource must be handled before another, making relationships that are not obvious from configuration visible. section 5.1.1 section 5.8

Use graph terminology to reason about Terraform behavior:

  • Nodes represent resources or other entities. section 5.1.1
  • Edges represent relationships; directed edges commonly express resource dependencies. section 5.1.1
  • Acyclic graphs contain no circular path; circular dependencies can be difficult to locate without inspecting the graph. section 5.1.1 section 5.2.2

Visualizing a Terraform graph

Run `terraform graph` to emit a GraphViz representation. Pipe it to `dot` to create an image, such as `terraform graph | dot -Tpng > graph.png`. The `-type` option selects plan, plan-refresh-only, plan-destroy, or apply graphs. Apply graphs require a saved plan; otherwise, a bug can produce an empty graph. section 5.2.2

Table 5.1 Outputting graphs in different formats (view table figure)

File output

Command

GraphViz dot file

terraform graph > graph.dot  

SVG

terraform graph | dot -Tsvg > graph.svg  

PNG

terraform graph | dot -Tpng > graph.png  

Compare commands for producing DOT, SVG, and PNG graph output. section 5.2.2

How Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu covers it

How deep it goes
Defines nodes, edges, direction, and cycles, then demonstrates visualization but stops short of graph-construction internals.
Examples
Uses family trees, organization charts, social media relationships, Terraform TLS modules, and DOT-to-image commands.
What it assumes
Introduces graph terminology from basic relationships before applying it to Terraform resources and plans.
What you can do after
Diagnose resource dependencies and circular-dependency errors by generating Terraform graph visualizations.
How it connects
Connects graphs with directed graphs, acyclic graphs, dependency graphs, Terraform plans, Terraform apply, and GraphViz.

Also explained in

Compare how 21 books explain graph →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu. The section links point to the parts of the book it draws on.