【发布时间】:2019-12-13 02:02:40
【问题描述】:
使用 terraform 和 Azure ARm 模板,我正在尝试在函数上创建一个 azure 事件网格订阅。
这是用于事件网格订阅的 ARM:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json",
"contentVersion": "1.0.0.0",
"parameters": {
"eventGridTopicName": {
"type": "string",
"metadata": {
"description": "The name of the Event Grid custom topic."
}
},
"eventGridSubscriptionName": {
"type": "string",
"metadata": {
"description": "The name of the Event Grid custom topic's subscription."
}
},
"eventGridSubscriptionUrl": {
"type": "string",
"metadata": {
"description": "The webhook URL to send the subscription events to. This URL must be valid and must be prepared to accept the Event Grid webhook URL challenge request. (RequestBin URLs are exempt from this requirement.)"
}
},
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "The location in which the Event Grid resources should be deployed."
}
}
},
"resources": [{
"name": "[parameters('eventGridTopicName')]",
"type": "Microsoft.EventGrid/topics",
"location": "[parameters('location')]",
"apiVersion": "2018-01-01"
},
{
"name": "[concat(parameters('eventGridTopicName'), '/Microsoft.EventGrid/', parameters('eventGridSubscriptionName'))]",
"type": "Microsoft.EventGrid/topics/providers/eventSubscriptions",
"location": "[parameters('location')]",
"apiVersion": "2018-01-01",
"properties": {
"destination": {
"endpointType": "WebHook",
"properties": {
"endpointUrl": "[parameters('eventGridSubscriptionUrl')]"
}
},
"filter": {
"includedEventTypes": [
"All"
]
}
},
"dependsOn": [
"[parameters('eventGridTopicName')]"
]
}
]
}
按照文档here 创建订阅,我们必须恢复系统密钥才能创建完整的 webhook 端点。所以在here这个帖子之后,我使用了一个ARM模板来恢复名为evengrid_extension的系统密钥。
所以一切都很顺利,除了在 eventgrid 订阅的 arm 部署期间。我有这个错误:
等待部署时出错:Code="DeploymentFailed" Message="至少一项资源部署操作失败。请 列出部署操作以了解详细信息。请参见 https://aka.ms/arm-debug 了解使用详情。” 详细信息=[{"代码":"冲突","消息":"{\r\n
\"状态\": \"失败\",\r\n
\"error\": {\r\n \"code\": \"ResourceDeploymentFailure\",\r\n
\"message\": \"资源操作完成,终端配置状态为'失败'。\",\r\n
\"详情\": [\r\n {\r\n
\"code\": \"网址验证\",\r\n
\"message\": \"尝试验证提供的端点https://myFunctionName.azurewebsites.net/runtime/webhooks/eventgrid 失败的。 \欲了解更多详情,请访问https: //aka.ms/esvalidation.\"\r\n }\r\n ]\r\n }\r\n}"}]
我检查了我的代码 n terraform,以确保我在这个 arm 模板中的所有参数都使用了正确的值,并且一切正常。我有正确的主题名称,正确的端点并填写了所有值。所以我不明白我在这里缺少什么。我也想知道我是否使用了正确的系统密钥。我知道有一个名为 durabletask_extension 的系统密钥,还有一个名为 eventgrid_extension 的系统密钥。但实际上我都试过了,都发生了同样的错误。
更新
请注意键,即 durabletask_extension 和 eventgrid_extension 都是系统键。因此,在我的 arm 模板中恢复这些效果很好,我只使用 eventgrid_extension 来恢复正确的系统密钥。
这是我的 terraform 代码:
resource "azurerm_eventgrid_topic" "eventgrid_topic" {
name = "topicName"
location = var.main_location
resource_group_name = azurerm_resource_group.name
}
resource "azurerm_template_deployment" "eventgrid_subscription" {
name = "EventGridSbscription"
resource_group_name = azurerm_resource_group.environment.name
template_body = file("./arm/event-grid-subscription.json")
parameters = {
eventGridTopicName = "${azurerm_eventgrid_topic.eventgrid_topic.name}"
eventGridSubscriptionName = "eventgrid-myFunctionName"
eventGridSubscriptionUrl = "https://${azurerm_function_app.function.name}.azurewebsites.net/runtime/webhooks/eventgrid?functionName=${azurerm_function_app.function.name}&code=${lookup(azurerm_template_deployment.function_key.outputs, "systemKey")}"
location = var.main_location
}
deployment_mode = "Incremental"
depends_on = [
azurerm_template_deployment.function_key
]
}
所以我不明白为什么我的 susbription 部署失败,或者为了使用 terraform 自动执行此设置而缺少什么。
按照文档here 我也明白:
如果您无权访问应用程序代码(例如,如果 您正在使用支持 webhook 的第三方服务),您可以 使用手动握手机制。确保您使用的是 2018-05-01-preview API 版本或更高版本(安装 Event Grid Azure CLI extension) 以在验证事件中接收 validationUrl。到 完成手动验证握手,获取值 validationUrl 属性并在您的网络浏览器中访问该 URL。如果 验证成功,您应该在 Web 浏览器中看到一条消息 验证成功。您会看到该事件订阅的 provisioningState 为“成功”。
那么,有没有一种方法可以使用 terraform 或其他方式来自动进行验证?
【问题讨论】:
-
用于测试目的:转到门户并从您的 EventGridTrigger 函数获取其订阅 URL(位于集成页面上)并在 terraform 代码中使用它。
-
另外,您可以使用邮递员请求 POST subscriptionUrl、标头 aeg-event-type=SubscriptionValidation 和有效负载测试 EventGridTrigger 函数的验证响应来自docs.microsoft.com/en-us/azure/event-grid/… 中描述的 SubscriptionValidationEvent 示例
-
我在 ARM 模板中设置函数应用的订阅 URL 时遇到类似问题。我认为问题在于 URL 中的查询字符串参数;如果您查看验证失败,它不会在 URL 中显示 ?functionName={whatever}。如果我通过 Azure 门户手动设置订阅,它可以正常工作。
标签: azure azure-devops azure-functions terraform azure-eventgrid