How can I retrieve the output variable from a module called in a loop? I like to add subnets in the next step to the vnet.
Main.bicep
module vnet01 'vNet.bicep' = [ for vnet in vnets : {
name: vnet.name
scope: virtualNetworkRg
params: {
vnetName: vnet.name
vnetAddressPrefix: vnet.vnetAddressPrefix
location: location
}
}]
vNet.bicep
param ...
resource vnet 'Microsoft.Network/virtualNetworks@2021-08-01' = {
name: vnetName
location: location
properties: {
addressSpace: {
addressPrefixes: [
vnetAddressPrefix
]
}
}
}
//Output
output id string = vnet.id
CodePudding user response:
You could always loop through vnet01
(as it is an array):
module vnet01 'vNet.bicep' = [for vnet in vnets: {
name: vnet.name
...
}]
output vnetIds array = [for i in range(0, length(vnets)): {
id: vnet01[i].outputs.id
}]