Blast Radius

使用 d3.js 实现地形依赖图的交互式可视化。「Interactive visualizations of Terraform dependency graphs using d3.js」

Github stars Tracking Chart

Blast Radius

Blast Radius 是使用交互式可视化工具推理地形依赖图的工具。

使用 Blast Radius 可以:

  • 通过实际示例了解 Terraform 或其提供商之一
  • 记录您的基础架构
  • 关于资源之间关系的原因并评估对资源的更改
  • 文档中的下图(以及许多其他图)进行交互

先决条件

注意:对于 macOS,您可以 brew install graphviz

快速开始

使用 Blast Radius 启动和运行的最快方法是使用 pip 将其安装到您先前存在的环境中:

pip install blastradius

安装完成后,只需将 Blast Radius 指向任何已初始化的 Terraform 目录:

blast-radius --serve /path/to/terraform/directory

您将很快获得一个浏览器链接:http://127.0.0.1:5000/

Docker

手动运行本地目录的Blast Radius:

docker run --rm -it -p 5000:5000 \
  -v $(pwd):/data:ro \
  --security-opt apparmor:unconfined \
  --cap-add=SYS_ADMIN \
  28mm/blast-radius

还有一种稍微定制一些的变体,可以作为一个 docker-compose.yml 用例,用于工作区。

Docker 配置

Terraform 模块链接被保存为相对于项目根目录的绝对路径(注意 .terraform/modules/<uuid>)。鉴于这些路径在 Docker 和主机之间会有所不同,我们将卷安装为只读,以确保我们不会干扰您的实际环境。

但是,为了使 Blast Radius 实际与 Terraform 一起使用,需要对其进行初始化。为此,容器创建了一个存在于容器中的 overlayfs,可以覆盖您自己的,以便它可以独立运行。为此,需要某些运行时特权-特别是 --cap-add=SYS_ADMIN。

有关此工作方式及其对主机的含义的更多信息,请查看运行时特权文档。

Docker 和子目录

如果您使用 stacks 和 modules 组织 Terraform 项目,则必须从项目根目录调用 Blast Radius 并将其作为子目录引用 -- 别忘了给 --serve 前缀!

例如,让我们使用以下内容创建一个 Terraform 项目:

$ tree -d
`-- project/
    |-- modules/
    |   |-- foo
    |   |-- bar
    |   `-- dead
    `-- stacks/
        `-- beef/
             `-- .terraform

它由 3个 模块 foo、bar 和 dead 组成,后跟一个 beef stack。 要将 Blast Radius 应用于 beef stack,您需要使用以下命令运行容器:

$ cd project
$ docker run --rm -it -p 5000:5000 \
    -v $(pwd):/data:ro \
    --security-opt apparmor:unconfined \
    --cap-add=SYS_ADMIN \
    28mm/blast-radius --serve stacks/beef

嵌入式图

您可能希望将使用 Blast Radius 生成的图形嵌入其他文档中。您将需要以下内容:

  1. 代表图形及其布局的 svg 文件和 json 文档。
  2. .../blastradius/server/static 中找到的 javascriptcss
  3. 唯一标识的 DOM 元素,应出现 <svg> 的位置。

您可以在文档中阅读更多详细信息。

实施细节

Blast Radius 使用 [Graphviz][] 包来布局图形图,使用 PyHCL 来解析 Terraform 配置,并使用 d3.js 来实现交互式功能和动画。

进一步阅读

Blast Radius 的开发记录在一系列博客文章中:

  • 第1部分:动机,d3 force-directed layouts vs. vanilla graphviz.
  • 第2部分:d3 增强的 graphviz 布局,有意义的着色和动画。
  • 第3部分:限制水平扩展,支持模块。
  • 第4部分: 搜索,缩放,修剪选择,docker。

第1部分:动机,d3强制控制的布局与香草graphviz。

可在此处找到示例 Terraform 配置及其依赖图的目录。

这些示例主要是从与各种 Terraform 提供程序一起分发的 examples/ 目录中提取的,不一定是理想的。强烈希望有其他示例,尤其是最佳实践或多云配置的演示。


(The first version translated by vz on 2020.07.26)

Main metrics

Overview
Name With Owner28mm/blast-radius
Primary LanguageJavaScript
Program languageMakefile (Language Count: 7)
PlatformDocker, Linux, Mac, Windows
License:MIT License
所有者活动
Created At2017-11-07 05:20:23
Pushed At2024-08-14 12:38:03
Last Commit At2020-01-06 12:11:12
Release Count0
用户参与
Stargazers Count2.1k
Watchers Count32
Fork Count259
Commits Count120
Has Issues Enabled
Issues Count68
Issue Open Count36
Pull Requests Count23
Pull Requests Open Count11
Pull Requests Close Count14
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private

Blast Radius

CircleCI
PyPI version

Blast Radius is a tool for reasoning about Terraform dependency graphs
with interactive visualizations.

Use Blast Radius to:

  • Learn about Terraform or one of its providers through real examples
  • Document your infrastructure
  • Reason about relationships between resources and evaluate changes to them
  • Interact with the diagram below (and many others) in the docs

screenshot

Prerequisites

Note: For macOS you can brew install graphviz

Quickstart

The fastest way to get up and running with Blast Radius is to install it with
pip to your pre-existing environment:

pip install blastradius

Once installed just point Blast Radius at any initialized Terraform
directory:

blast-radius --serve /path/to/terraform/directory

And you will shortly be rewarded with a browser link http://127.0.0.1:5000/.

Docker

To launch Blast Radius for a local directory by manually running:

docker run --rm -it -p 5000:5000 \
  -v $(pwd):/data:ro \
  --security-opt apparmor:unconfined \
  --cap-add=SYS_ADMIN \
  28mm/blast-radius

A slightly more customized variant of this is also available as an example
docker-compose.yml usecase for Workspaces.

Docker configurations

Terraform module links are saved as absolute paths in relative to the
project root (note .terraform/modules/<uuid>). Given these paths will vary
betwen Docker and the host, we mount the volume as read-only, assuring we don't
ever interfere with your real environment.

However, in order for Blast Radius to actually work with Terraform, it needs
to be initialized. To accomplish this, the container creates an overlayfs
that exists within the container, overlaying your own, so that it can operate
independently. To do this, certain runtime privileges are required --
specifically --cap-add=SYS_ADMIN.

For more information on how this works and what it means for your host, check
out the runtime privileges documentation.

Docker & Subdirectories

If you organized your Terraform project using stacks and modules,
Blast Radius must be called from the project root and reference them as
subdirectories -- don't forget to prefix --serve!

For example, let's create a Terraform project with the following:

$ tree -d
`-- project/