我需要调试对一个环境的循环依赖。所有其他人都使用相同的计划/.tf 文件。其原因可能是在有问题的环境中,某些资源尚未被破坏。这些环境是通过 .tfvar 文件定义的,通常传递给
plan
和 apply
,如下所示:
terraform plan -var-file="./envs/some-env/terraform.tfvars"
terraform graph
命令有4个选项
Options:
-plan=tfplan Render graph using the specified plan file instead of the
configuration in the current directory. Implies -type=apply.
-draw-cycles Highlight any cycles in the graph with colored edges.
This helps when diagnosing cycle errors. This option is
supported only when illustrating a real evaluation graph,
selected using the -type=TYPE option.
-type=TYPE Type of operation graph to output. Can be: plan,
plan-refresh-only, plan-destroy, or apply. By default
Terraform just summarizes the relationships between the
resources in your configuration, without any particular
operation in mind. Full operation graphs are more detailed
but therefore often harder to read.
-module-depth=n (deprecated) In prior versions of Terraform, specified the
depth of modules to show in the output.
以下 2 个可以工作,但没有以红色指示任何循环错误,可能是因为它不是针对唯一失败的环境运行的。
terraform graph -draw-cycles
terraform graph -draw-cycles -type=plan > graph.dot
所以我尝试按照创建的计划运行它。为此,在遵循帮助文本时,必须将类型设置为
apply
。然而,这会出错。
terraform graph -draw-cycles -type=apply -plan=plan.out > graph.dot
Too many command line arguments. Did you mean to use -chdir?
所以我的问题是如何在特定计划上正确运行
terraform graph
?
我在 Windows 上使用 terraform 版本 1.7.5 和 1.9.6,它们都显示相同的行为
归结为我没有正确转义 powershell 命令。与上述命令的区别在于
"
的路径周围有
plan.out
正确的运行方式
terraform graph
如下:
terraform plan -var-file="./envs/some-env/terraform.tfvars" -out="plan.out" -var image_tag=test123
terraform graph -draw-cycles -type="apply" -plan="plan.out" > graph.dot