通过ARM创建对自定义事件网格主题的存储队列订阅

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

我正在尝试通过自定义主题为我的存储队列设置事件网格订阅。

在门户中导航时很容易做到,但是我无法为此创建合适的ARM模板。经过大量搜索和尝试后,我提出了以下模板。

{
    "name": "MyCustomTopicName/Microsoft.EventGrid/MySubscriptionName",
    "type": "Microsoft.EventGrid/topics/providers/eventSubscriptions",
    "location": "[resourceGroup().location]",
    "apiVersion": "2019-06-01",
    "properties": {
        "destination": {
            "endpointType": "StorageQueue",
            "properties": {
                "resourceId": "[resourceId('Microsoft.Storage/storageAccounts', variables('theNameOfMyStorageAccount'))]",
                "queueName": "[variables('theNameOfMyQueue')]"
            }
        },
        "filter": {
            "advancedFilters": []
        },
        "labels": [],
        "eventDeliverySchema": "EventGridSchema"
    }
}

对我来说这看起来还不错,但是失败了,因为事件网格主题不在我要部署模板的资源组中。

Deployment failed. Correlation ID: [guid]. {
  "error": {
    "code": "ResourceNotFound",
    "message": "The Resource 'Microsoft.EventGrid/topics/MyCustomTopicName' under resource group 'TheResourceGroupTheStorageAccountIsIn' was not found."
  }
}

我正在将完整的ARM模板部署到TheResourceGroupTheStorageAccountIsInMyCustomTopicName主题位于我们放置自定义主题的资源组中,因此所有服务都可以使用它。

我尝试使用自定义主题的完整标识符(资源ID),但这是无效的。想法?

PS:我正在使用类似的模板来创建对Azure Function的订阅,该订阅可以正常工作。那里的主要区别是destination块,这很有意义。

azure arm-template azure-eventgrid
1个回答
1
投票

如果我没看错,您只需要使用嵌套的部署并将目标所在的资源组作为目标:

{
    "apiVersion": "2017-05-10",
    "name": "nestedTemplate",
    "type": "Microsoft.Resources/deployments",
    "resourceGroup": "your_topic_resource_roup",
    "properties": {
        "mode": "Incremental",
        "template": {
            "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
            "contentVersion": "1.0.0.0",
            "parameters": {},
            "variables": {},
            "resources": [
                {
                    "name": "MyCustomTopicName/Microsoft.EventGrid/MySubscriptionName",
                    "type": "Microsoft.EventGrid/topics/providers/eventSubscriptions",
                    "location": "[resourceGroup().location]",
                    "apiVersion": "2019-06-01",
                    "properties": {
                        "destination": {
                            "endpointType": "StorageQueue",
                            "properties": {
                                "resourceId": "[resourceId('Microsoft.Storage/storageAccounts', variables('theNameOfMyStorageAccount'))]",
                                "queueName": "[variables('theNameOfMyQueue')]"
                            }
                        },
                        "filter": {
                            "advancedFilters": []
                        },
                        "labels": [],
                        "eventDeliverySchema": "EventGridSchema"
                    }
                }
            ]
        }
    }
},
© www.soinside.com 2019 - 2024. All rights reserved.