terraform 无法识别计数值
我有一个 terraform 代码,必须执行多次,这意味着 terraform init,plan,apply 将在 for 循环内。一个资源块有一个计数变量,该变量根据局部变量进行评估。第一次迭代运行良好,直到 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.
以下块是使用 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 的值 我的疑问是第一次迭代如何通过但第二次迭代失败。
I have a terraform code which has to execute multiple times which means terraform init,plan,apply will be within a for loop. One resource block has a count variable which gets evaluated based on local variable. First iteration works well until terraform apply. In the second iteration it fails at terraform plan with the following error.
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.
The following block is where count is used
resource "null_resource" "test" {
count = length(local.stacc)
provisioner "local-exec" {
command = "echo ${local.data[count.index]} >> myfile.txt"
}
}
This local.stcacc is achieved based on certain for loop processing which will result in a list. Hence count of items in the list is the value of local.stacc
My doubt is how the first iteration passes but second iteration fails.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
local.stacc
不能依赖于其他资源。它的值必须在apply
时知道,而不是在期间。正如错误所示,使用 -target 来 < code>apply 并创建评估local.stacc
所需的资源,然后再次apply
运行您的null_resource” “测试”。
local.stacc
can't be dependent on other resources. Its value must be know atapply
time, not during. As the error suggest, use -target toapply
and create the resources which are needed for evaluation oflocal.stacc
, and thenapply
again to run yournull_resource" "test"
.