You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Terraform配置Azure AD B2C租户及用户流等资源?

解决Azure AD B2C用户流的Terraform自动化配置问题

不需要自行编写Terraform Provider,现有方案就能实现用户流的自动化配置,以下是几种可行的方式:

1. 借助ARM模板通过azurerm_template_deployment部署

Azure Resource Manager(ARM)模板原生支持配置Azure AD B2C用户流,你可以在Terraform中使用azurerm_template_deployment资源调用ARM模板完成部署,既保持Terraform作为IaC入口的统一性,又能复用ARM对AD B2C资源的完整支持。

示例代码:

resource "azurerm_template_deployment" "b2c_user_flow" {
  name                = "b2c-user-flow-deployment"
  resource_group_name = azurerm_resource_group.b2c_rg.name
  deployment_mode     = "Incremental"

  template_content = <<JSON
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "resources": [
    {
      "type": "Microsoft.AzureActiveDirectory/b2cDirectories/userFlows",
      "apiVersion": "2021-04-01",
      "name": "${azurerm_aadb2c_directory.b2c.name}/B2C_1_signupsignin",
      "properties": {
        "userFlowType": "signUpOrSignIn",
        "userFlowTypeVersion": "1.0.0",
        "identityProviders": [
          {
            "clientId": "${azurerm_api_management_identity_provider_aadb2c.example.client_id}",
            "name": "AzureADB2C",
            "type": "AzureADB2C"
          }
        ]
      }
    }
  ]
}
JSON
}

2. 使用local-exec调用Azure CLI

如果ARM模板的写法成本较高,可以用Terraform的local-exec provisioner直接调用Azure CLI命令创建用户流,适合快速实现简单场景的自动化。

示例代码:

resource "azurerm_aadb2c_directory" "b2c" {
  name                = "myb2cdirectory"
  resource_group_name = azurerm_resource_group.b2c_rg.name
  location            = "eu"
  sku_name            = "PremiumP1"
}

provisioner "local-exec" {
  command = <<EOT
az ad b2c user-flow create --resource-group ${azurerm_resource_group.b2c_rg.name} --name B2C_1_signupsignin --type signUpOrSignIn --identity-providers AzureADB2C
EOT
  depends_on = [azurerm_aadb2c_directory.b2c]
}

注意:执行Terraform的环境需要预先配置好Azure CLI的登录权限,且安装了支持AD B2C命令的最新版Azure CLI。

3. 等待AzureRM Provider官方支持

如果上述临时方案不符合你的需求,可以关注Terraform AzureRM Provider的开发进度,查看是否有AD B2C用户流资源的开发计划或已提交的PR,待官方原生资源发布后直接使用即可。


内容的提问来源于stack exchange,提问作者Bulchsu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 03:05:24