I want to use count in module block but since it is not supported im trying to write for_each with a for loop but it is giving "for_each" argument value is unsuitable error.
"for_each" argument value is unsuitable
I can't pass count to the inner module because it will mess my output format. can someone guide me how to properly call 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 }
There are few ways to do this. One way is:
for_each = {for id in range(2): id=>id}
other one is:
for_each = toset([for id in range(2): tostring(id)])
2.1m questions
2.1m answers
60 comments
57.0k users