In Azure Resource Manager (ARM) templates, it is possible to set allowedValues for various parameters. This field is used to define a list of valid values for a parameter. This is a way to restrict the input values provided when deploying or updating a resource using the template.

However, when it comes to a parameter defining the location of a resource, this practice can lead to a code smell. Users may be unable to deploy such a template if their desired location is not included in the allowedValues.

Why is this an issue?

In Azure Resource Manager (ARM) templates, it is possible to set allowedValues for various parameters to limit the options and maintain control. However, when it comes to a parameter defining the location of a resource, this practice can lead to a code smell. Specifically, setting allowedValues for a location parameter can cause issues because the locations list might not be exhaustive or suitable for all users. Users may be unable to deploy such a template if their desired location is not included in the allowedValues, causing inconvenience and potential delays in their work.

How to fix it in ARM Templates

Remove allowedValues for the parameter specifying the location.

Code examples

Noncompliant code example

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
      "location": {
          "type": "string",
          "metadata": {
              "description": "The location in which the resources should be deployed."
          },
          "defaultValue": "[resourceGroup().location]",
          "allowedValues": [
              "eastus",
              "westus",
              "northeurope",
              "westeurope",
              "southeastasia"
          ]
      }
  }
}

Compliant solution

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
      "location": {
          "type": "string",
          "metadata": {
              "description": "The location in which the resources should be deployed."
          },
          "defaultValue": "[resourceGroup().location]"
      }
  }
}

How to fix it in Bicep

Remove allowedValues for the parameter specifying the location.

Code examples

Noncompliant code example

@allowed([
  'eastus'
  'westus'
  'northeurope'
  'westeurope'
  'southeastasia'
])  // Noncompliant
param location string = resourceGroup().location

Compliant solution

param location string = resourceGroup().location

Resources

Documentation