1
votes

I am trying to create an ARM template that will allow my to deploy VMs that may or may not need additional data disks. However when I test my template, I get the error below.

What is weird is that if the vmDataDisk parameter has a value of 0 or 1, all works perfectly. If that parameter has anything greater than 1, I get the error below.

For example the following works great: vmDataDisk = 1 and vmDataDiskSizesInGb = 30

However, the following values throw error below: vmDataDisk = 3, vmDataDiskSizesInGb = 10,20,30

Parameters Element - ARM json

  "parameters": {
    ...
    "vmDataDisks": {
      "type": "int",
      "defaultValue": 0,
      "allowedValues": [
        0,
        1,
        2,
        3,
        4,
        5
      ],
      "metadata": {
        "description": "Select the number of data disks (in addition to OS disk) needed for this VM."
      }
    },
    "vmDataDiskSizesInGb": {
      "type": "string",
      "defaultValue": 0,
      "metadata": {
        "description": "Enter string of comma separated values for the size of each data disk. For example, if the VmDataDisks parameter is set to '3', the VmDataDiskSizesInGb parameter might have a value of '10,25,50' and the template will deploy 3 data disks that are 10, 25 and 50 GB in size respectively."
      }
    }
  }

Variables Element - ARM json

"variables": {
    ...
    "diskSizes":  "[split(parameters('vmDataDiskSizesInGb'), ',')]",
    "copy": [
      {
        "name": "dataDisks",
        "count": "[if(equals(parameters('vmDataDisks'),0), 1, parameters('vmDataDisks'))]",
        "input": {
          "name": "[concat(parameters('vmName'), '_DataDisk_', copyIndex('dataDisks'))]",
          "lun": "[copyIndex('dataDisks')]",
          "createOption": "Empty",
          "diskSizeGB": "[if(equals(parameters('vmDataDisks'),0), 1, int(variables('diskSizes')[copyIndex()]))]",
          "caching": "[if(startsWith(parameters('vmType'), 'SQL'), 'ReadOnly', 'None')]",
          "managedDisk": {
            "storageAccountType": "Premium_LRS"
          }
        }
      }
    ]
  }

Resources Element - ARM json

"resources": [
    {
      "type": "Microsoft.Compute/virtualMachines",
      "name": "[parameters('vmName')]",
      "apiVersion": "2017-03-30",
      "location": "[parameters('location')]",
      "dependsOn": [],
      "properties": {
        "hardwareProfile": {},
        "osProfile": {},
        "storageProfile": {
          "imageReference": {},
          "osDisk": {},
          "dataDisks": "[if(equals(parameters('vmDataDisks'),0), json('null'), variables('dataDisks'))]"
        },
        "networkProfile": {},
        "diagnosticsProfile": {}
      }
    }
  ]

Test-AzureRmResourceGroupDeployment Error

Code : InvalidTemplate
Message : Deployment template language expression evaluation failed: 'The language expression property '0' can't be evaluated.'. Please see https://aka.ms/arm-template-expressions for usage details.
Details :

1

1 Answers

0
votes

The error says that the language expression you used in your template cannot be evaluated. For other words, the language expression you used does not meet the rules of the template. And the wrong expression property is ‘0’.

So you should check all your expression with property ‘0’ compared with the document that the error post: https://aka.ms/arm-template-expressions.

update

In the template code you post, the parameter "vmDataDiskSizesInGb" type is string and your "defaultValue" is 0, it's not correct, you should give "0" to it.

But I'm not sure if you have any other error,so I suggest you check all your expression with property ‘0’ compared with the document that the error post: https://aka.ms/arm-template-expressions.