terraform 无法识别计数值

发布于 2025-01-11 02:34:00 字数 784 浏览 2 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

卖梦商人 2025-01-18 02:34:01

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 at apply time, not during. As the error suggest, use -target to apply and create the resources which are needed for evaluation of local.stacc, and then apply again to run your null_resource" "test".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文