2014-07-25 00:44:10 +02:00
|
|
|
---
|
2021-12-15 03:41:17 +01:00
|
|
|
page_title: 'Command: graph'
|
|
|
|
description: >-
|
|
|
|
The terraform graph command generates a visual representation of a
|
|
|
|
configuration or execution plan that you can use to generate charts.
|
2014-07-25 00:44:10 +02:00
|
|
|
---
|
|
|
|
|
|
|
|
# Command: graph
|
|
|
|
|
|
|
|
The `terraform graph` command is used to generate a visual
|
|
|
|
representation of either a configuration or execution plan.
|
|
|
|
The output is in the DOT format, which can be used by
|
2014-07-25 21:41:27 +02:00
|
|
|
[GraphViz](http://www.graphviz.org) to generate charts.
|
2014-07-25 00:44:10 +02:00
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
main: new global option -chdir
This new option is intended to address the previous inconsistencies where
some older subcommands supported partially changing the target directory
(where Terraform would use the new directory inconsistently) where newer
commands did not support that override at all.
Instead, now Terraform will accept a -chdir command at the start of the
command line (before the subcommand) and will interpret it as a request
to direct all actions that would normally be taken in the current working
directory into the target directory instead. This is similar to options
offered by some other similar tools, such as the -C option in "make".
The new option is only accepted at the start of the command line (before
the subcommand) as a way to reflect that it is a global command (not
specific to a particular subcommand) and that it takes effect _before_
executing the subcommand. This also means it'll be forced to appear before
any other command-specific arguments that take file paths, which hopefully
communicates that those other arguments are interpreted relative to the
overridden path.
As a measure of pragmatism for existing uses, the path.cwd object in
the Terraform language will continue to return the _original_ working
directory (ignoring -chdir), in case that is important in some exceptional
workflows. The path.root object gives the root module directory, which
will always match the overriden working directory unless the user
simultaneously uses one of the legacy directory override arguments, which
is not a pattern we intend to support in the long run.
As a first step down the deprecation path, this commit adjusts the
documentation to de-emphasize the inconsistent old command line arguments,
including specific guidance on what to use instead for the main three
workflow commands, but all of those options remain supported in the same
way as they were before. In a later commit we'll make those arguments
produce a visible deprecation warning in Terraform's output, and then
in an even later commit we'll remove them entirely so that -chdir is the
single supported way to run Terraform from a directory other than the
one containing the root module configuration.
2020-09-02 00:45:12 +02:00
|
|
|
Usage: `terraform graph [options]`
|
2014-07-25 00:44:10 +02:00
|
|
|
|
2021-02-02 19:09:30 +01:00
|
|
|
Outputs the visual execution graph of Terraform resources according to
|
|
|
|
either the current configuration or an execution plan.
|
2015-04-23 20:24:26 +02:00
|
|
|
|
|
|
|
The graph is outputted in DOT format. The typical program that can
|
|
|
|
read this format is GraphViz, but many web services are also available
|
|
|
|
to read this format.
|
2014-12-14 09:21:43 +01:00
|
|
|
|
2021-02-02 19:09:30 +01:00
|
|
|
The `-type` flag can be used to control the type of graph shown. Terraform
|
2016-12-04 00:29:04 +01:00
|
|
|
creates different graphs for different operations. See the options below
|
|
|
|
for the list of types supported. The default type is "plan" if a
|
|
|
|
configuration is given, and "apply" if a plan file is passed as an
|
|
|
|
argument.
|
|
|
|
|
2014-12-14 09:21:43 +01:00
|
|
|
Options:
|
|
|
|
|
2021-02-02 19:09:30 +01:00
|
|
|
* `-plan=tfplan` - Render graph using the specified plan file instead of the
|
2021-12-15 03:41:17 +01:00
|
|
|
configuration in the current directory.
|
2021-02-02 19:09:30 +01:00
|
|
|
|
2015-04-23 20:24:26 +02:00
|
|
|
* `-draw-cycles` - Highlight any cycles in the graph with colored edges.
|
2021-12-15 03:41:17 +01:00
|
|
|
This helps when diagnosing cycle errors.
|
2015-04-23 20:24:26 +02:00
|
|
|
|
2019-03-22 00:44:00 +01:00
|
|
|
* `-type=plan` - Type of graph to output. Can be: `plan`, `plan-destroy`, `apply`,
|
2021-12-15 03:41:17 +01:00
|
|
|
`validate`, `input`, `refresh`.
|
2015-04-23 20:24:26 +02:00
|
|
|
|
2020-01-08 22:33:30 +01:00
|
|
|
* `-module-depth=n` - (deprecated) In prior versions of Terraform, specified the
|
2021-12-15 03:41:17 +01:00
|
|
|
depth of modules to show in the output.
|
2020-01-08 22:33:30 +01:00
|
|
|
|
2014-07-25 00:44:10 +02:00
|
|
|
## Generating Images
|
|
|
|
|
|
|
|
The output of `terraform graph` is in the DOT format, which can
|
|
|
|
easily be converted to an image by making use of `dot` provided
|
|
|
|
by GraphViz:
|
|
|
|
|
2021-02-02 19:09:30 +01:00
|
|
|
```shellsession
|
2018-03-09 01:22:21 +01:00
|
|
|
$ terraform graph | dot -Tsvg > graph.svg
|
2014-07-25 00:44:10 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
Here is an example graph output:
|
2021-12-15 03:41:17 +01:00
|
|
|
![Graph Example](/img/docs/graph-example.png)
|