Azure Function App 触发不一致

Azure Function App inconsistently triggering

在从事件中心触发的 zip 部署的函数应用程序中,应用程序不一致地触发(似乎仅在 Azure 门户中调试应用程序时以及大约 15 分钟后触发)。

resource "azurerm_function_app" "helloworld" {
  name                      = "helloworld-func"
  location                  = "${azurerm_resource_group.helloworld.location}"
  resource_group_name       = "${azurerm_resource_group.helloworld.name}"
  app_service_plan_id       = "${azurerm_app_service_plan.helloworld.id}"
  storage_connection_string = "${azurerm_storage_account.helloworld.primary_connection_string}"
  version                   = "~2"

  app_settings {
    # key must match bindings.connection in functionapp/eventHubsMessages/function.json and must include EntityPath
    # bindings.eventHubName in functionapp/eventHubMessages/function.json is purposelly kept empty to avoid overriding the EntityPath in connection string
    # see https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-event-hubs#output---configuration
    LOGSEVENTHUBCONNECTIONSTRING = "${azurerm_eventhub_authorization_rule.helloworld.primary_connection_string}"

    # TODO figure out how to use Azure AD and RBAC to allow the Function App access to the storage blob without a time-based token
    WEBSITE_USE_ZIP              = "${azurerm_storage_blob.helloworld.url}${data.azurerm_storage_account_sas.helloworld.sas}"
    HASH                         = "${data.archive_file.helloworld.output_base64sha256}"
    WEBSITE_NODE_DEFAULT_VERSION = "10.14.1"
  }
}

这是一个由函数触发器不同步引起的长期已知的突出问题(参见 https://github.com/Azure/Azure-Functions/issues/210

在使用 azure cli 的 terraform 中添加此 local-exec 配置器 syncfunctiontriggers 效果很好

  # required to sync the function trigger (event hub trigger); without, function app will trigger inconsistently
  provisioner "local-exec" {
    command = "az resource invoke-action --resource-group ${azurerm_resource_group.datadog_logs.name} --action syncfunctiontriggers --name ${azurerm_function_app.datadog_logs.name} --resource-type Microsoft.Web/sites"
  }