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.
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.
Remove allowedValues for the parameter specifying the location.
{
"$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"
]
}
}
}
{
"$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]"
}
}
}
Remove allowedValues for the parameter specifying the location.
@allowed([ 'eastus' 'westus' 'northeurope' 'westeurope' 'southeastasia' ]) // Noncompliant param location string = resourceGroup().location
param location string = resourceGroup().location