terraform graph: Usage & Common CI Errors
Visualize the resource dependency graph Terraform builds.
terraform graph outputs the dependency graph of your configuration or plan in DOT format, which you can render with Graphviz to debug ordering and cycle problems.
What it does
terraform graph emits a DOT-language description of the graph Terraform uses to order operations. Piped into Graphviz (dot) it becomes an image showing which resources depend on which - invaluable for understanding apply order and locating dependency cycles.
Common usage
# Emit DOT and render to PNG with Graphviz
terraform graph | dot -Tpng > graph.png
# Graph a specific plan
terraform plan -out=tfplan
terraform graph -plan=tfplan | dot -Tsvg > graph.svgCommon error in CI: dot not installed / cycle in graph
The pipeline errors with "dot: command not found" (Graphviz missing on the runner) or, separately, terraform plan reports "Error: Cycle: a -> b -> a". Fix: install Graphviz in CI (apt-get install -y graphviz) before rendering. For a real cycle, use the graph image to find the loop, then break it - usually by removing an unnecessary depends_on or restructuring a reference so dependencies flow one way.
Key options
| Option | Purpose |
|---|---|
| -plan=FILE | Graph a saved plan file |
| -type=TYPE | Graph type (plan, apply, etc.) |
| -draw-cycles | Highlight any dependency cycles |