blob: 12a471977f0f2ec19de13b3893256596dac24a5f [file] [log] [blame]
---
page_title: terraform graph command reference
description: >-
The `terraform graph` command generates a visual representation of a
configuration or execution plan that you can use to generate charts.
---
# `terraform graph` command
The `terraform graph` command generates a visual representation of a configuration or execution plan that you can use to generate charts. This command uses the DOT language generate graphs. Refer to the [GraphViz documentation](https://graphviz.org/doc/info/lang.html) for additional information.
## Usage
Usage: `terraform graph [options]`
By default the result is a simplified graph which describes only the dependency
ordering of the resources (`resource` and `data` blocks) in the configuration.
The `-type=...` option optionally selects from a number of other graph types
which have more detail, at the expense of also exposing some of the
implementation details of the Terraform language runtime.
Options:
* `-plan=tfplan` - Produce a graph for applying the given plan. Implies `-type=apply`.
* `-draw-cycles` - Highlight any cycles in the graph with colored edges.
This helps when diagnosing cycle errors. This option is supported only when
selecting one of the real graph operaton types using the `-type=...`
option.
* `-type=...` - Selects a specific operation type to show the graph of, instead
of the default resources-only simplified graph.
Can be: `plan`, `plan-refresh-only`, `plan-destroy`, or `apply`.
## Generating Images
The graph output uses
[the DOT language](https://en.wikipedia.org/wiki/DOT_(graph_description_language)),
which is a machine-readable graph description language which originated in
[Graphviz](https://graphviz.org/). You can use the Graphviz `dot` command
to present the resulting graph description as an image. There are also various
third-party online graph rendering services which accept this format.
If you have the Graphviz `dot` command already installed, you can render
a PNG image by piping into that command:
```shellsession
$ terraform graph -type=plan | dot -Tpng >graph.png
```
The following is an example result:
![A visualization of the plan graph of a hypothetical Terraform configuration, produced by dot](/img/docs/graph-example.png)