Unable to create a azure b2c tenant with bicep

Ser*_*lva 2 azure azure-ad-b2c azure-bicep

I'm trying to create a azure B2c tenant with bicep. When I do it in the portal everything is ok. With terraform also everything is ok. But with bicep I get this

New-AzSubscriptionDeployment : 5:41:21 PM - The deployment 'xpto-devTEST' failed with error(s). Showing 2 out of 2 error(s). Status Message: The response for resource had empty or invalid content. (Code:ResourceDeploymentFailure) Status Message: At least one resource deployment operation failed. Please list deployment operations for details. Please see

  • { "error": { "code": "ResourceDeploymentFailure", "message": "The response for resource had empty or invalid content." } } (Code:InternalServerError) CorrelationId: c0a20039-0a78-44c3-94fb-998c53c661a4 At line:1 char:1
  • New-AzSubscriptionDeployment -Name xpto-devTEST -Template ...
  • + CategoryInfo          : NotSpecified: (:) [New-AzDeployment], Exception
    + FullyQualifiedErrorId : >Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureSubscriptionDeploymentCmdlet
    
    Run Code Online (Sandbox Code Playgroud)

My main bicep have this

@description('the name of the environment. this must be dev, test, or prod.')
@allowed([
  'dev'
  'test'
  'prod'
])
param environmentname string = 'dev'

@description('the location of the resource')
param location string = 'northeurope'
@description('Name of the resource group')
param resourceGroupName string = 'xpto-${environmentname}'

targetScope = 'subscription'

resource rg 'microsoft.resources/resourcegroups@2021-04-01' = {
  name: resourceGroupName
  location:location
}

module azureb2c 'modules/azureB2C.bicep' = {
  name: 'xptoTenant-${environmentname}'
  scope: rg
}
Run Code Online (Sandbox Code Playgroud)

My module have this

@description('The name of the environment. This must be dev, test, or prod.')
@allowed([
  'dev'
  'test'
  'prod'
])
param environmentName string = 'dev'

@description('The location of the resource')
param location string = 'Europe'

resource b2c 'Microsoft.AzureActiveDirectory/b2cDirectories@2019-01-01-preview' ={
  name: 'xpto${environmentName}Tenant.onmicrosoft.com'
  location: location
  sku: {
    name: 'PremiumP1'
  }
  properties:{
    createTenantProperties:{
      displayName: 'xpto-${environmentName}-tenant'
      countryCode: 'PT'
    
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

The Command that I'm running is this

New-AzSubscriptionDeployment -Name xpto-devTEST -TemplateFile main.bicep -TemplateParameterFile .\main.parameters-dev.json -DeploymentDebugLogLevel All
Run Code Online (Sandbox Code Playgroud)

Can Anyone help me?

小智 6

resource b2cDirectory 'Microsoft.AzureActiveDirectory/b2cDirectories@2021-04-01' = {
  #disable-next-line no-hardcoded-location
  location: 'Australia'
  name: '<your-name>.onmicrosoft.com'
  sku: {
    name: 'PremiumP2'
    tier: 'A0'
  }
  properties: {
    createTenantProperties: {
      countryCode: 'AU'
      displayName: '<Your description>'
    }
  }
  tags: {
    Department: 'Dev'
  }
}
Run Code Online (Sandbox Code Playgroud)

作品!名称可能很重要,您需要使用有效的 DNS 名称来命名您的资源。