Search code examples
azurejenkinscloudinfrastructure-as-code

Azure availability zone parameter syntax


I'm trying to parameterise a VM deployment that uses availability zones. However, I keep receiving this error on deployment:

'The provided value for the template parameter 'availabilityZoneParameter' at line '1' and column '5118' is not valid.'

or:

"Deployment template parse failed: 'Error converting value \"[ '1' ]\" to type 'System.String[]'. Path ''.'."

The parameter file syntax is currently:

"availabilityZoneParameter": {
  "value": "[ '1' ]"
}

I am then porting it in as a parameter and turning it into a variable, before exporting it to other linked templates as well as using it in the initial build template.

Parameter in deploy file syntax:

"availabilityZoneParameter": {
  "type": "string"
}

Variable in original deploy file syntax:

"availabilityZone": "[parameters('availabilityZoneParameter')]"

Disk creation syntax in original deploy file:

    {
  "name": "[variables('diskName')]",
  "type": "Microsoft.Compute/disks",
  "apiVersion": "2017-03-30",
  "location": "[resourceGroup().location]",
  "zones": [ "[variables('availabilityZone')]" ],
  "sku": {
    "name": "Standard_LRS"
  },
  "properties": {
    "creationData": {
      "createOption": "Empty"
    },
    "diskSizeGB": 1023
  }
},

VM parameter in original deploy template, which feeds into linked template:

      "name": "PAN-VM",
  "type": "Microsoft.Resources/deployments",
  "apiVersion": "2018-05-01",
  "dependsOn": [
    "[concat('Microsoft.Compute/disks/', variables('diskName'))]",
    "Microsoft.Resources/deployments/SettingUpVirtualNetwork",
    "Microsoft.Resources/deployments/SettingUpPublicIP",
    "Microsoft.Resources/deployments/SetupNetworkInterfaces"
  ],
  "properties": {
    "mode": "Incremental",
    "templateLink": {
      "uri": "[concat(variables('virtualMachineTemplate'), parameters('artifactsLocationSasToken'))]",
      "contentVersion": "1.0.0.5"
    },
    "parameters": {
"avZone": {
        "value": "[variables('availabilityZone')]"

VM template parameter:

    "avZone": {
  "type": "string"

VM template variable:

  "variables": {
"apiVersion": "2018-04-01",
"availabilityZone": "[parameters('avZone')]"

VM template resource (calling parameter):

  "resources": [
{
  "apiVersion": "[variables('apiVersion')]",
  "type": "Microsoft.Compute/virtualMachines",
  "name": "[parameters('vmName')]",
  "location": "[parameters('location')]",
  "zones": "[variables('availabilityZone')]",
  "plan": {
    "name": "[parameters('imageSku')]",
    "product": "[parameters('imageOffer')]",
    "publisher": "[parameters('imagePublisher')]"
  },
  "properties":

For context - there are several files at play here. An initial azureparameters file, an azuredeploy file, and then at least two linked templates which also rely on the availability zone value.

Any advice on the correct syntax?


Solution

  • According to the example I've found online, it should be like this:

    "availabilityZoneParameter": {
        "value": [ "1" ]
    }
    

    also, it should be array:

    "availabilityZoneParameter": {
        "type": "array"
    }
    

    As it excepts an array, not a string that looks like an array:

    https://github.com/Azure/azure-quickstart-templates/blob/master/101-vm-simple-zones/azuredeploy.json#L176