ARM Template Availability Zone Deployment

Ens 1 Reputation point
2023-12-01T08:48:57.65+00:00

I want to set up a virtual machine using an ARM template, and I want users to choose an availability zone. However, since the Australia Southeast and westus regions don't have availability zones, I don't want users to have the options to select a zone. Whenever region is selected as westus, I want to disable zones 1,2,3 in dropdown menu.

Can ARM template provide this flexibility?

Thanks.

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,566 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Deepanshukatara-6769 7,980 Reputation points
    2023-12-04T05:40:06.6633333+00:00

    You can simply use condition like this

    "parameters": {
        "availabilityZone": {
            "type": "int",
            "allowedValues": [ 
               1,
               2,
               3
           ]
        }
    },
    "variables": {
        "isZone1": "[equals(parameters('availabilityZone'), 1)]",
        "isZone2": "[equals(parameters('availabilityZone'), 2)]",
        "isZone3": "[equals(parameters('availabilityZone'), 3)]"
    },
    "resources": [
        {
            "condition": "[variables('isZone1')]",
            "type": "Microsoft.Compute/...",
            // Resource configuration for Zone 1
        },
        {
            "condition": "[variables('isZone2')]",
            "type": "Microsoft.Compute/...",
            // Resource configuration for Zone 2
        },
        {
            "condition": "[variables('isZone3')]",
            "type": "Microsoft.Compute/...",
            // Resource configuration for Zone 3
        }
    ]
    
    
    1 person found this answer helpful.

  2. Deepanshukatara-6769 7,980 Reputation points
    2023-12-01T09:23:18.5566667+00:00

    Hi , hope doing well

    Yes, ARM templates do allow for conditional logic and parameterization, which can be used to provide different options based on region selections. To achieve the desired behavior of disabling specific zone options based on the region selected, you can utilize parameter dependencies and conditions in your ARM template.

    Here's an example of how you might structure your ARM template:

    1. Define parameters for region and availability zone:
    "parameters": {
        "region": {
            "type": "string",
            "allowedValues": [
                "Australia Southeast",
                "westus"
            ]
        },
        "availabilityZone": {
            "type": "int",
            "defaultValue": 1,
            "allowedValues": [1, 2, 3]
        }
    }
    
    
    
    1. Use conditions to disable zones based on the region selected:
    "variables": {
        "disableZonesForWestUS": "[equals(parameters('region'), 'westus')]"
    },
    "parameters": {
        "availabilityZone": {
            "type": "int",
            "defaultValue": 1,
            "allowedValues": {
                "if": "[variables('disableZonesForWestUS')]",
                "then": [1],
                "else": [1, 2, 3]
            }
        }
    }
    

    This example demonstrates how you can set up a parameter for the availability zone and use a condition to determine which zone options should be allowed based on the selected region. If 'westus' is selected, only zone 1 will be enabled; otherwise, zones 1, 2, and 3 will be available

    Please accept answer if it helps, Thanks