From a resource group with a tag defined named tag1
(did it through the portal), I have the following deployment template in Visual Studio:
{
"name": "appsettings",
"type": "config",
"apiVersion": "2015-08-01",
"dependsOn": [
"[resourceId('Microsoft.Web/sites', variables('websiteName'))]"
],
"tags": {
"displayName": "website AppSettings"
},
"properties": {
"Setting1": "[resourceGroup().tags.tag1]",
"Setting2": "[parameters('param2')]"
}
}
I get the this error:
... 'The language expression property 'tags' doesn't exist, available properties are 'id, name, location, properties'...
But using https://resources.azure.com I can see that resource group has the tag
property indeed:
{
"id": "/subscriptions/{someguid}/resourceGroups/resourceGroup1",
"name": "resourceGroup1",
"location": "brazilsouth",
"tags": {
"tag1": "test"
},
"properties": {
"provisioningState": "Succeeded"
}
}
Is there any way to get the resource group tags inside the deployment template?
Update
As @juvchan pointed out, tags must exist or this error happens. I created the tag, but when deploying the template from VisualStudio tags are deleted, when deploying from the portal tags are kept. This lead to different issue and question.
Reason for this is the visual studio project has a PowerShell script with this line:
#Create or update the resource group using the specified template file and template parameters file
New-AzureRmResourceGroup -Name $ResourceGroupName -Location $ResourceGroupLocation -Verbose -Force -ErrorAction Stop
But the New-AzureRmResourceGroup
cmdlet does not keep existing tags. Be aware. Solution: modify script to not run the cmdlet if resource group already exist.