【问题标题】:Turn on 'App Service Authentication' for Azure Active Directory from terraform script从 terraform 脚本为 Azure Active Directory 启用“应用服务身份验证”
【发布时间】:2019-12-07 04:48:05
【问题描述】:

需要从我的 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.

【问题讨论】:

    标签: azure terraform


    【解决方案1】:

    来自azurerm_app_service

    active_directory 块支持以下内容:

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

    azurerm_app_service 块中没有直接的client_id 属性,您需要在 Azure Active Directory 中注册应用服务应用,然后在 Azure 门户的 active_directory 块中添加 Application (client) ID。请参阅有关configure your App Service app to use Azure Active Directory sign-in 的详细信息。

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

    例如,这对我有用 Terraform v0.12.5 + 提供者.azuread 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
    
    }
    

     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/"
    
    }
    

    结果

    【讨论】:

    • 我目前正在使用 azurerm_app_service 来配置我的应用服务。您是说我需要改用 azuread_application 吗?或者,azuread_application 是否可以引用现有的 app_service?
    • 我的意思是您需要 azuread 分区的提供程序“azuread”。我只是使用带有单独 .tf 文件的 azuread 分区,这可以引用生成的 azurerm_app_service。
    • @NancyXiong 我可以使用 Terrafrom 在 Azure AD 中进行应用注册吗?
    猜你喜欢
    • 2016-02-14
    • 2018-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-21
    • 1970-01-01
    相关资源
    最近更新 更多