Deployment template validation failed: Circular dependency detected on resource
I was writing this article “How to use ARM templates for deployments” and received this error when I click the purchase button from within the portal.
Deployment template validation failed: "Circular dependency detected on resource:
"/subscriptions/25ec5/resourceGroups/HCM/providers/Microsoft.Network/networkInterfaces/hcm00146";.
Please see https://aka.ms/arm-template/#resources for usage details.". (Code: InvalidTemplate)
Here is a list of some actions to take if you get this exception “Solution 5 - circular dependency detected”.
I did what the articles said and simply removed some of the DepndsOn settings in the JSON file, I was optimistically suprised when the script ran with such little effort, that feeling was quickly squashed, Figure 1.
Figure 1, ARM deployment failed
Let the effort begin…
To start with, I deleted everything and then recreated my VM and watched real close what was being created and when. I clicked the create button, navigated to the Resource Group blade and hit the Refresh button repeatedly watching what was being created and in what order. Here is what I saw.
- Batch 1 – IP, NSG and VNET
- Batch 2 – Network Interface
- Batch 3 – Storage Account
- Batch 4 – Virtual Machine and Disk
But that didn’t turn out to be the issue. Ultimatly, there was a indeed a ‘circular reference’ which required me to read through the entire template and find it, just like the instructions said. Here is what I found, perhaps had I started with a simplier template, I would have found it faster.
The Virtual Machine contained a dependsOn reference to my network interface:
"[resourceId('Microsoft.Network/networkInterfaces', parameters('networkInterfaces_hcm001446_name'))]";
And my network interface containded a dependsOn reference to my Virtual Machine:
"[resourceId('Microsoft.Compute/virtualMachines', parameters(';virtualMachines_HCM001_name'))]"
Working through many paths towards finding which to remove, I concluded to remove the dependsOn reference in the network interface configuration. Whihc means that the network interface is not dependent on the Virtual Machine but the Virtual Machine is dependent on the network interface. Once I did that, the script worked as expected.
The path which solved it for me was that I created a similar deployment template using Visual Studio, as discussed here and I saw no dependsOn from the network interface to the virtual machine in the generated template.
To get a overview of the project I worked on, read the following articles as well.
- Required parameter ‘adminPassword’ is missing (null).
- osDisk.managedDisk.id’ is not allowed
- Creating an Azure App Service Hybrid Connection
- How to deploy to Azure using an ARM template with PowerShell
- How to use/create ARM templates for deployments
- Deployment template validation failed: Circular dependency detected on resource
- How to Azure Function App with Hybrid Connection
- Troubleshooting App Service Hybrid Connection Manager