使用 Bicep 模板创建 Azure 订阅失败并出现错误 'InvalidSubCreationScope - Not a valid subscription creation scope'

Creating an Azure Subscription with a Bicep template fails with error 'InvalidSubCreationScope - Not a valid subscription creation scope'

我正在尝试使用以下二头肌模板创建新的 Azure 订阅:

targetScope = 'tenant'

var spokeSubscriptionName = 'Test Sub'
resource spokeSubscription 'Microsoft.Subscription/aliases@2020-09-01' = {
  scope: tenant()
  name: name: guid(spokeSubscriptionName, tenant().tenantId)
  properties: {
    displayName: spokeSubscriptionName
    billingScope: '/providers/Microsoft.Billing/billingAccounts/foo:bar'
    workload: 'Production'
  }
}

当我使用此命令执行部署时:

az deployment tenant create --name 01TestSubDeploy2021-11-21 --location uksouth --template-file .\subscription-only.bicep

我收到以下错误:

{
    "status": "Failed",
    "error": {
        "code": "DeploymentFailed",
        "message": "At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.",
        "details": [
            {
                "code": "BadRequest",
                "message": "{\r\n  \"error\": {\r\n    \"code\": \"InvalidSubCreationScope\",\r\n    \"message\": \"Not a valid subscription creation scope\"\r\n  },\r\n  \"code\": \"InvalidSubCreationScope\",\r\n  \"message\": \"Not a valid subscription creation scope\"\r\n}"
            }
        ]
    }
}

运行 带有 --what-if 开关的命令 returns 如下:

The deployment will update the following scope:

Scope: /

  + Microsoft.Subscription/aliases/[SUBGUID] [2020-09-01]

      apiVersion:              "2020-09-01"
      id:                      "/providers/Microsoft.Subscription/aliases/[SUBGUID]"
      name:                    "[SUBGUID]"
      properties.billingScope: "/providers/Microsoft.Billing/billingAccounts/foo:bar"
      properties.displayName:  "Test Sub"
      properties.workload:     "Production"
      type:                    "Microsoft.Subscription/aliases"

我使用的帐户在 Root 范围内具有所有者权限。

This post 表明我为计费范围使用的值可能不正确。我从命令 az billing account list 返回的 ID 属性 中获取了计费范围值。我已经尝试了完整的范围路径和 ID 值。

计费帐户的类型为 'Microsoft Customer Agreement'(例如,不是 EA)。大多数关于程序化订阅创建的文档都明确指出示例适用于 EA 租户,'modifications will need to be made' 适用于其他租户类型。但是,没有说不可能。

我想确认 MCA 计费帐户目前无法通过 Bicep 模板创建订阅,或者更正我的模板或部署命令中的任何错误。

提前致谢!

此错误是由于计费范围无效造成的。

MCA 订阅的正确范围需要包括计费帐户、计费配置文件和发票部分。

此处有更多详细信息:https://docs.microsoft.com/en-us/azure/cost-management-billing/manage/programmatically-create-subscription-microsoft-customer-agreement