vamshi krishna
vamshi krishna

Reputation: 11

ARM template for VM creation with multiple disks

I want to deploy VM with multiple disks of count 2.I have used copy object but couldn't deploy getting the error message as Template deployment returned the following errors: Error: Code=InvalidTemplate; Message=Deployment template language expression evaluation failed: 'The template language function 'copyIndex' has an invalid argument. The provided copy name '' doesn't exist in the resource.

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "vkstorg1Type": {
      "type": "string",
      "defaultValue": "Standard_LRS",
      "allowedValues": [
        "Standard_LRS",
        "Standard_ZRS",
        "Standard_GRS",
        "Standard_RAGRS",
        "Premium_LRS"
      ]
    },
    "numDataDisks": {
      "type": "int",
      "defaultValue": 2,
      "minValue": 1,
      "maxValue": 64,
      "metadata": {
        "description": "This parameter allows the user to select the number of disks they want"
      }
    },
    "vm1111Name": {
      "defaultValue": "vm1111",
      "type": "string",
      "minLength": 1
    },
    "vm1111AdminUserName": {
      "defaultValue": "vamshivm2",
      "type": "string",
      "minLength": 1
    },
    "vm1111AdminPassword": {
      "defaultValue": "Vamshivm1111",
      "type": "securestring"
    },
    "vm1111WindowsOSVersion": {
      "type": "string",
      "defaultValue": "2012-R2-Datacenter",
      "allowedValues": [
        "2008-R2-SP1",
        "2012-Datacenter",
        "2012-R2-Datacenter",
        "Windows-Server-Technical-Preview"
      ]
    },
    "VMpublicIP1DnsName": {
      "defaultValue": "vm1111dns",
      "type": "string",
      "minLength": 1
    }
  },
  "variables": {
    "sizeOfDataDisksInGB": "50",
    "diskCaching": "ReadWrite",

    "vnet1Prefix": "10.0.0.0/16",
    "vnet1Subnet1Name": "Subnet-1",
    "vnet1Subnet1Prefix": "10.0.0.0/24",
    "vnet1Subnet2Name": "Subnet-2",
    "vnet1Subnet2Prefix": "10.0.1.0/24",
    "vkstorg1Name": "[concat('vkstorg1', uniqueString(resourceGroup().id))]",
    "subnet1Prefix": "10.0.0.0/16",
    "subnet1Subnet1Name": "Subnet-1",
    "subnet1Subnet1Prefix": "10.0.0.0/24",
    "subnet1Subnet2Name": "Subnet-2",
    "subnet1Subnet2Prefix": "10.0.1.0/24",
    "vm1111ImagePublisher": "MicrosoftWindowsServer",
    "vm1111ImageOffer": "WindowsServer",
    "vm1111OSDiskName": "vm1111OSDisk",
    "vm1111datadiskName1": "diskA1",
    "vm1111datadiskName2": "diskA2",
    "vm1111VmSize": "Standard_D2_v2",
    "vm1111VnetID": "[resourceId('Microsoft.Network/virtualNetworks', 'subnet1')]",
    "vm1111SubnetRef": "[concat(variables('vm1111VnetID'), '/subnets/', variables('subnet1Subnet1Name'))]",
    "vm1111StorageAccountContainerName": "vhds",
    "vm1111NicName": "[concat(parameters('vm1111Name'), 'NetworkInterface')]",
    "VMpublicIP1Name": "VMpublicIP1"
  },
  "resources": [
    {
      "name": "[parameters('vm1111Name')]",
      "type": "Microsoft.Compute/virtualMachines",
      "location": "[resourceGroup().location]",
      "apiVersion": "2015-06-15",
      "dependsOn": [
        "[resourceId('Microsoft.Storage/storageAccounts', variables('vkstorg1Name'))]",
        "[resourceId('Microsoft.Network/networkInterfaces', variables('vm1111NicName'))]"
      ],
      "tags": {
        "displayName": "vm1111"
      },
      "properties": {
        "hardwareProfile": {
          "vmSize": "[variables('vm1111VmSize')]"
        },
        "osProfile": {
          "computerName": "[parameters('vm1111Name')]",
          "adminUsername": "[parameters('vm1111AdminUsername')]",
          "adminPassword": "[parameters('vm1111AdminPassword')]"
        },
        "storageProfile": {
          "imageReference": {
            "publisher": "[variables('vm1111ImagePublisher')]",
            "offer": "[variables('vm1111ImageOffer')]",
            "sku": "[parameters('vm1111WindowsOSVersion')]",
            "version": "latest"
          },

          "osDisk": {
            "name": "[concat(parameters('vm1111Name'),copyindex(),'_OSDisk')]",
            "caching": "ReadWrite",
            "createOption": "FromImage"
          },
          "copy": [
            {
              "name": "dataDisks",
              "count": "[parameters('numDataDisks')]",
              "input": {
                "caching": "[variables('diskCaching')]",
                "diskSizeGB": "[variables('sizeOfDataDisksInGB')]",
                "lun": "[copyIndex('dataDisks')]",
                "name": "[concat(parameters('vm1111Name'), '-datadisk',copyIndex(), copyIndex('dataDisks'))]",
                "createOption": "Empty"
              }
            }
          ]
        },
        "networkProfile": {
          "networkInterfaces": [
            {
              "id": "[resourceId('Microsoft.Network/networkInterfaces', variables('vm1111NicName'))]"
            }
          ]
        }
      }
    },

  "outputs": {}
}

Template deployment returned the following errors: Error: Code=InvalidTemplate; Message=Deployment template language expression evaluation failed: 'The template language function 'copyIndex' has an invalid argument. The provided copy name '' doesn't exist in the resource.

Upvotes: 1

Views: 680

Answers (1)

4c74356b41
4c74356b41

Reputation: 72151

this is wrong:

"name": "[concat(parameters('vm1111Name'), '-datadisk',copyIndex(), copyIndex('dataDisks'))]",

it should be:

"name": "[concat(parameters('vm1111Name'), '-datadisk', copyIndex('dataDisks'))]",

Upvotes: 1

Related Questions