Azure 函数“主机密钥”不是使用 Terraform 创建的

kis*_*m3t 9 function terraform terraform-provider-azure

如果我通过门户手动创建 Azure 函数,则会创建应用程序密钥: 在此输入图像描述

如果我通过 terraform 尝试相同的操作:

功能应用程序

  resource "azurerm_function_app" "resize_images" {
    name                      = format("%s%s%s%s", module.subscription_prefix.prefix, "pfunctionapp", lower(local.environment), "0001")
    location                  = azurerm_resource_group.azure_functions.location
    resource_group_name       = azurerm_resource_group.azure_functions.name
    app_service_plan_id       = module.app_service_plan.id
  
    # AzureRM 1.x needs this
    #storage_connection_string = local.azure_functions_storage_account_primary_connection_string
  
    # AzureRM 2.x needs this
    storage_account_name       = data.azurerm_storage_account.resize_storage.name
    storage_account_access_key = data.azurerm_storage_account.resize_storage.primary_access_key
  
    app_settings = {
      AzureWebJobsDashboard          = data.azurerm_storage_account.resize_storage.primary_connection_string
      AzureWebJobsStorage            = data.azurerm_storage_account.resize_storage.primary_connection_string
      BLOB_STORAGE_CONNECTION_STRING = data.azurerm_storage_account.resize_storage.primary_connection_string
      CONTAINER_NAME = "images"
      FUNCTIONS_EXTENSION_VERSION = "~3"
      WEBSITE_HTTPLOGGING_RETENTION_DAYS = "3"
      WEBSITE_RUN_FROM_PACKAGE = "1"
    }
  
    version = "~3"
  
    tags = local.tags
  }
Run Code Online (Sandbox Code Playgroud)

没有创建应用程序密钥: 在此输入图像描述

Terraform 文档中,没有说明如何创建这些密钥,但您可以将它们作为data读取。

谁能指出我如何创建密钥的正确方向?!

Nan*_*ong 5

默认情况下,密钥存储在设置提供的帐户中的 Blob 存储容器中AzureWebJobsStorage。在您的代码中,密钥确实是在关联的存储帐户上自动生成的,但没有显示在 Azure Function 应用程序 UI 上。

经过我的验证,如果您删除WEBSITE_RUN_FROM_PACKAGE = "1"中的app_settings,那么您将在 Function 应用程序中看到默认的应用程序键。当您将设置添加WEBSITE_RUN_FROM_PACKAGE到函数应用设置时,它使您的函数应用能够从包运行。我认为这或多或少会覆盖默认的 Azure 函数部署行为。阅读本文了解更多详细信息。