Ken Muse

Creating Hidden Links in Bicep


When creating an App Insights resource, you’ll often want to link that to Application Insights to ensure that you can effectively navigate between the two resources. Azure keeps track of that relationship with a special tag, hidden-link. This tag has limited documentation, but essentially it makes Azure aware that two resources have an association. The format of this tag requires you to put the resource identifier in the tag name and provide the tag value Resource. For example, in ARM Templates, this is expressed as:

1"tags": {
2    "hidden-link:/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupId}/providers/Microsoft.Web/{siteName}": "Resource"
3}

Most examples of using Bicep show how to create simple name/value pairs. Until recently, the property name required a fixed value. This made it challenging to implement the hidden-link. A recent enhancement to Bicep allows you to now take advantage of string interpolation with the property names as well. The improvement is simple — the property name is just expressed as a string.

This means that we can now use this expression in Bicep for the same purpose, linking to a resource in the same template:

1tags: {
2    'hidden-link:${resource.id}': 'Resource'
3}

A quick example:

 1resource appService 'Microsoft.Web/sites@2021-02-01' = {
 2  name: websiteName
 3  location: location
 4  identity:{
 5    type:'SystemAssigned'
 6  }
 7  properties: {
 8    serverFarmId: appServicePlan.id
 9    siteConfig: {
10      linuxFxVersion: linuxFxVersion
11    }
12  }
13}
14
15resource appInsights 'Microsoft.Insights/components@2020-02-02' = {
16  name: insightsName
17  location: location
18  kind: 'web'
19  properties:{
20    Application_Type:'web'
21    WorkspaceResourceId: workspace.id
22  }
23  tags: {
24    'hidden-link:${appService.id}': 'Resource'
25  }
26}