parent not working when using module #4119
-
I'm looking for a way to create a subnet later on after I have created a firewall and a udr and getting stuck in a bit of a loop so looking for a solution. Anyway back on to the issue, so the below works fine and deploys the vnet and subnet
If I try the same thing but use a vnet module it doesn’t even try and create the subnet or error at all.
vnet.module.bicep
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @davidjhole This is one of the items that is being worked on, in order to make this scenario easier #2246 To explain the current state... via your example: Parent is not equivalent to Dependson. There is a separate dependsOn property. When you use parent it expects a resource type reference. The reference to the Module (which can potentially do/contain anything and multiples of them) does not satisfy that reference (or a VNET). Some the options are:
resource subnet2 'Microsoft.Network/virtualNetworks/subnets@2021-02-01' = {
name: 'vnet02/sub02'
properties: {
addressPrefix: '10.1.1.0/24'
}
} I noticed that you can also use a reference to the module to retrieve the Module Name string and use that, since/so long as it will match the vnet name. I think this is more scalable. module vnet2 '../modules/vnet.module.bicep' = {
name: 'vnet02'
params: {
vnetName: 'vnet02'
addressPrefix: '10.1.0.0/16'
subnetsDefinitions: []
}
}
resource subnet2 'Microsoft.Network/virtualNetworks/subnets@2021-02-01' = {
name: '${vnet2.name}/sub02'
properties: {
addressPrefix: '10.1.1.0/24'
}
} My personal recommendation would be: Simply update your subnet definitions in your source code to reflect the new state (UDR/RT/NSG) redeploy the whole VNET again which will have the same outcome and overall have less chance of any configuration skew over time. Looking at this 'sample' it will be deploying the whole VNET and then the SUBNETS a whole second time here anyway, so the second subnet loop is redundant. Assume this may just be a sample for this repro. Otherwise if you are only wanting to deploy the subnet loop template (maybe for a DR exercise or change window) i.e. independently, then move to an existing resource for the vnet. That way it will ONLY process the subnet loop and not have to execute the VNET module at all. resource vnet 'Microsoft.Network/virtualNetworks@2021-02-01' existing = {
name: vnetName
}
resource subnet2 'Microsoft.Network/virtualNetworks/subnets@2021-02-01' = {
name: 'sub02'
parent: vnet
properties: {
addressPrefix: '10.1.1.0/24'
}
} Hopfully that gives you some ideas. |
Beta Was this translation helpful? Give feedback.
Hi @davidjhole
This is one of the items that is being worked on, in order to make this scenario easier #2246
To explain the current state... via your example:
Parent is not equivalent to Dependson. There is a separate dependsOn property.
When you use parent it expects a resource type reference. The reference to the Module (which can potentially do/contain anything and multiples of them) does not satisfy that reference (or a VNET).
Some the options are: