azureazure-web-app-serviceazure-application-insightsazure-bicepazure-monitor-workbooks

How to link my workbook resource with another resource


I have created a simple workbook template via Bicep without any settings.

I'd like to integrate/link it with another resource, for example application insights using Bicep and deploy it to Azure with my pipeline.

However, I do not know how I can link them together. If it is not possible, how can I link the workbook template to an App Service resource or another resource instance?

This is my workbook Bicep:

@description('The unique guid for this workbook instance.')
param workbookId string

@description('The location of the resource.')
param location string

@description('The friendly name for the workbook that is used in the Gallery or Saved List. Needs to be unique in the scope of the resource group and source.')
param workbookName string

@description('The gallery that the workbook will been shown under. Supported values include workbook, `tsg`, Azure Monitor, etc.')
param workbookType string = 'tsg'

@description('The id of resource instance to which the workbook will be associated.')
param workbookSourceId string = '<insert-your-resource-id-here>'

resource workbook 'Microsoft.Insights/workbooks@2022-04-01' = {
  name: workbookId
  location: location
  kind: 'shared'
  properties: {
    displayName: workbookName
    serializedData: '{"version":"Notebook/1.0","items":[{"type":1,"content":"{\\"json\\":\\"Hello World!\\"}","conditionalVisibility":null}],"isLocked":false}'
    version: '1.0'
    sourceId: workbookSourceId
    category: workbookType
  }
}

output workbookId string = workbook.id

And this is my Application Insights:

@description('Name of Application Insights resource.')
param appName string

@description('Type of app you are deploying. This field is for legacy reasons and will not impact the type of App Insights resource you deploy.')
param type string = 'web'

@description('Which Azure Region to deploy the resource to. This must be a valid Azure regionId.')
param regionId string

@description('Source of Azure Resource Manager deployment.')
param requestSource string

@description('Log Analytics workspace ID to associate with your Application Insights resource.')
param workspaceResourceId string

//param deployWorkspaceDiagnosticSettings bool = true

// @description('See documentation on tags: https://learn.microsoft.com/azure/azure-resource-manager/management/tag-resources.')
// param tagsArray object

resource applicationInsights 'Microsoft.Insights/components@2020-02-02' = {
  name: appName
  location: regionId
  // tags: tagsArray
  kind: 'other'
  properties: {
    Application_Type: type
    Flow_Type: 'Bluefield'
    Request_Source: requestSource
    WorkspaceResourceId: workspaceResourceId
  }
}

@description('Get Application Insights ID.')
output appIdOutput string = applicationInsights.id

@description('Get Application Type.')
output appTypeOutput string = applicationInsights.properties.Application_Type

@description('Get Instrumentation Key.')
output appInstrumentationKeyOutput string = applicationInsights.properties.InstrumentationKey

Solution

  • @description('The id of resource instance to which the workbook will be associated.')
    param workbookSourceId string = '<insert-your-resource-id-here>'
    

    This is what links the workbook to a resource. that workbookSourceId would be the resource id of the application insights resource, which you'd create first (if you want to link it to the app insights resource)

    how you actually do that in bicep specifically i do not know, but it appears you already do similar with workspaceResourceId?