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:

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

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:

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

A quick example:

resource appService 'Microsoft.Web/sites@2021-02-01' = {
  name: websiteName
  location: location
  identity:{
    type:'SystemAssigned'
  }
  properties: {
    serverFarmId: appServicePlan.id
    siteConfig: {
      linuxFxVersion: linuxFxVersion
    }
  }
}

resource appInsights 'Microsoft.Insights/components@2020-02-02' = {
  name: insightsName
  location: location
  kind: 'web'
  properties:{
    Application_Type:'web'
    WorkspaceResourceId: workspace.id
  }
  tags: {
    'hidden-link:${appService.id}': 'Resource'
  }
}