Azure Resource Manager (ARM) Templates have the ability to use Linked Templates. These linked templates can define additional resources to create during an ARM template deployment.
ARM templates support dependencies which ensure some resources are created before others are.
I would like to specify a dependency in a linked template for a resource created in the master template. If I include the dependency in the Linked Template, it looks like this:
"resources": [
{
"apiVersion": "2015-08-01",
"type": "Microsoft.Web/sites/hostNameBindings",
"name": "[concat(parameters('siteName'),'/', parameters('fqdn'))]",
"dependsOn": [
"[concat('Microsoft.Web/sites/', parameters('siteName'))]"
],
"properties": {
"siteName": "[parameters('siteName')]"
}
}
]
While the dependsOn
appears correct, the a resource is created at Microsoft.Web/sites/{siteNameParameter}
, deploying the ARM template outputs the following error message:
InvalidTemplate : Deployment template validation failed: 'The resource 'Microsoft.Web/sites/blahblahblahblah' is not defined in the template. Please see https://aka.ms/arm-template for usage details.'.
I am currently defining this dependency in the master template when I define the linked template call. This seems brittle and easy to break. Is there a better way than defining dependencies in the master ARM template?
{
"apiVersion": "2015-01-01",
"name": "SomeName",
"type": "Microsoft.Resources/deployments",
"dependsOn": [
"[concat('Microsoft.Web/sites/', parameters('siteName'))]"
],
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "https://tempuri.org/supersecrettemplatepath/azuredeploy.json",
"contentVersion": "1.0.0.0"
},
"parameters":
{
"fqdn": {
"value": "www.tempuri.org"
},
"siteName": {
"value": "[parameters('siteName')]"
}
}
}
}