繁体   English   中英

对于端点Webhook URL上的事件网格订阅,ARM部署失败

[英]ARM deployment failed for event grid subscription on endpoint webhook url

我正在使用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')]"
            ]
        }
    ]
}

按照此处的文档创建订阅后,我们必须恢复系统密钥才能创建完整的webhook端点。 因此,在此发布本文之后 ,我使用了一个ARM模板来恢复名为evengrid_extension的系统密钥。

因此,除了在eventgrid订阅的手臂部署期间之外,其他一切都进行得很好。 我有这个错误:

“等待部署时出错:Code =” DeploymentFailed“ Message =”至少一项资源部署操作失败。请列出部署操作以获取详细信息。请参阅https://aka.ms/arm-debug以获取使用详细信息。“ 详细= [{ “代码”: “冲突”, “消息”:“{\\ r \\ n
\\“状态\\”:\\“失败\\”,\\ r \\ n
\\“ error \\”:{\\ r \\ n \\“ code \\”:\\“ ResourceDeploymentFailure \\”,\\ r \\ n
\\“ message \\”:\\“资源操作完成,终端供应状态为“ Failed”。\\”,\\ r \\ n
\\“详细信息\\”:[\\ r \\ n {\\ r \\ n
\\“代码\\”:\\“网址验证\\”,\\ r \\ n
\\“消息\\”:\\“尝试验证提供的端点https://myFunctionName.azurewebsites.net/runtime/webhooks/eventgrid失败。\\有关更多详细信息,请访问https://aka.ms/esvalidation。\\” \\ r \\ n} \\ r \\ n] \\ r \\ n} \\ r \\ n}“}]

我检查我的代码n terraform,以确保我为此手臂模板中的所有参数使用了正确的值,并且一切正常。 我有正确的主题名称,正确的端点,所有值均已填写。因此,我不明白我在这里缺少什么。 我也想知道我是否使用了正确的系统密钥。 我知道有一个名为耐用任务扩展名的系统密钥,还有一个名为eventgrid_extension的系统密钥。 但是实际上我已经尝试过两者,并且发生了相同的错误。


更新

只需注意,键(例如耐用任务扩展名事件网格扩展名)都是系统密钥。 因此,在我的手臂模板中,恢复这些文件的效果很好,我仅使用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
  ]
}

因此,我不明白为什么我的暂存部署失败,或者为了用terraform自动化此设置而缺少了什么。

遵循这里的文档我也明白:

如果您无权访问应用程序代码(例如,如果您使用的是支持Webhooks的第三方服务),则可以使用手动握手机制。 确保您使用的是2018-05-01-preview API版本或更高版本(安装Event Grid Azure CLI扩展)以在验证事件中接收validationUrl。 要完成手动验证握手,请获取validationUrl属性的值,然后在网络浏览器中访问该URL。 如果验证成功,您应该在Web浏览器中看到一条消息,表明验证成功。 您将看到事件订阅的ProvisioningState为“成功”。

因此,有一种方法可以使用terraform进行验证,或者可以通过另一种方法来自动执行此验证?

该模板是正确的,您只是误解了eventGridSubscriptionUrl中的eventGridSubscriptionUrl 看一下URL URL显示如下:

2.x版运行时

https://{functionappname}.azurewebsites.net/runtime/webhooks/eventgrid?functionName={functionname}&code={systemkey}

1.x版运行时

https://{functionappname}.azurewebsites.net/admin/extensions/EventGridExtensionConfig?functionName={functionname}&code={systemkey}

functionappname是您设置为值azurerm_function_app.function.name的值,而functionname不是。

您可以通过Azure REST API Web Apps-Get Function获得现有的函数名称。

在Terraform中,似乎函数应用程序中没有可供您创建的函数资源。 但是您也可以使用模板创建函数并输出函数名称。 然后,您可以在URL中进行设置。 您可以在此处的Azure模板中获得有关函数的更多详细信息,函数名称显示在属性中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM