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
以取得完整指令清單或特定指令的協助