简体   繁体   中英

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?

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

Should the parameter just be ?

"availabilityZoneParameter": {
  "value": "1"
}

Final syntax, for those coming to this board seeking the same answer:

Note that the value is an array and not a string, as pointed out by contributor 4c74356b41 in this thread.

In original azureparameter file:

    },
"availabilityZone": {
  "value": [ "3" ]
}

In azuredeploy file:

    },
"availabilityZone": {
  "type": "array"
}

To call the availability zone parameter in nested template (example using storage disk resource):

  "name": "[variables('diskName')]",
  "type": "Microsoft.Compute/disks",
  "apiVersion": "2017-03-30",
  "location": "[resourceGroup().location]",
  "zones": "[parameters('availabilityZone')]",
  "sku": {

If using a linked template, when expressing the linked template parameters, I used this syntax:

"avZone": {
  "value": "[parameters('availabilityZone')]"

Importing the parameter in the linked template:

    },
"avZone": {
  "type": "array"
}

And then in the resources within the linked template, I called the parameter in the same way as the azuredeploy template:

  "apiVersion": "[variables('apiVersion')]",
  "type": "Microsoft.Compute/virtualMachines",
  "name": "[parameters('vmName')]",
  "location": "[parameters('location')]",
  "zones": "[parameters('avZone')]",

As you can see, I decided not to turn it into a variable as this was unnecessary in my case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM