我正在尝试通过 Terraform 部署 Azure Linux 函数应用程序。此功能应用程序使用基于 Microsoft 的身份验证。在我的函数应用程序资源模板中,我有这个用于身份验证的块:
"auth_settings_v2" {
content {
auth_enabled = true
require_authentication = true
microsoft_v2 {
client_id = var.app_registration_client_id
client_secret_setting_name = "MICROSOFT_PROVIDER_AUTHENTICATION_SECRET"
allowed_audiences = ["api://${var.app_registration_client_id}"]
}
login {}
}
}
我还指定了一个名为
app_setting
的 MICROSOFT_PROVIDER_AUTHENTICATION_SECRET
。我在 Azure 门户中验证身份验证确实已启用,但它显示“Microsoft (V1)”。我还验证了应用程序设置已添加正确的秘密值。
我正在使用
hashicorp/azurerm = 3.104.2
。为什么启用 V1 身份验证而不是 V2?
AzureRM
提供程序版本主要侧重于用于身份验证的 ADAL 库。检查您是否已将 terraform 版本正确升级到最新版本。如果问题仍然存在,请尝试在
runtime_version
块下添加
auth_settings_v2
属性,如下面的代码所示。
runtime_version = "~2"
microsoft_v2
但每次它都在部署
v1
之后。看起来这是文档中的一个错误。作为解决方法,您可以使用
active_directory_V2 身份验证提供程序而不是 microsoft_v2
。
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.104.2"
}
}
}
provider "azurerm" {
features {}
}
data "azurerm_resource_group" "example" {
name = "Jahnavi"
}
resource "azurerm_storage_account" "example" {
name = "functionappsajnew"
resource_group_name = data.azurerm_resource_group.example.name
location = data.azurerm_resource_group.example.location
account_tier = "Standard"
account_replication_type = "LRS"
}
resource "azurerm_service_plan" "example" {
name = "jahplannew"
resource_group_name = data.azurerm_resource_group.example.name
location = data.azurerm_resource_group.example.location
os_type = "Linux"
sku_name = "Y1"
}
resource "azurerm_linux_function_app" "example" {
name = "exampleappjnew"
resource_group_name = data.azurerm_resource_group.example.name
location = data.azurerm_resource_group.example.location
storage_account_name = azurerm_storage_account.example.name
storage_account_access_key = azurerm_storage_account.example.primary_access_key
service_plan_id = azurerm_service_plan.example.id
site_config {}
app_settings = {
"MICROSOFT_PROVIDER_AUTHENTICATION_SECRET" = var.client_secret
}
auth_settings_v2 {
auth_enabled = true
runtime_version = "~2"
default_provider = "aad"
require_authentication = true
require_https = true
unauthenticated_action = "RedirectToLoginPage"
active_directory_v2 {
client_id = var.client_Id
client_secret_setting_name = "MICROSOFT_PROVIDER_AUTHENTICATION_SECRET"
tenant_auth_endpoint = "https://login.microsoftonline.com/tenant_ID/v2.0/"
}
login{}
}
}
输出: