Skip to main content

Command Palette

Search for a command to run...

A better alternative to visualize your Terraform graph

Updated
2 min read
A better alternative to visualize your Terraform graph
M

Hey, I'm a postgraduate in Cyber Security with practical experience in Software Engineering and DevOps Operations. The top player on TryHackMe platform, multilingual speaker (Kazakh, Russian, English, Spanish, and Turkish), curios person, bookworm, geek, sports lover, and just a good guy to speak with!

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

More from this blog

M

Maxat Akbanov's blog

259 posts

Postgraduate in Cyber Security with experience in Software Engineering and DevOps Operations.