azureazure-rm-templatenetwork-security-groups

How to use multiple destination port in single NSG SecurityRule in ARM template


I want to use single securityRule in NSG instead of separate rule for each destination port.

I have used destinationPortRanges with multiple ports in below template instead of destinationPortRange with single ports.

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

When I try to run the above template using Azure CLI, I am unable to proceed due to the following error

The template deployment 'test' is not valid according to the validation procedure. The tracking id is '0ee64525-9d2b-49cb-bac7-24baa73ac1d7'. See inner errors for details. Please see https://aka.ms/arm-deploy for usage details.

Update:-

{"error":{"code":"InvalidTemplateDeployment","message":"The template deployment \'test\' is not valid according to the validation procedure. The tracking id is \'1e7527bc-6c7f-4aa9-8ed6-235402a229b7\'. See inner errors for details. Please see https://aka.ms/arm-deploy for usage details.","details":[{"code":"InvalidResourceName","message":"Resource name Allow ports is invalid. The name can be up to 80 characters long. It must begin with a word character, and it must end with a word character or with \'_\'. The name may contain word characters or \'.\', \'-\', \'_\'.","details":[]}]}}'
msrest.exceptions : The template deployment 'test' is not valid according to the validation procedure. The tracking id is '1e7527bc-6c7f-4aa9-8ed6-235402a229b7'. See inner errors for details. Please see https://aka.ms/arm-deploy for usage details.

I got the above error, After renaming the security rule name, issue got resolved.


Solution

  • The error was due to the bad security rule name.