How to Visualize Your Terraform
Introduction
Working with Terraform can sometimes be challenging—especially when your infrastructure is composed of multiple modules or lacks a clear architectural diagram. Understanding exactly what’s being deployed and how different resources interconnect can become quite complex.
That’s where Rover comes in. Rover is a tool designed to help you visualize your Terraform code, enabling you to quickly see how resources and modules relate to each other. In this guide, we’ll walk through how to generate a Terraform plan in JSON format, run Rover in a container, and ultimately view your Terraform architecture in an easy-to-understand diagram. this tool while trying to find a way to visualize terraform code, it’s called rover.
How to Use Rover
1.Generate the Terraform Plan (in JSON Format)
The first step involves creating a Terraform plan and outputting it in JSON format. You can do this by running:
$ terraform plan -out plan.out
$ terraform show -json plan.out > plan.json
terraform plan -out plan.out
creates a plan file.terraform show -json plan.out > plan.json
converts that plan into JSON.
2.Run Rover and View the Visualization
Next, run Rover in a Docker container:
docker run --rm -it -p 9000:9000 -v $(pwd)/plan.json:/src/plan.json -v $(pwd):/app/rover-output im2nguyen/rover:latest -planJSONPath=plan.json
Open your browser and navigate to http://localhost:9000. You’ll see a graphical representation of your Terraform code, including resources and their relationships.
4.you can generate an artifacte that represent the generated visualisation
Rover lets you export an HTML files (a zipped file) that captures your Terraform visualization. This can be useful for documentation or reviewing your infrastructure over time.
You can integrate this step into your CI/CD pipeline, ensuring each deployment generates an updated visualization for stakeholders and developers to review.
Once the artifact is created (named rover.zip
), unzip it and open the index.html
file in your browser to explore the visualization without needing to rerun Rover.
5-Generate a Static Image
If you want a static image of your Terraform architecture, you can run Rover with the -genImage
flag:
docker run --rm -it -p 9000:9000 -v $(pwd)/:/src/ -v $(pwd):/app/rover-output im2nguyen/rover:latest -planJSONPath=plan.json -genImage true
This will create an image file capturing the graph of your Terraform resources practical for quick documentation or presentation slides.
Conclusion
By using Rover, you can turn the complexities of multi-module Terraform deployments into a clear, navigable diagram. This improved visibility can accelerate debugging, enhance team collaboration, and streamline your infrastructure reviews.
References
https://github.com/im2nguyen/rover