Generating Terraform graphs automatically in Pull Requests
Tags: terraform, aws, gcp, azure
Published: 2023-12-05 14:41:46



In today’s fast-paced digital landscape, managing and provisioning infrastructure efficiently and accurately is a crucial aspect of any organization’s success. This is where Terraform comes into play. With its ability to define and provision infrastructure resources using declarative configuration files, Terraform simplifies the process of building and managing complex infrastructure environments.

But what if we could take advantage of Terraform to automatically generate infrastructure diagram? This would enable to visualize infrastructure, quickly track changes, generate up-to-date documentation and improve collaboration.

Introducing Holori - a new tool that lets you generate clear and accurate terraform graphs for AWS, Azure and GCP directly in your CI/CD.

Visualizing, tracking changes and documenting your infrastructure shouldn’t be a nightmare. At Holori, we have always had in mind to make the job of DevOps and Cloud Architects easier and that’s why we came up with automated Terraform graph generation directly in CI/CD.

In this article, we will see how you can use Holori to generate terraform graphs in minutes.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ttaqzziuvrgdrv7uuaom.png)


## What are Terraform Graphs?

Terraform graphs provide a comprehensive view of the resources within an infrastructure environment are and how they are interconnected. A terraform graph can be created by tools that parse the Terraform configuration files and generate an infrastructure diagram from it.

As any cloud architecture diagram, it provides a visual overview of infrastructure. It uses icons to represent specific types of products, resources, and services.

In a nutshell, Terraform graphs enables quick resource discoverability to ensure that DevOps teams are aware of the resources in place and identify the ones that are misconfigured or should be removed.


## Using Holori to generate Terraform Graphs in CI/CD

You are now probably wondering how hard it can be to set up such a system? Don’t worry, it’s as easy as 1, 2, 3 !

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nv7fmklaosghxkmx6scf.png)

**How it works :**
1- Create Holori account — Preferably log in with your Github account

2- Install Holori Github App — Directly install it from Holori software

3- You are all set, from now on, Holori will monitor the pull requests and identify the ones containing Terraform files.

4- Once a pull request containing Terraform files is identified, Holori automatically create the corresponding cloud infrastructure diagram.

5- The picture generated is directly posted as a comment under your pull request making it easy to directly identify the impact it has on your infrastructure.

{% embed https://www.youtube.com/watch?v=rlEajEoUytc&ab_channel=Holori %}


If you need to dig deeper into your infrastructure details, you can directly open the diagram in Holori App. There you will be able to get access to detailed information about each resource used, its size, configuration and even its cost estimation.

In addition to a picture, it is also possible to generate a PDF documentation. This pdf contains a picture of your infra, the list of all the different resources as well as their configuration.

The Holori terraform graph in the CI/CD Add-On eliminates the necessity for manual creation of infrastructure diagrams. Any modifications to the infrastructure are automatically instantly translated into a visual format and documented saving valuable engineering time every month. The visual representation is not only efficient but also simplifies communication across the entire team, making it much easier compared to navigating through complex explanations.


**Wanna give it a try ? https://app.holori.com/
We offer 50 Runs/month for free**


## Generate terraform Graphs directly in Holori App

In case you don’t need to generate the terraform infrastructure diagram in your CI/CD, you can alternatively use Holori App.

1- Create an account on Holori App

2- New project > Import from terraform

3- Upload a ZIP that contains main.tf, output.tf … not the tf.state

3- Wait 1 to 5 min for the terraform graph to be generated

{% embed https://www.youtube.com/watch?v=YeAmJvzZDGo&ab_channel=Holori
 %}

Using Holori App to generate terraform graph can be useful when you are working on your terraform code and want to visualize what you are doing. I personally think that it can also be useful for people learning terraform.

Another use case, could be for cloud consultants, that are working at their customer but don’t have access to the CI/CD.

Generating Terraform Graph with Holori App, is of course less automated than if plugged with the CI/CD and is more suitable for people with periodic needs.

## Why any organization should adopt Terraform Graphs

**Visualization of Infrastructure:** A Terraform graph offers a visual representation of the infrastructure, enabling better understanding and easier communication of complex configurations. This visualization helps teams identify potential issues, such as circular dependencies or resource conflicts, which may not be immediately apparent in the code.
Documentation of infrastructure: By keeping track of each infra evolution, pull request after pull request, it becomes easier to capture the state of the infra at any given time. It can easily be shared with various stakeholders, from management to new hires in order to quickly understand the infrastructure as a whole.

**Dependency Analysis:** By examining the graph, DevOps and cloud architects can quickly identify the dependencies between resources. This knowledge is invaluable when planning changes or optimizations, as it allows teams to assess the impact of modifying or removing specific resources on the overall infrastructure.

**Infrastructure Validation:** Terraform graphs can assist in validating the correctness of infrastructure configurations. By inspecting the graph, it becomes easier to spot potential misconfigurations or inconsistencies before applying changes to the infrastructure, reducing the risk of introducing errors.

**Performance Optimization:** By visualizing the resource dependencies, teams can evaluate alternative configurations and identify opportunities for optimization, ultimately improving the efficiency and scalability of the infrastructure. Moreover, it helps to quickly identify risky situations. For example all resources located in a single datacenter that would be a single point of failure in case of an outage.


## What’s next for Holori?

Terraform graphs serve as a powerful tool for infrastructure engineers and DevOps teams, enabling them to gain a deeper understanding of the resources and their dependencies within their infrastructure. This is key to document the infra, reduce errors, and improve overall efficiency.

With Holori Terraform Graph generation, you don’t need to choose anymore between having poor documentation or wasting worthy DevOps time, you can have it all.

In addition to visualizing your pull requests as an infrastructure diagram we will also soon be able to highlight its evolution. This is key to track modifications directly in your CI/CD. Infrastructure changes will be highlighted with a color code directly in the Terraform graph:

Green: new resource created
Yellow: terraform attribute was modified (size, configuration…)
Red: the element was deleted

Wanna try Holori for free, sign up here : **https://app.holori.com/**
**We offer 50 Runs/month !**