A better alternative to visualize your Terraform graph

A better alternative to visualize your Terraform graph

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:

  1. 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
    }
    
  2. Initialize the backend:
    terraform init
    

Standard way to visualize plan by using dot:

  1. Install dot tool:
    sudo apt install dot
    
  2. Output graph.png output file:
    terraform graph -type=plan | dot -Tpng > graph.png
    
  3. Output: graph.png

Alternative way of visualizing by Terraform visual:

  1. Install terraform visual:
    npm install -g @terraform-visual/cli
    
  2. Generate terraform plan:
    terraform plan -out=plan.out
    
  3. Convert plan into JSON format:
    terraform show -json plan.out > plan.json
    
  4. Create Terraform Visual Report:
    terraform-visual --plan plan.json
    
  5. Root project files: root
  6. Open index.html file with LiveServer (ALT+L ALT+O): reporter

Reference:

  1. Terraform Visual
  2. Github project