Azure ServiceBus-队列-授权规则创建错误



我正在使用ServiceBus、队列和耦合共享访问规则创建Azure资源管理器模板。我正确地创建了名称空间和队列,但当我尝试添加授权规则时,我得到了:

资源Microsoft.ServiceBus/namespaces/authorizationRules"myservicebusnamespace/SendOnlyKey"失败,返回消息"Request"有效载荷不是预期的格式。

首先,这可能吗?那里没有样本,也没有文档。。

由于这是一条非常通用的消息,我想知道是否有其他人在使用ARM模板创建队列时遇到过类似的问题?这就是我目前所拥有的:

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "sbNamespace": {
      "type": "string",
      "metadata": {
        "description": "The service bus namespace"
      }
    }
  },
  "variables": {
    "location": "[resourceGroup().location]",
    "sbVersion": "[providers('Microsoft.ServiceBus', 'namespaces').apiVersions[0]]",
    "queueName": "testQueue",
    "defaultSASKeyName": "RootManageSharedAccessKey",
    "authRuleResourceId": "[resourceId('Microsoft.ServiceBus/namespaces/authorizationRules', parameters('sbNamespace'), variables('defaultSASKeyName'))]",
    "sendAuthRuleResourceId": "[resourceId('Microsoft.ServiceBus/namespaces/authorizationRules', parameters('sbNamespace'), 'SendOnlyKey')]",
    "keyGeneratorTemplateUri": "https://raw.githubusercontent.com/sjkp/Azure.ARM.ServiceBus/master/Azure.ARM.ServiceBus/Templates/keygenerator.json"
  },
  "resources": [
    {
      "apiVersion": "2015-01-01",
      "name": "primaryKey",
      "type": "Microsoft.Resources/deployments",
      "properties": {
        "mode": "incremental",
        "templateLink": {
          "uri": "[variables('keyGeneratorTemplateUri')]",
          "contentVersion": "1.0.0.0"
        },
        "parameters": {
          "seed": { "value": "1234a5" }
        }
      }
    },
    {
      "apiVersion": "2015-01-01",
      "name": "secondaryKey",
      "type": "Microsoft.Resources/deployments",
      "properties": {
        "mode": "incremental",
        "templateLink": {
          "uri": "[variables('keyGeneratorTemplateUri')]",
          "contentVersion": "1.0.0.0"
        },
        "parameters": {
          "seed": { "value": "ac34a5" }
        }
      }
    },
    {
      //namespace
      "apiVersion": "[variables('sbVersion')]",
      "name": "[parameters('sbNamespace')]",
      "type": "Microsoft.ServiceBus/namespaces",
      "location": "[variables('location')]",
      "properties": {
        "messagingSku": 2
      },
      "resources": [
        {
          //queue
          "apiVersion": "[variables('sbVersion')]",
          "name": "[variables('queueName')]",
          "type": "Queues",
          "dependsOn": [
            "[concat('Microsoft.ServiceBus/namespaces/', parameters('sbNamespace'))]"
          ],
          "properties": {
            "path": "[variables('queueName')]",
            "defaultMessageTimeToLive": "14.0:0:0",
            "maxQueueSizeInMegaBytes": "1024",
            "maxDeliveryCount": "10"
          }
        }
        ,{
          //auth rule 1
          "apiVersion": "[variables('sbVersion')]",
          "name": "[concat(parameters('sbNamespace'),'/SendOnlyKey')]",
          "type": "Microsoft.ServiceBus/namespaces/authorizationRules",
          "dependsOn": [
            "[concat('Microsoft.ServiceBus/namespaces/', parameters('sbNamespace'))]",
            "[concat('Microsoft.Resources/deployments/', 'primaryKey')]",
            "[concat('Microsoft.Resources/deployments/', 'secondaryKey')]"
          ],
          "location": "[variables('location')]",
          "properties": {
            "keyName": "SendOnlyKey",
            "PrimaryKey": "[reference('primaryKey').outputs.key.value]",
            "SecondaryKey": "[reference('secondaryKey').outputs.key.value]"
          }
        }
      ]
    }
  ],
  "outputs": {
    "NamespaceDefaultConnectionString": {
      "type": "string",
      "value": "[listkeys(variables('authRuleResourceId'), variables('sbVersion')).primaryConnectionString]"
    }
  }
}

听起来应该生成密钥的子模板出现了故障。

你能试着用例如powershell来生成它们的密钥吗:

$bytes = New-Object Byte[] 32
$rand = [System.Security.Cryptography.RandomNumberGenerator]::Create()
$rand.GetBytes($bytes)
$rand.Dispose()
$key = [System.Convert]::ToBase64String($bytes)

看看这是否修复了错误。

困难的东西,这是肯定的。看看

  • 服务总线ARM模板
  • 还没有ARM的服务总线提供程序

最新更新