terraform 模块块中的 for_each 返回 - “for_each”参数值不合适

问题描述

我想在模块块中使用计数,但由于它不受支持,我试图用 for 循环编写 for_each 但它给出了 "for_each" argument value is unsuitable 错误。

我无法将 count 传递给内部模块,因为它会弄乱我的输出格式。有人可以指导我如何正确调用 for_each。

main.tf

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
}

am/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
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)