terraform graph ではグラフ表示が厳しすぎる。 もっといい感じにリソースを構成図に落とし込んだり確認したい。
できれば、Pulumi の Graph View がよい。
pcasteran/terraform-graph-beautifier: Terraform graph beautifier https://github.com/pcasteran/terraform-graph-beautifier
terraform graph | docker run --rm -i \
--name terraform-graph-beautifier \
ghcr.io/pcasteran/terraform-graph-beautifier:latest-linux \
--output-type=cyto-html \
> config1.html
一番いい感じ。
im2nguyen/rover: Interactive Terraform visualization. State and configuration explorer. https://github.com/im2nguyen/rover
Warning Terraform Cloud のリモートバックエンドで利用できない。
terraform plan -out=plan.out
が必要で、エラーが出る。
# rover
2023/04/12 17:52:16 Starting Rover...
2023/04/12 17:52:16 Initializing Terraform...
2023/04/12 17:52:24 Generating plan...
2023/04/12 17:52:27 Unable to parse Plan: Unable to run Plan: exit status 1
Error: Saving a generated plan is currently not supported
Terraform Cloud does not support saving the generated execution plan locally
at this time.
なお、いわゆるスタンダードモジュール構成の場合、docker で実行時に次のように sh でコンテナ入って実行が必要。
# pwd は terraform のフォルダ直下にして modules も environments もとれるようにする
$ docker run --rm -it -p 9000:9000 -e TF_API_TOKEN=<YOUR_TOKEN> -v $(pwd):/src --entrypoint sh im2nguyen/rover
# docker
wget -O terraform_1.3.7.zip https://releases.hashicorp.com/terraform/1.3.7/terraform_1.3.7_linux_amd64.zip
unzip terraform_1.3.7.zip
rm terraform_1.3.7.zip
mv terraform /usr/local/bin/.
terraform --version
cat >~/.terraformrc <<EOL
credentials "app.terraform.io" {
token = "${TF_API_TOKEN}"
}
EOL
cd environments/aws_dev
rover
hieven/terraform-visual: Terraform Visual is an interactive way of visualizing your Terraform plan https://github.com/hieven/terraform-visual
Warning Terraform Cloud のリモートバックエンドで利用できない。
terraform plan -out=plan.out
が必要で、エラーが出る。
$ terraform plan -out=plan.out
Unable to parse Plan: Unable to run Plan: exit status 1
Error: Saving a generated plan is currently not supported
Terraform Cloud does not support saving the generated execution plan locally
at this time.
cycloidio/inframap: Read your tfstate or HCL to generate a graph specific for each provider, showing only the resources that are most important/relevant. https://github.com/cycloidio/inframap
生成はされるが、いい感じのグラフにはならないので難しい。
state.tfstate を リモートバックエンドからダウンロードする。
TFC_TOKEN=<YOUR_TERRAFORM_CLOUD_API_TOKEN>
WORKSPACE_ID=<YOUR_TERRAFORM_CLOUD_WORKSPACE_ID>
HTTP_RESPONSE=$(curl \
--header "Authorization: Bearer "$TFC_TOKEN"" \
--header "Content-Type: application/vnd.api+json" \
"https://app.terraform.io/api/v2/workspaces/$WORKSPACE_ID/current-state-version" | jq -r '.data | .attributes | ."hosted-state-download-url"')
curl -o state.tfstate $HTTP_RESPONSE
で実行。
docker run --rm -v <TFSTATE_FOLDER>:/opt cycloid/inframap generate /opt/state.tfstate | dot -Tpng > graph.png
Command: graph | Terraform | HashiCorp Developer https://developer.hashicorp.com/terraform/cli/commands/graph
グラフが細かすぎて無理。
terraform graph | dot -Tsvg > graph.svg
https://gkzz.dev/posts/alternative-terraform-graph/ が同じことしてた。