Skip to content

Use type string for location parameters#

Operational Excellence · All resources · Azure.Template.LocationType

Location parameters should use a string value.

Description#

The template parameter location is a standard parameter recommended for deployment templates. The location parameter is a intended for specifying the deployment location of the primary resource. When including location parameters in templates use the type string.

Additionally, the template may include other resources. Use the location parameter value for resources that are likely to be in the same location. This approach minimizes the number of times users are asked to provide location information.

Recommendation#

Consider updating the location parameter to be of type string.

Examples#

Configure with Azure template#

To author templates that pass this rule:

  • If the location parameter is specified, it should be set to a string type.

For example:

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "location": {
            "type": "string",
            "defaultValue": "[resourceGroup().location]",
            "metadata": {
                "description": "The location resources will be deployed."
            }
        }
    },
    "resources": [
        {
            "type": "Microsoft.Network/networkSecurityGroups",
            "apiVersion": "2021-02-01",
            "name": "nsg-001",
            "location": "[parameters('location')]",
            "properties": {
                "securityRules": [
                    {
                        "name": "deny-hop-outbound",
                        "properties": {
                            "priority": 200,
                            "access": "Deny",
                            "protocol": "Tcp",
                            "direction": "Outbound",
                            "sourceAddressPrefix": "VirtualNetwork",
                            "destinationAddressPrefix": "*",
                            "destinationPortRanges": [
                                "3389",
                                "22"
                            ]
                        }
                    }
                ]
            }
        }
    ]
}

Configure with Bicep#

To author bicep source files that pass this rule:

  • If the location parameter is specified, it should be set to a string type.

For example:

@description('The location resources will be deployed.')
param location string = resourceGroup().location

Last update: 2021-09-24