EilonA
EilonA

Reputation: 581

ARM nested template ‘Invalid Template could not find template resource’

I'm deploying arm template to create an SSL certificate to existing traffic managers and to bind the certificates to the app services. Since the app services in one resource group and the traffic manager and certificate in a different resource group - I use nested template. i got an error with my certificate SSL:

Deployment template validation failed: 'The template reference 'blabla-ssl1' is not valid: could not find template resource or resource copy with this name

  "comments": "Get the Traffic Manager SSL cert that will be binded to the app",
  "copy": {
    "name": "loop",
    "count": "[length(variables('locations'))]"
  },
  "type": "Microsoft.Web/certificates",
  "name": "[concat(variables('tmsslcert')['secretname'], copyIndex())]",
  "apiVersion": "2016-03-01",
  "location": "[variables('locations')[copyIndex()]]",
  "dependsOn": [
    "[variables('TMName')]"
  ],
  "properties": {
    "keyVaultId": "[variables('tmsslcert')['KeyVaultId']]",
    "secretname": "[variables('tmsslcert')['secretname']]"
  }
},
{
  "type": "Microsoft.Resources/deployments",
  "apiVersion": "2018-05-01",
  "resourceGroup": "[variables('webappResourceGroup')]",
  "name": "[concat('AddTMSSLCert_',variables('locations')[copyIndex()],'_nestedTemplate')]",
  "copy": {
    "name": "endpointloop",
    "count": "[length(variables('locations'))]"
  },
  "properties": {
    "mode": "Incremental",
    "template": {
      "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "resources": [
        {
          "comments": "app hostname binding of TM CNAME",
          "type": "Microsoft.Web/sites/hostNameBindings",
          "name": "[concat(variables('webappDNSNamePrefix'), '-', variables('locations')[copyIndex()], '/', variables('tmcname'))]",
          "apiVersion": "2016-08-01",
          "location": "[variables('locations')[copyIndex()]]",
          "scale": null,
          "properties": {
            "siteName": "variables('webappDNSNamePrefix'), '-', variables('locations')[copyIndex()]",
            "sslState": "SniEnabled",
            "thumbprint": "[reference(resourceId(variables('webappResourceGroup'),'Microsoft.Web/certificates', concat(variables('tmsslcert')['secretname'], copyIndex())),'2016-03-01').Thumbprint]"
          },
          "dependsOn": [
            "[concat(variables('tmsslcert')['secretname'], copyIndex())]",
            //"[concat('Microsoft.Web/certificates/', variables('tmsslcert')['secretname'], copyIndex())]"
          ]
        }
      ]
    }
  }
}

Upvotes: 0

Views: 3368

Answers (1)

4c74356b41
4c74356b41

Reputation: 72191

its impossible to tell where the error is exactly (given the data you provided), but this means either your references or dependsOn are trying to reach the resource that's either not created or in a different resource group. One thing that looks specifically wrong is this:

"dependsOn": [
    "[concat(variables('tmsslcert')['secretname'], copyIndex())]",
    //"[concat('Microsoft.Web/certificates/', variables('tmsslcert')['secretname'], copyIndex())]"
]

this would not work, because it will work in the context of the nested deployment, so in a different resource group

Upvotes: 2

Related Questions