-
Hello, Trying to figure out the child nesting syntax for subnets within a virtual network. Goal is to create separate files for vnet and subnets and eventually NSGs to use as modules. So, I want to be able to call or reference these child resource types wherever I need. I have looked at the examples and I have failed to get this working. This would be especially important in cases where we might deploy multiple vnets and subnets of different ranges. In this case, we may have a vnet1 module and a vnet 2 module and corresponding subnet1, subnet2 modules. Thanks for your help. //deploy virtual network
@description('The expected Azure region to deploy resources.')
param location string = resourceGroup().location
@description('The base naming for all resources.')
param namePrefix string = 'azmech'
@description('The base name of the virtual network.')
param vnetid string = 'vnet'
@description('The virtual network address space.')
param vnetAddressSpace string = '10.0.0.0/26'
@description('The tags to be used.')
param resourceTags object = {
environment: 'dev'
project: 'bicep_tutorial'
}
var baseName = '${namePrefix}-${location}'
resource vnet 'Microsoft.Network/VirtualNetworks@2020-07-01' = {
name: toLower('${baseName}-${vnetid}-1')
location: location
tags: resourceTags
properties: {
addressSpace: {
addressPrefixes: [
vnetAddressSpace
]
}
resource subs 'subnets' = { //Why the mismatch?
name: //?????
}
}
}
} //deploy subnets
@description('The expected Azure region to deploy resources.')
param location string = resourceGroup().location
@description('The base naming for all resources.')
param namePrefix string = 'azmech'
@description('The base name of a virtual network subnet resource.')
param snetid string = 'snet'
var baseName = '${namePrefix}-${location}'
var subnets = [
{
snetPrefix: '10.0.0.0/28'
}
{
snetPrefix: '10.0.0.16/28'
}
{
snetPrefix: '10.0.0.32/28'
}
{
snetPrefix: '10.0.0.48/28'
}
]
resource snets 'Microsoft.Network/VirtualNetworks/subnets@2020-07-01' = [for (subnet, i) in subnets: {
name: toLower('${baseName}-${snetid}-${i + 1}')
properties: {
addressPrefix: subnet.snetPrefix
}
}] |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
I think this should answer your question?
or
^^ here i assumed throwing in an array of objects, which I personally prefer |
Beta Was this translation helpful? Give feedback.
-
@fluffy-cakes Ok. Will look at it. I think my initial question is related to Issue #1170 |
Beta Was this translation helpful? Give feedback.
@fluffy-cakes Ok. Will look at it. I think my initial question is related to Issue #1170