4
votes

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.

1

1 Answers

1
votes

Your ARM template syntax to get the resource group tag below is correct.

"[resourceGroup().tags.tag1]"

You need to make sure your resource group has the above mentioned tags created before deploy your ARM template in order to get the specific tag's value.

"tags": { "tag1": "test" },

I am able to reproduce your exact error when I try to deploy the ARM template to get the resource group tag which is not yet created.

I am also able to get the resource group tag value as expected in my ARM template deployment when I created the tag to resource group before the deployment.

{
  "id": "/subscriptions/{id}/resourceGroups/ResourceGroupwithTag",
  "name": "ResourceGroupwithTag",
  "location": "southeastasia",
  "tags": {
    "displayName": "test"
  },
  "properties": {
    "provisioningState": "Succeeded"
  }
}

Output section of my ARM template to display the resource group tag.

"outputs": {
    "rgTag": {
        "type": "String",
        "value": "[resourceGroup().tags.displayName]"
    }
}

enter image description here

Hope this helps!