通过 ARM 模板将现有的混合连接链接到 azure web 应用程序

mar*_*son 4 deployment azure azure-rm-template azure-hybrid-connections

我有一个 azure 资源组,其中包含一个包含混合连接的中继。我正在尝试部署另一个包含 Web 应用程序的资源组,该应用程序应该链接另一个资源组中的现有混合连接。

在 azure 门户中执行此任务很简单,但由于我想在 ARM 模板部署期间运行“完整模式”,因此我需要在部署期间执行此操作。

我找不到任何好的文档,而且很多答案似乎已经过时。这可能吗,如果可能,如何实现?

小智 7

You can use this code to create hybrid connection on Relay:

{
  "name": "[concat(relayName, '/', hybridConnectionName]",
  "type": "Microsoft.Relay/namespaces/hybridConnections",
  "apiVersion": "2017-04-01",      
  "dependsOn": [
    "relayName"
  ],
  "properties": {
    "requiresClientAuthorization": true,
    "userMetadata": [
       {
          "key": "endpoint",
          "value": "google.com:443"
       }
    ]
  },
  "resources": []
}
Run Code Online (Sandbox Code Playgroud)

And then connect it to the web app:

"variables": { 
   "hybridConnectionResourceId": "[resourceId(relayResourceGroup, 'Microsoft.Relay/Namespaces/Hybridconnections', relayName, hybridConnectionName)]"
},
{
  "name": "[concat(webAppName, '/', relayName, '/', hybridConnectionName)]",
  "type": "Microsoft.Web/sites/hybridConnectionNamespaces/relays",
  "apiVersion": "2018-02-01",
  "dependsOn": [
    "webAppName"
  ],
  "location": "[resourceGroup().location]",
  "properties": {
    "serviceBusNamespace": "relayName",
    "relayName": "hybridConnectionName",
    "relayArmUri": "[variables('hybridConnectionResourceId')]",
    "hostName": "[split(json(reference(variables('hybridConnectionResourceId'), '2017-04-01').userMetadata)[0].value, ':')[0]]",
    "port": "[split(json(reference(variables('hybridConnectionResourceId'), '2017-04-01').userMetadata)[0].value, ':')[1]]",
    "sendKeyName": "defaultSender",
    "sendKeyValue": "[listkeys(concat(variables('hybridConnectionResourceId'), '/authorizationRules/defaultSender'), '2017-04-01').primaryKey]"
  }
}
Run Code Online (Sandbox Code Playgroud)

Hope this helps.

  • 它有帮助但要小心:userMedata 属性必须是一个 json 数组作为字符串:例如,"userMetadata": " [concat('[{\"key\":\"endpoint\",\"value\":\" ', variables('myEndpoint'), '\"}]')]" (3认同)