簡體   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