簡體   English   中英

計數值在 terraform 中不被識別

[英]The count value is not recognized in terraform

我有一個 terraform 代碼,它必須執行多次,這意味着 terraform init,plan,apply 將在一個 for 循環中。 一個資源塊有一個計數變量,它根據局部變量進行評估。 第一次迭代運行良好,直到 terraform 應用。 在第二次迭代中,它在 terraform 計划失敗並出現以下錯誤。

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.

以下塊是使用計數的地方

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

這個local.stcacc是基於一定的for循環處理實現的,會得到一個list。 因此列表中的項目計數是 local.stacc 的值我的疑問是第一次迭代如何通過但第二次迭代失敗。

local.stacc不能依賴於其他資源。 它的值必須在apply時知道,而不是在應用期間。 正如錯誤提示的那樣,使用-targetapply和創建評估local.stacc所需的資源,然后再次apply以運行您的null_resource" "test"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM