我正在尝试订阅存在于不同资源组上的自定义事件网格主题。例如,如果我在资源组
my-custom-topic
中有一个自定义事件网格主题 publisher-group
。如何从资源组中创建对我的主题的事件网格订阅subscriber-group
?
以下 ARM 模板仅在
my-custom-topic
与我应用该模板位于同一资源组中时才有效
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json",
"contentVersion": "1.0.0.0",
"parameters": {
"eventGridSubscriptionName": {
"type": "String",
"metadata": {
"description": "The name of the Event Grid custom topic's subscription."
}
},
"location": {
"defaultValue": "[resourceGroup().location]",
"type": "String",
"metadata": {
"description": "The location in which the Event Grid resources should be deployed."
}
}
},
"resources": [
{
"type": "Microsoft.EventGrid/topics/providers/eventSubscriptions",
"apiVersion": "2018-01-01",
"name": "[concat('my-custom-topic', '/Microsoft.EventGrid/', parameters('eventGridSubscriptionName'))]",
"location": "[parameters('location')]",
"properties": {
"destination": {
"endpointType": "EventHub",
"properties": {
"resourceId": "..."
}
},
"filter": {
"includedEventTypes": [
"All"
]
}
}
}
]
}
如果我将
name
更改为主题的完整路径(例如,subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx/resourceGroups/publisher-group/providers/Microsoft.EventGrid/topics/my-custom-topic)然后模板抱怨我有太多段
我本以为这是一个非常常见的用例,在不同的资源组中具有主题和订阅,但我无法找到具体的示例
如何创建 ARM 模板来订阅不同资源组上的事件网格主题?
这是不可能的 - 事件网格主题和订阅必须位于同一资源组中。
我建议创建一个单独的资源组,仅用于包含您的事件网格主题及其所有订阅。
从逻辑上讲,您不应将单个事件发布者视为拥有其发布到的事件网格主题,而应将主题视为许多发布者和订阅者所依赖的共享资源。
虽然订阅必须与主题位于同一资源组中,但订阅主题的实际资源可以位于任何资源组中,如目标的 ResourceId 中指定的那样。换句话说,订阅与主题紧密耦合,但订阅使用的资源却不是。这绝对令人困惑,并且与您想象的相反。