从 terraform 脚本为 Azure Active Directory 打开“应用程序服务身份验证”

mja*_*mes 5 azure terraform

需要从我的 terraform 脚本中为 Active Directory 打开“应用程序服务身份验证”。

当我使用正在创建的 app_service 的 client_id 将 auth_settings 部分添加到我的 azurerm_app_service 资源时,出现错误

“不允许自我引用”

有道理,但是我要为我正在创建的项目打开身份验证吗?

  name                = "${var.prefix}-${var.environment_code}-${var.environment_segment_code}-web"
  location            = "${azurerm_resource_group.my_resource_group.location}"
  resource_group_name = "${azurerm_resource_group.my_resource_group.name}"
  app_service_plan_id = "${azurerm_app_service_plan.my_app_service_plan.id}"

  app_settings = {
    APPINSIGHTS_INSTRUMENTATIONKEY = "${azurerm_application_insights.my_insights.instrumentation_key}"
  }

  tags = {
    my-Environment = "${var.environment}"
    my-Location    = "${var.country}"
    my-Stack       = "${var.stack}"
  }

  lifecycle {
    ignore_changes = [
      "app_settings"
    ]
  }

  auth_settings {
    enabled = true
    active_directory {
      client_id = "${azurerm_app_service.web.client_id}"
    }
    default_provider = "AzureActiveDirectory"
  }
}```

I'd like to have ad authentication enabled for my website when I terraform.
Run Code Online (Sandbox Code Playgroud)

Nan*_*ong 6

来自azurerm_app_service

active_directory支持以下内容:

client_id -(必需)此依赖方应用程序的客户端 ID。启用 Azure Active Directory 的 OpenIDConnection 身份验证。

该块中没有直接client_id属性azurerm_app_service,您需要在 Azure Active Directory 中注册应用服务应用程序,然后Application (client) ID在块中的 Azure 门户上添加active_directory请参阅有关配置应用服务应用以使用 Azure Active Directory 登录的详细信息。

Azure Active Directory 资源已拆分为新的 AzureAD 提供程序 - 因此 AzureRM 提供程序中的 AzureAD 资源已弃用,并将在下一个主要版本 (2.0) 中删除。您可以使用azuread_application块来完成此操作。

例如,这对我来说适用于 Terraform v0.12.5 +provider.azurerm v0.5.1 +provider.azurerm v1.32.0

# Configure the Microsoft Azure Active Directory Provider
provider "azuread" {
  version = "~> 0.3"
}

# Create an application
resource "azuread_application" "example" {
  name = "${var.prefix}-app-service"
  homepage                   = "https://${var.prefix}-app-service"
  identifier_uris            = ["https://${var.prefix}-app-service"]
  reply_urls                 = ["https://${var.prefix}-app-service.azurewebsites.net/.auth/login/aad/callback"]
  available_to_other_tenants = false
  oauth2_allow_implicit_flow = true

}
Run Code Online (Sandbox Code Playgroud)

 auth_settings  {
     enabled = true 

     active_directory  {
         client_id = "${azuread_application.example.application_id}"
     }
     default_provider = "AzureActiveDirectory"
     issuer = "https://sts.windows.net/xxxxxxx-xxxx-xxx-xxxx-xxxtenantID/"

}
Run Code Online (Sandbox Code Playgroud)

结果

在此输入图像描述