Problem
I’m trying to use Bicep to create a Hybrid Connection on a webapp.
The documentation, unfortunately, has no descriptions in the properties of RelayServiceConnectionEntityProperties:
Here’s what I came up with:
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'
}
}
When I try to deploy, though, I get the following error:
I’m not sure what resourceConnectionString, resourceType, or biztalkUri should be. I’m not sure where to look for them, or what I’m doing wrong.
Unfortunately, if you do it manually on the Azure Portal and then “Export template,” the export will not include any information about the hybrid connection (whether it is in the Webapp, or in the Hybrid Connection itself)
Asked by Nuno
Solution #1
You’ll need a bicep file like this to create a Hybrid-Connection for webs:
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'
}
}
Consider what this bicepConsts file contains:
{
"..." : "...",
"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!",
}
}
Answered by KondzioSSJ4
Post is based on https://stackoverflow.com/questions/69760823/deploying-hybrid-connection-to-webapp-using-bicep