gpt4 book ai didi

azure - terraform 无法识别计数值

转载 作者:行者123 更新时间:2023-12-02 22:59:42 26 4
gpt4 key购买 nike

我有一个 terraform 代码,必须执行多次,这意味着 terraform init、plan、apply 将在 for 循环内。一个资源 block 有一个计数变量,该变量根据局部变量进行评估。第一次迭代运行良好,直到 terraform 应用为止。在第二次迭代中,它在 terraform plan 上失败并出现以下错误。

The "count" value depends on resource attributes that cannot be determined until apply, so Terraform cannot predict how many instances will be created.To work around this, use the -target argument to first apply only the resources that the count depends on.

下面的 block 是使用 count 的地方

resource "null_resource" "test" {
count = length(local.stacc)
provisioner "local-exec" {
command = "echo ${local.data[count.index]} >> myfile.txt"
}
}

这个local.stcacc是基于某些for循环处理来实现的,这将产生一个列表。因此列表中的项目数就是 local.stacc 的值我的疑问是第一次迭代如何通过但第二次迭代失败。

最佳答案

local.stacc 不能依赖于其他资源。它的值必须在apply时知道,而不是在期间。正如错误提示,使用 -target apply 并创建评估 local.stacc 所需的资源,然后再次 apply 运行您的 null_resource""测试”

关于azure - terraform 无法识别计数值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71303757/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com