B2c tenant Creation and creation of users/apps from main tenant using terraform. Is that possible?

58 Views Asked by At

I want to create a B2C tenant using Terraform. And need to create an application in that tenant and create users and assign roles. I have created a B2C tenant using Terraform in the main tenant, but cannot create an application and users in it.

I have created a B2C tenant from the main tenant, but don't know how to create an app and users in B2C from the main tenant. Is there any way to create users and app directly in B2C tenant using Terraform?

1

There are 1 best solutions below

0
Vinay B On

B2c tenant Creation and creation of users/apps from main tenant using terraform.

Yes, it's possible to create the tenant and apps, users from the main tenant.

My terraform configuration:

# Configure Azure Provider
provider "azurerm" {
  features {}
}

# Create Azure AD B2C Directory
resource "azurerm_aadb2c_directory" "example" {
  country_code            = "US"
  data_residency_location = "United States"
  display_name            = "vksbtenant"
  domain_name             = "vkssbtenant.onmicrosoft.com"
  resource_group_name     = "vinay-rg"
  sku_name                = "PremiumP1"
  
}


output "tenant_id" {
  value = azurerm_aadb2c_directory.example.tenant_id
}


# Configure Azure AD Provider (using the obtained tenant ID)
provider "azuread" {
  tenant_id = azurerm_aadb2c_directory.example.tenant_id
}

# Create Azure AD B2C Application (dependent on AAD B2C Directory)
resource "azuread_application" "b2c_app" {
  display_name = "MyB2CApplication"
  
  depends_on = [azurerm_aadb2c_directory.example]
  # Additional configurations as needed for your application

}
# Create Azure AD User (optional, dependent on AAD Provider)
resource "azuread_user" "example" {
  # Use domain name from AAD B2C Directory
  user_principal_name = "[email protected]"
  display_name        = "J. Doe"
  mail_nickname       = "jdoe"
  password             = "yourpassword"

  depends_on = [ azurerm_aadb2c_directory.example ]

  
  
}

deployment succeeded:

enter image description here

enter image description here

enter image description here

enter image description here