Home > Blockchain >  How to populate Azure SignalR Service's upstream code in Bicep
How to populate Azure SignalR Service's upstream code in Bicep

Time:05-25

I have a Bicep template to create an Azure SignalR Service per the following script. How can I obtain the upstream's code value within the bicep template and populate the urlTemplate's code value based on it? (the keyword TBD exhibits the exact spot in the following code.)

targetScope = 'resourceGroup'
param location string = resourceGroup().location
param signalRName string

resource signalR 'Microsoft.SignalRService/signalR@2022-02-01' = {
  name: signalRName
  location: location
  kind: 'SignalR'
  sku: {
    name: 'Free_F1'
    tier: 'Free'
    capacity: 1
  }
  properties: {
    features: [
      {
        flag: 'ServiceMode'
        value: 'Serverless'
      }
      {
        flag: 'EnableConnectivityLogs'
        value: 'true'
      }
      {
        flag: 'EnableMessagingLogs'
        value: 'true'
      }
      {
        flag: 'EnableLiveTrace'
        value: 'true'
      }
    ]
    liveTraceConfiguration: {
      enabled: 'true'
      categories: [
        {
          name: 'ConnectivityLogs'
          enabled: 'true'
        }
        {
          name: 'MessagingLogs'
          enabled: 'true'
        }
        {
          name: 'HttpRequestLogs'
          enabled: 'true'
        }
      ]
    }
    cors: {
      allowedOrigins: [
        '*'
      ]
    }
    upstream: {
      templates: [
        {
          hubPattern: '*'
          eventPattern: '*'
          categoryPattern: '*'
          auth: {
            type: 'None'
          }
          urlTemplate: 'https://${signalRName}.azurewebsites.net/runtime/webhooks/signalr?code=TBD'
        }
      ]
    }
  }
}

CodePudding user response:

I'm assuming that you are using a function app that has the same name as your signalR service.

Looking at the documentation:

  • The url always looks like that <Function_App_URL>/runtime/webhooks/signalr?code=<API_KEY>
  • the API_KEY is a function app systemkey called signalr_extension.

So you should be able to retrieve the key and use it like that:

var signalRKey = listKeys(resourceId('Microsoft.Web/sites/host', signalRName, 'default'), '2022-03-01').systemkeys.signalr_extension

resource signalR 'Microsoft.SignalRService/signalR@2022-02-01' = {
  name: signalRName
  ...
  properties: {
    ...
    upstream: {
      templates: [
        {
          ...
          urlTemplate: 'https://${signalRName}.azurewebsites.net/runtime/webhooks/signalr?code=${signalRKey}'
        }
      ]
    }
  }
}
  • Related