Richie
December 2, 2021, 2:56pm
1
Hello, pls can someone help me with this. i am trying to create multiple resources using for loop, I got an error with the for loop statement . is my for loop statement wrong?
map = flatten([
for keys, values in var.express_route_direct : {
for exr_ccts_key, exr_ccts in values.express_route_circuits :
"${keys}-${exr_ccts_key}" => {
express_route_direct_port_name = keys
resource_group_name = values.resource_group_name
resource_group_location = values.resource_group_location
peering_location = values.peering_location
rtp_bandwidth_in_gbps = values.rtp_bandwidth_in_gbps
express_route_circuit_name = exr_ccts_key
bandwidth_in_gbps = exr_ccts.bandwidth_in_gbps
authorizations = exr_ccts.authorizations
sku = exr_ccts.sku
}
}
])
}
the error is "This object does not have an attribute named “express_route_circuits”.
Hi @Richie ! Can you show an example of var.express_route_direct
? It’s unclear how that object is modelled.
Richie
December 2, 2021, 6:32pm
3
the project is to create iterate over those var and create the resources
variable "express_route_direct" {
type = map(object({
express_route_direct_port_name = string
express_route_circuits = map(object({
bandwidth_in_gbps = string
sku = object({
tier = string
family = string
})
authorizations = set(string)
}))
resource_group_name = string
resource_group_location = string
encapsulation = string
peering_location = string
rtp_bandwidth_in_gbps = string
}))
}
Richie
December 2, 2021, 6:34pm
4
i am using an expression for the variables evaluation:
map = flatten([
for keys, values in var.express_route_direct : {
for exr_ccts_key, exr_ccts in values.express_route_circuits :
"${keys}-${exr_ccts_key}" => {
express_route_direct_port_name = keys
resource_group_name = values.resource_group_name
resource_group_location = values.resource_group_location
peering_location = values.peering_location
rtp_bandwidth_in_gbps = values.rtp_bandwidth_in_gbps
express_route_circuit_name = exr_ccts_key
bandwidth_in_gbps = exr_ccts.bandwidth_in_gbps
authorizations = exr_ccts.authorizations
sku = exr_ccts.sku
}
}
])