I have a Terraform script using modules. I want to create multiple resources so I'm using the for_each method.
Below is my variable configuration:
variable bridge_domains {
description = "Bridge Domain"
type = map
default = {
bd1 = {
name = "BD1",
},
bd2 = {
name = "BD2"
}
}
}
In the root main.tf
file, I'm looping over that variable using for_each
:
module "schema_template_bd" {
source = "./modules/schema_template_bd"
for_each = var.bridge_domains
schema = module.tenant.mso_schema.id
template = var.template
bd = each.value.name
}
Then in the modules/schema_template_bd
file I have the following:
resource "mso_schema_template_bd" "bd" {
schema_id = var.schema
template_name = var.template
name = var.bd
}
The module has an output where I have defined the following:
output "mso_bd" {
value = mso_schema_template_bd.bd[*]
}
The idea is to output the names from all the objects that were created. So I have defined an output.tf
file (at root level) containing the following code:
output "bd_name" {
value = module.schema_template_bd.mso_bd.*.name
}
I always get:
This object does not have an attribute named "name".
Normally the bd
object has a name so the error has to do with a wrong syntax in my view.