Problem:
Standard output from terraform graph
used to visualize the dependency graph is hard to process when the number of resources is increasing. The readability of the graph decreases fast when using such tools as graphviz
and dot
.
In this post, I will show an alternative tool Terraform visualize which simplifies the graphs and increases the readability.
Example terraform project:
To show differences in the output visual report files, we will use a simple terraform project to create a local file on our machine:
- Create main.tf file with the following content:
terraform { required_version = ">= 0.15" required_providers { local = { source = "hashicorp/local" version = "~> 2.0" } } } resource "local_file" "literature" { filename = "funny_quotes.txt" content = <<-EOT "In order to understand recursion, one must first understand recursion. (Someone on the Internet)" EOT }
- Initialize the backend:
terraform init
Standard way to visualize plan by using dot
:
- Install
dot
tool:sudo apt install dot
- Output
graph.png
output file:terraform graph -type=plan | dot -Tpng > graph.png
- Output:
Alternative way of visualizing by Terraform visual:
- Install terraform visual:
npm install -g @terraform-visual/cli
- Generate terraform plan:
terraform plan -out=plan.out
- Convert plan into JSON format:
terraform show -json plan.out > plan.json
- Create Terraform Visual Report:
terraform-visual --plan plan.json
- Root project files:
- Open index.html file with LiveServer (ALT+L ALT+O):