Home Copy element within copy element in Azure ARM deployment template to create multiple instances of a resource
Reply: 0

Copy element within copy element in Azure ARM deployment template to create multiple instances of a resource

user1759
1#
user1759 Published in April 27, 2018, 6:52 am

I'm trying to create do a "nested for loop" in my Azure ARM deployment template via the copy element feature to create multiple instance of the same resource type (Microsoft.Web/sites/hostnameBindings in my case)

More specifically I'm trying to bind multiple hostnames to multiple apps (azure app service websites).

Is this possible? Or would I need to go down the linked templates path?

Here is my attempt so far but I can't get it to work.

parameters.json

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {    
    "appList": {
      "value": [
        { "appName": "app1", "hostNames": [ "app1.qqq.example.com", "app1.ttt.example.com" ] },
        { "appName": "app2", "hostNames": [ "app2.qqq.example.com" , "app2.ttt.example.com" ] },
        { "appName": "app3", "hostNames": [ "app3.qqq.example.com", "app3.ttt.example.com" ] }    
      ]
    }    
  }
}

template.json

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {    
    "appList": { "type": "array"  }
  },  
  "resources": [
    {
      "type": "Microsoft.Web/sites/hostnameBindings",
      "name": "parameters('appList')[copyIndex('webAppCopy')]/parameters('appList')[copyIndex('webAppCopy')].hostNames",
      "copy": [
        {
          "name": "webAppCopy",
          "count": "[length(parameters('appList'))]"
        }        
      ],
      "apiVersion": "2016-03-01",
      "location": "[resourceGroup().location]"
    }
  ],
  "outputs": {}
}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.368286 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO