title: Handling dependencies in Azure Resource Manager Linked Templates
body: <p>Azure Resource Manager (ARM) Templates have the ability to use <a href="https://azure.microsoft.com/en-us/documentation/articles/resource-group-linked-templates/" rel="noreferrer">Linked Templates</a>. These linked templates can define additional resources to create during an ARM template deployment. </p>
  
  <p>ARM templates support <a href="https://azure.microsoft.com/en-us/documentation/articles/resource-group-define-dependencies/" rel="noreferrer">dependencies</a> which ensure some resources are created before others are. </p>
  
  <p>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:</p>
  
  <pre class="lang-json prettyprint-override"><code>"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')]"
          }
      }
  ]
  </code></pre>
  
  <p>While the <code>dependsOn</code> appears correct, the a resource is created at <code>Microsoft.Web/sites/{siteNameParameter}</code>, deploying the ARM template outputs the following error message:</p>
  
  <blockquote>
    <p>InvalidTemplate : Deployment template validation failed: 'The resource 'Microsoft.Web/sites/blahblahblahblah' is not defined in the template. Please see <a href="https://aka.ms/arm-template" rel="noreferrer">https://aka.ms/arm-template</a> for usage details.'.</p>
  </blockquote>
  
  <p>I am currently defining this dependency in the <em>master</em> 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?</p>
  
  <pre class="lang-json prettyprint-override"><code>{
      "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')]"
              }
          }
      }
  }
  </code></pre>