[英]for_each in terraform module block returns - “for_each” argument value is unsuitable
我想在模塊塊中使用計數,但由於不支持我嘗試用 for 循環編寫 for_each 但它給出的"for_each" argument value is unsuitable
錯誤。
我無法將計數傳遞給內部模塊,因為它會弄亂我的 output 格式。 有人可以指導我如何正確調用 for_each。
主文件
module "test" {
for_each = toset([for id in range(2): {
index = id
}])
source = "./am"
name = each.value
}
output "all" {
depends_on = [ module.test ]
value = module.one
}
上午/test.tf
variable "name" {
type = string
}
resource "azurerm_public_ip" "ip" {
name = ..
resource_group_name = ..
location = ..
allocation_method = ..
}
output "one" {
description = "one_value"
value = azurerm_public_ip.ip.ip_address
}
有幾種方法可以做到這一點。 一種方法是:
for_each = {for id in range(2): id=>id}
另一種是:
for_each = toset([for id in range(2): tostring(id)])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.