如何将Azure Eventhub主和辅助连接密钥作为ARM模板输出返回?

问题描述 投票:0回答:1

我已经准备了用于部署Azure Eventhub实例的ARM模板,并想知道如何访问两个连接键以将它们作为输出返回?

portal screenshot

我想以以下形式返回字符串:

Endpoint = sb://my-eventhub.servicebus.windows.net/; SharedAccessKeyName = RootManageSharedAccessKey; SharedAccessKey = ojZMQcJD7uYifxJyGeXG6tNDdZyaC1 / h5tmX6ODVfmY =

这是我当前的模板:

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "clusterName": {
            "type": "string",
            "defaultValue": "eventhub",
            "metadata": {
                "description": "Name for the Event Hub cluster."
            }
        },
        "namespaceName": {
            "type": "string",
            "defaultValue": "namespace",
            "metadata": {
                "description": "Name for the Namespace to be created in cluster."
            }
        }
    },
    "variables": {
        "clusterName": "[concat(resourceGroup().name, '-', parameters('clusterName'))]",
        "namespaceName": "[concat(resourceGroup().name, '-', parameters('namespaceName'))]"
    },
    "outputs": {
        "MyClusterName": {
            "type": "string",
            "value": "[variables('clusterName')]"
        },
        "PrimaryConnectionString": {
            "type": "string",
            "value": "WHAT TO USE HERE PLEASE?"
        },
        "SecondaryConnectionString": {
            "type": "string",
            "value": "WHAT TO USE HERE PLEASE?"
        }
    },
    "resources": [
        {
            "type": "Microsoft.EventHub/clusters",
            "apiVersion": "2018-01-01-preview",
            "name": "[variables('clusterName')]",
            "location": "[resourceGroup().location]",
            "sku": {
                "name": "Dedicated",
                "capacity": 1
            }
        },
        {
            "type": "Microsoft.EventHub/namespaces",
            "apiVersion": "2018-01-01-preview",
            "name": "[variables('namespaceName')]",
            "location": "[resourceGroup().location]",
            "dependsOn": [
                "[resourceId('Microsoft.EventHub/clusters', variables('clusterName'))]"
            ],
            "sku": {
                "name": "Standard",
                "tier": "Standard",
                "capacity": 1
            },
            "properties": {
                "isAutoInflateEnabled": false,
                "maximumThroughputUnits": 0,
                "clusterArmId": "[resourceId('Microsoft.EventHub/clusters', variables('clusterName'))]"
            }
        }
    ]
}

我尝试了以下操作:

"value": "[listKeys(resourceId(concat('Microsoft.ServiceBus/namespaces/AuthorizationRules'), variables('namespaceName'), 'RootManageSharedAccessKey'),'2018-01-01-preview').primaryConnectionString]"

但出现部署错误:

[错误] ParentResourceNotFound:无法对嵌套资源执行请求的操作。找不到父资源“ my-rg-namespace”。

UPDATE:

以下是杰西的建议对我有用(谢谢!):

"variables": {
    "clusterName": "[concat(resourceGroup().name, '-', parameters('clusterName'))]",
    "namespaceName": "[concat(resourceGroup().name, '-', parameters('namespaceName'))]",
    "defaultSASKeyName": "RootManageSharedAccessKey",
    "authRuleResourceId": "[resourceId('Microsoft.EventHub/namespaces/authorizationRules', variables('namespaceName'), variables('defaultSASKeyName'))]"
},
"outputs": {
    "MyClusterName": {
        "type": "string",
        "value": "[variables('clusterName')]"
    },
    "PrimaryConnectionString": {
        "type": "string",
        "value": "[listkeys(variables('authRuleResourceId'), '2015-08-01').primaryConnectionString]"
    },
    "SecondaryConnectionString": {
        "type": "string",
        "value": "[listkeys(variables('authRuleResourceId'), '2015-08-01').secondaryConnectionString]"
    }
},
azure azure-eventhub arm-template
1个回答
1
投票

似乎您使用的是错误的资源ID,是从Microsoft.ServiceBus而不是Microsoft.EventHub提取的,失败的原因是因为没有名称正确的Service Bus名称空间。

您可能希望尝试使用类似于以下内容的表格来标识您的资源:

"variables": {                
    "location": "[resourceGroup().location]",
    "apiVersion": "2015-08-01",
    "defaultSASKeyName": "RootManageSharedAccessKey",
    "authRuleResourceId": "[resourceId('Microsoft.EventHub/namespaces/authorizationRules', parameters('namespaceName'), variables('defaultSASKeyName'))]"
},

如上所述,您应该允许使用listkeys将其返回:

"outputs": {
    "NamespaceConnectionString": {
        "type": "string",
        "value": "[listkeys(variables('authRuleResourceId'), variables('apiVersion')).primaryConnectionString]"
    }
}

Event Hubs sample template中提供了一个简单部署的完整示例。

© www.soinside.com 2019 - 2024. All rights reserved.