Search code examples
azureazure-rm-template

How to put multiple destination port ranges in ARM templates?


I have a long list of destination port ranges, 12000-13000, 2000-3000, 443. How do I put all these port ranges in the ARM templates?

{
    "name": "test-nsg",
    "type": "Microsoft.Network/networkSecurityGroups",
    "apiVersion": "2020-06-01",
    "location": "[variables('location')]",
    "properties": {
        "securityRules": [                {
                "name": "Allow ports",
                "properties": {
                    "priority": 1000,
                    "sourceAddressPrefix": "*",
                    "protocol": "TCP",
                    "destinationPortRanges": [
                        "443",
                        ""
                    ],
                    "access": "Allow",
                    "direction": "Inbound",
                    "sourcePortRange": "*",
                    "destinationAddressPrefix": "*"
                }
            }]
    }
}

Solution

  • You can pass multiple destination port ranges in your arm template as shown in below

    "destinationPortRanges":  ["1200-1300","2000-3000","443","22"]
    

    enter image description here

    Alternatively, you can pass those multiple destinations port ranges values by creating a parameter for ports of type array & calling those parameters in the resources block as shown in below

    "parameters":{
       "port":{
          "type":"array",
          "defaultValue":[
             "1200-1300",
             "15000-16000",
             "443"
          ]
       }
    }
    

    In resources block :

      "destinationPortRanges":  "[parameters('port')]"
    

    enter image description here