TerraVision 是一个 CLI 工具,可将 Terraform 代码转换为专业云架构图,并解决云项目中最重要的文档(架构文档)保持最新的问题。随着现在高速发布的规范,机器生成的架构图比依赖云架构师绘制的与现实不再相符的自由式图表更准确。 Terravision 安全地运行 100% 客户端,无需依赖 Terraform 或访问您的云环境,动态解析您有条件创建的资源和变量,并生成架构的自动视觉效果。 Terravision 被设计为一个“文档即代码”(DaC) 工具,可以包含在 CI/CD 管道中,以便在构建/测试/发布管道阶段之后更新架构图,并补充其他文档生成器,例如 readthedocs.io。目前它支持 AWS,很快就会支持 Google 和 Azure 云。
转这个...
进入这个...
该软件仍处于 alpha 测试阶段,代码按“原样”共享,不带任何明示或暗示的保证或条件。使用风险自负。
git clone https://github.com/patrickchugh/terravision.git
cd terravision
和pwd
获取工作目录(完整路径)。PATH
值中,例如export PATH=$PATH:/Users/<PATH TO TERRAVISION>
以便您可以从任何地方运行它。 <PATH TO TERRAVISION>
将是第 3 行的输出。cd terravision && pip install -r requirements.txt
chmod +x terravision
执行terravision
并按以下格式指定 Terraform 源文件: $ terravision draw --source ~ /src/my-terraform-code
对于具有工作区的 Terraform 堆栈,您可以使用--workspace
参数:
$ terraform draw --source ~ /src/my-terraform-code --workspace development
对于 Git 存储库中的 Terraform 源代码,您还可以使用以下形式:
$ terravision draw --source https://github.com/your-repo/terraform-examples.git
如果您想要的代码位于文件夹层次结构下,请使用//
字符表示 Git 存储库中的子文件夹。
$ terravision draw --source https://github.com/your-repo/terraform-examples.git//mysubfolder/secondfolder/
自动生成的图表不会包含您需要的所有细节,最多只能完成 80-90% 的工作。要添加自定义注释,例如主图标题、箭头上的附加标签或在 Terraform 外部创建的附加资源,请在源代码文件夹中包含terravision.yml
文件,它将自动加载。或者,指定注释文件的路径作为 terravision 的参数。
terravision --source https://github.com/your-repo/terraform-examples.git --annotate /Users/me/MyDocuments/annotations.yml
.yml 文件是一种标准 YAML 配置文件,类似于下面的示例,其中包含一个或多个名为title
、 connect
、 disconnect
、 add
、 remove
或update
标题。节点名称遵循与 Terraform 资源名称相同的约定 https://registry.terraform.io/providers/hashicorp/aws/latest/docs 并支持通配符。您可以通过修改资源的属性并添加label
属性(Terraform 中不存在)来向任何 TF 资源添加自定义标签。对于线/连接,您可以通过添加 terravision 特定的edge_labels
来修改资源属性,以将文本添加到特定资源节点的连接线上。请参阅下面的示例:
format : 0.1
# Main Diagram heading
title : Serverless Wordpress Site
# Draw new connection lines that are not apparent from the Terraforms
connect :
aws_rds_cluster.this :
- aws_ssm_parameter.db_master_user : Retrieve credentials from SSM
# Remove connections between nodes that are currently shown
disconnect :
# Wildcards mean these disconnections apply to any cloudwatch type resource called logs
aws_cloudwatch*.logs :
- aws_ecs_service.this
- aws_ecs_cluster.this
# Delete the following nodes
remove :
- aws_iam_role.task_execution_role
# Add the following nodes
add :
aws_subnet.another_one :
# Specify Terraform attributes for a resource like this
cidr_block : " 123.123.1.1 "
# Modify attributes of existing node
update :
aws_ecs_service.this :
# Add custom labels to the connection lines that already exist between ECS->RDS
edge_labels :
- aws_rds_cluster.this : Database Queries
# Wildcards save you listing multiple resources of the same type. This edge label is added to all CF->ACM connections.
aws_cloudfront* :
edge_labels :
- aws_acm_certificate.this : SSL Cert
# Add a custom label to a resource node. Overrides default label
aws_ecs_service.this :
label : " My Custom Label "
键入terravision --help
以获取完整命令列表或特定命令的帮助