Reputation: 13
It seems like azure processes a nested template dependencies and fails if it doesn't find a resource.
For example, I have 3 nested templates:
Template Json:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"apiVersion": "2017-05-10",
"name": "VnetTemplate",
"type": "Microsoft.Resources/deployments",
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"properties":{
"subnets":[
{
"properties":{
"addressPrefix":"10.0.0.0/24"
},
"name":"default"
}
],
"addressSpace":{
"addressPrefixes":[
"10.0.0.0/24"
]
}
},
"type":"Microsoft.Network/virtualNetworks",
"location":"[resourceGroup().location]",
"name":"my_vnet",
"apiVersion":"2017-10-01"
},
{
"properties":{
"resolutionVirtualNetworks":[
{
"id":"[resourceId('Microsoft.Network/virtualNetworks/','my_vnet')]"
}
],
"zoneType":"Private"
},
"type":"Microsoft.Network/dnsZones",
"location":"global",
"dependsOn":["my_vnet"],
"name":"my.dns",
"apiVersion":"2017-10-01"
}
]
}
}
},
{
"apiVersion": "2017-05-10",
"name": "NicTemplate",
"type": "Microsoft.Resources/deployments",
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"properties":{
"ipConfigurations":[
{
"properties":{
"privateIPAllocationMethod":"Dynamic",
"subnet":{
"id":"[resourceId('Microsoft.Network/virtualNetworks/subnets', 'my_vnet', 'default')]"
}
},
"name":"app_vnic_IPConf"
}
]
},
"type":"Microsoft.Network/networkInterfaces",
"location":"[resourceGroup().location]",
"name":"app_vnic",
"apiVersion":"2017-10-01"
}
]
}
},
"dependsOn":[
"VnetTemplate"
]
},
{
"apiVersion": "2017-05-10",
"name": "DnsRecordTemplate",
"type": "Microsoft.Resources/deployments",
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"properties":{
"TTL":3600,
"ARecords":[
{
"ipv4Address":"[reference(resourceId('Microsoft.Network/networkInterfaces/','app_vnic'), '2017-10-01').ipConfigurations[0].properties.privateIPAddress]"
}
]
},
"type":"Microsoft.Network/dnsZones/A",
"name":"my.dns/my_app",
"apiVersion":"2017-10-01"
}
]
}
},
"dependsOn": [
"NicTemplate"
]
}
]
}
I'd expected that the last nested template would not be process until the first 2 are done, but that's not the case.
(This example simplify the issue I have with much bigger template, deployed on multiple resource groups)
Any idea how to deal with it?
Upvotes: 1
Views: 295
Reputation: 72151
This is not true, if you deploy your template one more time it will work and the deployments will wait for one another. So there is nothing wrong with dependsOn properties in your template. If you look at the error, however, you will notice that the error is talking about app_vnic
NIC not found. This error comes from the reference function, not from the nested INLINE template starting before it should (according to the dependencies).
To work around this, you need to convert your template with a reference function into a regular nested template (not inline). upload it to some publicly accessible place and reference it like this:
{
"name": "NestedDeployment1",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2015-01-01",
"dependsOn": [
"NicTemplate"
],
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "url_goes_here",
"contentVersion": "1.0.0.0"
}
}
}
this way it will work.
I have to admit this is kind of a bug, but to be fair, nested INLINE templates are full of weird behaviours, I'd advice against using them (unless you know what you are doing).
Upvotes: 1