Nuno
Nuno

Reputation: 3612

Deploying Hybrid Connection to webapp using bicep

I'm trying to create an Hybrid Connection on a webapp using Bicep.

The documentation, unfortunately, has no descriptions in the properties of RelayServiceConnectionEntityProperties:

https://learn.microsoft.com/en-us/azure/templates/microsoft.web/sites/hybridconnection?tabs=bicep

This is what I tried:

resource webappHcm 'Microsoft.Web/sites/hybridconnection@2021-02-01' = {
  name: 'hcm'
  parent: webapp
  properties: {
    entityConnectionString: 'Endpoint=sb://xxxxxxx.servicebus.windows.net/;SharedAccessKeyName=defaultListener;SharedAccessKey=XXXXXXXXXXX;EntityPath=xxxxxxxxxxxxxxx'
    entityName: 'xxxxxxxxxxxxxxxxx'
    hostname: 'xxxxxxxxxxxxxxxxx.hostname.internal'
    port: 12345
    // resourceConnectionString: 'string'
    // resourceType: 'string'
  }
}

However, when I try to deploy, I get this error:

Required parameter EntityName, EntityConnectionString, ResoureType, ResourceConnectionString, Hostname, or BiztalkUri is missing.

I have no idea what to put in resourceConnectionString, resourceType nor biztalkUri.
Any ideas where I can find those, or what am I doing wrong?

Unfortunately, doing it on the Azure Portal manually, and then "Export template", the export doesn't have anything related to the hybrid connection (whether it is in the Webapp, or in the Hybrid Connection itself)

Upvotes: 1

Views: 1178

Answers (1)

KondzioSSJ4
KondzioSSJ4

Reputation: 260

for creating Hybrid-Connection for webs you need to have bicep file like:

param appServiceName string

var cfg = json(loadTextContent('../../bicepConsts.json'))
var hc = cfg.HybridConnection

resource appService 'Microsoft.Web/sites@2021-02-01' existing = {
  name: appServiceName
}

var relayId = resourceId(hc.ResourceGroup, 'Microsoft.Relay/namespaces', hc.Namespace)
var connectionId = '${relayId}/hybridConnections/${hc.Name}'
var senderKeyName = 'defaultSender'

var key = listKeys('${connectionId}/authorizationRules/${senderKeyName}', '2017-04-01').primaryKey


resource hybridConnection 'Microsoft.Web/sites/hybridConnectionNamespaces/relays@2021-02-01' = {
  name: '${appService.name}/${hc.Namespace}/${hc.Name}'
  location: hc.NamespaceLocation
  dependsOn: [
    appService
  ]
  properties: {
    serviceBusNamespace: hc.Namespace
    relayName: hc.Name
    relayArmUri: connectionId
    hostname: hc.Host
    port: hc.Port
    sendKeyName: senderKeyName
    sendKeyValue: key
    serviceBusSuffix: '.servicebus.windows.net'
  }
}

Where this bicepConsts file contains think like:

{ 
    "..." : "...",
    "HybridConnection": {
        "ResourceGroup": "resource group of your HybridConnection from Azure",
        "Name": "Name of hybrid connection",
        "Namespace": "Namespace of hybrid connection",
        "NamespaceLocation": "Location (e.g. 'West US 2') of your hybrid connection namespace",
        "Host": "Host of your hybrid connection",
        "Port": "Port of your hybrid connection AS INTEGER!",
    }
}

Upvotes: 3

Related Questions