title: Iterate list using copy in ARM Template
body: <p>I have an ARM template in which I provision a number of web apps. I want to add IP restrictions on these web apps allowing access only between theses. I can retrieve the IPs using:</p>
  
  <pre><code>reference(resourceId(resourceGroup().name, 'Microsoft.Web/sites', parameters('appName1')),'2015-08-01').PossibleOutboundIpAddresses
  </code></pre>
  
  <p>It's the following that I don't know how to solve in a good manner.</p>
  
  <ol>
  <li><p>I have replaced the <code>resourceId(resourceGroup().name, 'Microsoft.Web/sites', parameters('appName1'))</code> part with a variable instead to shorten it a bit. Can I shorten it even more somehow? It becomes even more complex as you'll see soon.</p></li>
  <li><p>I have created a resources section for each web app in which there is a properties section. In this section the ipSecurityRestrictions resides. As the PossibleOutboundIpAddresses returns a string I use split to create a list and copy to iterate the IP addresses. But it does not work for me and returns the following error message: 
  <code>The template function 'copyIndex' is not expected at this location. The function can only be used in a resource with copy specified</code></p></li>
  </ol>
  
  <p>The section looks like this:</p>
  
  <pre><code>"resources": [
              {
                  "type": "config",
                  "name": "web",
                  "apiVersion": "2016-08-01",
                  "properties": {
                      "copy": [
                          {
                              "name": "ipSecurityRestrictions",
                              "count": "[length(split(reference(variables('appName1'),'2015-08-01').PossibleOutboundIpAddresses, ','))]",
                              "input": {
                                  "ipAddress": "[split(reference(variables('appName1'),'2015-08-01').PossibleOutboundIpAddresses, ',')[copyIndex('ipSecurityRestrictions')]]",
                                  "subnetMask": "255.255.255.254"
                              }
                          }
                      ],
                  },
                  "dependsOn": [
                      "[resourceId('Microsoft.Web/sites', parameters('appName1'))]"
                  ]
              }
          ]
  </code></pre>
  
  <p>I feel like I follow all examples I can find online exactly.
  Another problem with this is the many characters I'll have to write every time I want to reference the IP list. To make things worse, this list should be the merged one from all the provisioned web apps. So if I have 3 web apps the line is going to be incredible long and complicated.</p>
  
  <ol start="3">
  <li>Is there a better solution to this?</li>
  </ol>