title: Azure Virtual Machine ARM Template CopyIndex exclude avSet
body: <p>I'm trying to deploy a number of Virtual Machines from a Variable Object, some of the virtual machines need to be added to an AVSet while others do not.</p>
  <p>I'm struggling to find a way to iterate through the object while excluding AVSet etc.</p>
  <pre><code>    &quot;virtualMachineSettings&quot;: [
          {
              &quot;name&quot;: &quot;WEBSERVER&quot;,
              &quot;subnet&quot;: &quot;web&quot;,
              &quot;vmSize&quot;: &quot;Standard_B2ms&quot;,
              &quot;publisher&quot;: &quot;[parameters('standardVMPublisher')]&quot;,
              &quot;offer&quot;: &quot;[parameters('standardVMoffer')]&quot;,
              &quot;sku&quot;: &quot;[parameters('standardVMsku')]&quot;,
              &quot;avset&quot;: &quot;webServersAVSet&quot;
          },  
          {
              &quot;name&quot;: &quot;APPSERVER&quot;,
              &quot;subnet&quot;: &quot;app&quot;,
              &quot;vmSize&quot;: &quot;Standard_B2ms&quot;,
              &quot;publisher&quot;: &quot;[parameters('standardVMPublisher')]&quot;,
              &quot;offer&quot;: &quot;[parameters('standardVMoffer')]&quot;,
              &quot;sku&quot;: &quot;[parameters('standardVMsku')]&quot;,
              &quot;avset&quot;: &quot;appServersAVSet&quot;
          },
          {
              &quot;name&quot;: &quot;TESTSERVER&quot;,
              &quot;subnet&quot;: &quot;data&quot;,
              &quot;vmSize&quot;: &quot;Standard_B2ms&quot;,
              &quot;publisher&quot;: &quot;[parameters('standardVMPublisher')]&quot;,
              &quot;offer&quot;: &quot;[parameters('standardVMoffer')]&quot;,
              &quot;sku&quot;: &quot;[parameters('standardVMsku')]&quot;,
              &quot;avset&quot;: &quot;&quot;
          },
          {
              &quot;name&quot;: &quot;SQLSERVER&quot;,
              &quot;subnet&quot;: &quot;data&quot;,
              &quot;vmSize&quot;: &quot;Standard_B4ms&quot;,
              &quot;publisher&quot;: &quot;MicrosoftSQLServer&quot;,
              &quot;offer&quot;: &quot;SQL2017-WS2016&quot;,
              &quot;sku&quot;: &quot;SQLDEV&quot;,
              &quot;avset&quot;: &quot;&quot;
          }
  
      ],
  
          {
              &quot;type&quot;: &quot;Microsoft.Compute/virtualMachines&quot;,
              &quot;apiVersion&quot;: &quot;2019-07-01&quot;,
              &quot;name&quot;: &quot;[concat(variables('VirtualMachineSettings')[copyIndex()].name, '-', parameters('octopusTenant'))]&quot;,
              &quot;copy&quot;: {
                  &quot;name&quot;: &quot;vmIterator&quot;,
                  &quot;count&quot;: &quot;[length(variables('VirtualMachineSettings'))]&quot;
              },
              &quot;dependsOn&quot;: [
                  &quot;[concat('Microsoft.Network/networkInterfaces/', variables('virtualMachineSettings')[copyIndex()].name, '-', parameters('octopusTenant'),'-NIC')]&quot;,
                  &quot;avSet&quot;
              ],
              &quot;location&quot;: &quot;[resourceGroup().location]&quot;,
              &quot;tags&quot;: {
              },
              &quot;properties&quot;: {
                  &quot;hardwareProfile&quot;: {
                      &quot;vmSize&quot;: &quot;[variables('virtualMachineSettings')[copyIndex()].vmSize]&quot;
                  },
                   &quot;availabilitySet&quot;: {
                      &quot;id&quot;: &quot;[resourceId('Microsoft.Compute/availabilitySets',variables('virtualMachineSettings')[copyIndex()].avSet)]&quot;
                  },
  </code></pre>
  <p>So I think I need to set an if statement if the parameter avset is empty? but I'm stuck.  Any help would be amazing.</p>
  <p>Thanks</p>