Exploring Terraform Graphs With D3.js Part 3
This is the third in a series of posts exploring methods of visualizing Terraform dependency graphs, with the goal of producing a tool useful for learning and documentation.
Above is a representative example. Roll your mouse over one of the nodes to see its definition and to highlight its dependencies. For further information, refer to part one, part two, part three, or part four of this series; or to GitHub, where Blast Radius is hosted.
Modules greatly simplify Terraform administration, by isolating reusable components. Earlier versions of Blast Radius1 didn’t handle modules very well, or at all.
For a recent project,2 I wanted to launch a single AWS instance in a large number of AWS regions; a perfect fit for modules. Here is a single instance of that module, launched in the AWS
us-east-1 region, and named the same.
Here’s the same module reused to launch copies of that instance in both
us-east-1 (Northern Virginia), and
And, here is the same module reused to launch instances in seven regions. This graph in particular highlights the limitations of the visual language used: it is too colorful, and too broad. Illegible, in other words.
Something like Terraform’s
--module-depth parameter would simplify larger diagrams like this one. Better handling of the module registry and other remote sources, is needed as well… but it’s a start.
Narrowing (Some) Figures
In previous posts, I’ve described the tendency for Graphviz layouts of Terraform graphs to sprawl sideways. Some of this is unavoidable, but gains can be realized at the expense of vertical scrolling.
Variable resources often share a parent. Rather than lay these variables out side by side, they could be “stacked,” one atop the other, without sacrificing clarity.
(Output resources often share the same (single) dependency, and parent, and can be “stacked” in the same way. This figure demonstrates that possibility, as well.)
Code & Examples
The code used to produce these figures can be found on GitHub, as the Blast Radius project.
Further examples–most of them borrowed from examples/ directories in the Terraform provider ecosystem–can be found on the project’s documentation page.
If you’re interested in testing Blast Radius in your environment, you can obtain an experimental distribution from the Python Package Index.
[...]$ brew install graphviz [...]$ pip3 install blastradius
Or clone the GitHub repository, and install an edtitable copy (via
[...]$ git clone https://github.com/28mm/blast-radius.git [...]$ cd blast-radius [...]$ pip3 install -e .
Blast Radius requires an
init-ed Terraform project to run.
[...]$ cd path/to/terraform/project [...]$ terraform init [...]$ blast-radius --serve
While I’m pleased Blast Radius, as an exploratory project, more work is needed to make it generally useful. In particular, I’d like to shore up module support, do smarter tooltip layouts, and make it easier to embed figures.
What do you think? Comment and Suggestion to email@example.com