Terraform graph beautifier
Command line tool allowing to convert the barely usable output of the terraform graph
command to something more
meaningful and explanatory.
terraform graph raw output |
Processed output |
---|---|
You can download the binary corresponding to the required platform from the release page.
You can also build the binary from the sources:
go install github.com/pcasteran/terraform-graph-beautifier
Finally, you can also use the Docker images available for the Linux and Darwin operating systems:
# Linux
docker pull ghcr.io/pcasteran/terraform-graph-beautifier:latest-linux
# Darwin
docker pull ghcr.io/pcasteran/terraform-graph-beautifier:latest-darwin
cd samples/config1/
terraform init
# Using the binary.
terraform graph | terraform-graph-beautifier \
--output-type=cyto-html \
> config1.html
# Using the Docker image.
terraform graph | docker run --rm -i \
--name terraform-graph-beautifier \
ghcr.io/pcasteran/terraform-graph-beautifier:latest-linux \
--output-type=cyto-html \
> config1.html
The command performs the following:
terraform graph
from
the standard input or the specified file (--input
parameter).--output
parameter). The following output
types (--output-type
parameter) are supported:
The loading of the input graph involves the following steps:
[root] rsc_type.rsc_name
=> module.root.rsc_type.rsc_name
.'
character instead of "
fot the maps keys: buckets["artefacts"]
=> buckets['artefacts']
.--keep-tf-junk
parameter."root.rsc_type.rsc_name"
naming convention.--exclude
parameter, you can repeat it multiple times.An important option is to choose whether to embed a submodule in its parent module or not. The --embed-modules
parameter allows to control this behavior:
As a rule of thumb, --embed-modules=true
works well for small to medium size graphs but for larger ones it can produce
a very dense and compact result with a lot of overlapping nodes and intersecting edges.
Output type | --embed-modules=true |
--embed-modules=false |
---|---|---|
cyto-html | ||
graphviz |
The command uses Go templates to create the HTML output. The following annotations will be replaced during the output generation:
--graph-name
parameter).A basic template, with sensible default values for the graph rendering (style and layout), is provided and is embedded in the binary.
If you want to customize the output, you can provide your own template and specify to use it with
the --cyto-html-template
parameter.
It is good practice to check in your custom templates alongside your Terraform configuration.