0

I have created azure function app using arm template. But I want to create few hybrid connections under networking of the azure function like this below:

enter image description here

So, can anyone suggest me how to do this?

Pradeep
  • 5,101
  • 14
  • 68
  • 140
  • 1
    Does this help you? https://stackoverflow.com/questions/49383380/link-existing-hybrid-connection-to-an-azure-web-app-through-arm-template – Doris Lv Dec 10 '20 at 01:34
  • Thanks @Doris Lv, I'm able to create the hybrid connection by following the above documentation. But I want to create those connections using `copy' operator instead of repeating the code for all hybrid connections. – Pradeep Dec 10 '20 at 04:51
  • 1
    I think this is what you need: https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/template-functions-numeric?tabs=json#copyindex @Pradeep – Doris Lv Dec 10 '20 at 06:21
  • Yes @DorisLv, If possible pls share the complete template. – Pradeep Dec 10 '20 at 06:26

2 Answers2

1

Example works on my side:

Add an array list for your hybrid connection endpoint:

"parameters": {
        ......
        "endpoint": {
            "defaultValue": [
                "test6:3306",
                "test6:8081",
                "test6:8082"
            ],
            "type": "Array"
        }
    },

Copy Usage in resources section:

{
    "type": "Microsoft.Relay/namespaces/HybridConnections",
    "apiVersion": "2017-04-01",
    "name": "[concat(parameters('relayName'), '/', copyIndex())]",
    "location": "Central US",
    "dependsOn": [
        "[resourceId('Microsoft.Relay/namespaces', parameters('relayName'))]"],
    "properties": {
        "requiresClientAuthorization": false,
        "userMetadata": "[[{\"key\":\"endpoint\",\"value\":\"[parameters('endpoint')[copyIndex()]]\"}]"
    },
    "copy": {
        "name": "datacopy",
        "count": 3
    }
},
{
    "type": "Microsoft.Relay/namespaces",
    "apiVersion": "2018-01-01-preview",
    "name": "[parameters('relayName')]",
    "location": "Central US",
    "sku": {
        "name": "Standard",
        "tier": "Standard"
    },
    "properties": {}
}

Here are my reference:

  1. create hybridconnection using template

  2. Link existing hybrid connection to an azure web app through ARM-template

  3. copyIndex usage

Doris Lv
  • 3,083
  • 1
  • 5
  • 14
  • Please check the `"userMetadata": "[[{\"key\":\"endpoint\",\"value\":\"[parameters('endpoint')[copyIndex()]]\"}]"'` this line – Pradeep Dec 10 '20 at 16:39
  • Do you mean the extra left square bracket? @Pradeep . Although I don't know why it should be there, I copy this line from export template from portal, it is valid. – Doris Lv Dec 11 '20 at 01:24
  • currently I'm using this line `"userMetadata": " [concat('[{\"key\":\"endpoint\",\"value\":\"', variables('myEndpoint'), '\"}]')]"` – Pradeep Dec 11 '20 at 04:57
0

for creating Hybrid-Connection for webs using bicep you need to:

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!",
    }
}
KondzioSSJ4
  • 220
  • 4
  • 12