Blast Radius: Review the Impact of Changes in Your Terraform Files

3 min read

Analyzing Terraform files that have many lines of code spread across multiple files is cumbersome, and it can be confusing to understand the dependencies between modules, resources and data-sources.

This is further aggravated when you are trying to assess the impact of any small change in the Terraform configuration file.  

In this blog post, I’ll show you how you can use Blast Radius to simplify the Terraform resources and data source visualization. 

About Terraform and Blast Radius

Terraform was developed by Hashicorp and works on the principles of Infrastructure as Code (IaC). IBM uses Terraform as the default IaC-based automation engine in its product. For more information, refer to the Terraform on IBM Cloud documentation.

Blast Radius is an open-source tool used for reasoning about Terraform dependency graphs with an interactive view. You can use Blast Radius to do the following:

  • Learn about Terraform or one of its providers through real-time examples.
  • Document your IaC.
  • Reason the relationships between the resources and evaluate the differences.

IBM has enhanced the capabilities in Blast Radius to view the IBM Cloud Terraform configuration files, Terraform plan files and the Terraform state files (with additional details like cost estimate, time estimate and policy compliance for each resource in the graphical view).

Prerequisites

  • Python3.7 or higher version
  • Terraform v0.12 or higher used to generate the following:
    • Terraform plan json file
    • Terraform state file (after running the Terraform apply command)
    • Terraform cost estimator for IBM Cloud (to generate the cost.json file)
    • OPA Policy evaluation tool for IBM Cloud (to generate the policy.json file)

Usage

Install latest release of the Blast Radius wheel from the IBM Cloud repository via this command:

pip3 install blastradius-0.1.25.1-py3-none-any.whl

Verify the Blast Radius installation: 

blast-radius help

The output should look something like this: 

Figure 1: Blast Radius installation help.

Figure 1: Blast Radius installation help.

Running Blast Radius 

Follow these steps to run Blast Radius in your local system with a sample Terraform configuration:

  1. Download your Terraform templates to your local machine in a working directory:
  2. Generate the tfplan.json:
    • Run the terraform init command in the Terraform working directory.
    • Generate the terraform plan –out=tfplan.binary command.
    • Show terraform show -json tfplan.binary > tfplan.json to convert the Terraform plan binary data into JSON format. Note: ‘tfplan.json` is the mandatory file to provide cost and policy information in the graph. 
  3. Generate the Terraform state files (this is not mandatory step):
    • Run the terraform apply command in the Terraform working directory.
  4. Copy the static/images folder from Blast Radius directory to the Terraform working directory: 
    • The static folder contains Blast Radius images for the graphic display.
  5. Run the blast-radius --serve . command to view the graph.
  6. Open your browser with <URL> to view the graph as shown in the following screen capture:
    Figure 2: Complete view of Terraform configuration.

    Figure 2: Complete view of Terraform configuration.

Working with Blast Radius graphs 

The rows represent nodes, and they have on-click functionalities. The first row depicts the dependent path of the node, as shown in Figure 3:

Figure 3: On-click functionality.

Figure 3: On-click functionality.

When you on-click the plan row, you will get the plan data of the particular resource in the side panel, as shown in Figure 4:

Figure 4: On-click the plan row.

Figure 4: On-click the plan row.

Similarly, you can view the cost and policy information of the resources in the respective view, but for that, you need to have cost data and policy data in the form of cost.json and policy.json in the directory. You can also filter the graph based on their nodes:

Figure 5: Filter view by the node name in the search bar.

Figure 5: Filter view by the node name in the search bar.

You can also pure the graph to minimize its view and visualize it in a wider and clearer view. To do so, you need to select the node and click on the purge symbol. The view will be something like what is shown in Figure 6:

Figure 6: Purge view.

Figure 6: Purge view.

There are other features like zoom in and zoom out, and you can also download an .svg file of your graph.

Get started with Blast Radius

In this post, you learned how you can use Blast Radius to simplify Terraform resources and data source visualization. 

To explore more about Blast Radius and to contribute, use the Blast Radius repository

Be the first to hear about news, product updates, and innovation from IBM Cloud