When deploying an Azure Resource Manager template (ARM template), you must provide a location for each resource. Locations can either be added in a template directly or passed as a parameter. It’s advisable to use a parameter to specify the location of resources.
When deploying an Azure Resource Manager template (ARM template), you must provide a location for each resource. This can be done directly in the template or by passing parameters. However, hardcoding locations in the template can limit flexibility and potentially create deployment challenges, restricting users from choosing their preferred deployment location.
It is therefore recommended to use a parameter to specify the location for resources, with the default value set to
resourceGroup().location. This practice ensures consistency in resource allocation and provides users of the template the flexibility to
specify a location where they have the necessary permissions to deploy resources. This approach helps avoid hardcoding locations, which can lead to
potential deployment issues and restrictions.
Create a parameter for the location and set the default value to resourceGroup().location. Then, use the parameter to specify the
location of resources.
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2022-09-01",
"name": "[parameters('storageAccountName')]",
"location": "westus",
"sku": {
"name": "Standard_LRS"
},
"kind": "StorageV2"
}
]
}
{
"$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": "Location for all resources."
}
}
},
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2022-09-01",
"name": "[parameters('storageAccountName')]",
"location": "[parameters('location')]",
"sku": {
"name": "Standard_LRS"
},
"kind": "StorageV2"
}
]
}
Create a parameter for the location and set the default value to resourceGroup().location. Then, use the parameter to specify the
location of resources.
resource storageAccount 'Microsoft.Storage/storageAccounts@2022-09-01' = {
name: storageAccountName
location: 'westus'
sku: {
name: 'Standard_LRS'
}
kind: 'StorageV2'
}
param location string = resourceGroup().location
resource storageAccount 'Microsoft.Storage/storageAccounts@2022-09-01' = {
name: storageAccountName
location: location
sku: {
name: 'Standard_LRS'
}
kind: 'StorageV2'
}