如何使用ARM模板在管理组下移动订阅?

时间:2020-08-24 23:50:25

标签: azure-resource-manager arm-template azure-management-groups

如何通过ARM模板将预订移至管理组下?应该可以通过以下资源提供程序来实现:Microsoft.Management managementGroups/subscriptions template reference

我尝试用两种方式定义预订子资源,但是两个部署均因相同的错误而失败:'error': {'code': 'InternalServerError', 'message': "(...) 500 - Internal server error. There is a problem with the resource you are looking for, and it cannot be displayed. (...)" } }

选项1:

{
    "$schema": "https://schema.management.azure.com/schemas/2019-08-01/managementGroupDeploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "managementGroupName": {
            "type": "String",
            "metadata": {
                "description": "The management group to be configured"
            }
        },
        "childSubscription": {
            "type": "String",
            "metadata": {
                "description": "The list of child subscription IDs of the management group"
            }
        }
    },
    "variables": {},
    "functions": [],
    "resources": [
        {
            "type": "Microsoft.Management/managementGroups",
            "apiVersion": "2019-11-01",
            "name": "[parameters('managementGroupName')]",
            "resources": [
                {
                    "type": "subscriptions",
                    "apiVersion": "2020-05-01",
                    "name": "[parameters('childSubscription')]",
                    "dependsOn": [
                        "[parameters('managementGroupName')]"
                    ]
                }
            ]
        }
    ],
    "outputs": {}
}

选项2:

{
    "$schema": "https://schema.management.azure.com/schemas/2019-08-01/managementGroupDeploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "managementGroupName": {
            "type": "String",
            "metadata": {
                "description": "The management group to be configured"
            }
        },
        "childSubscription": {
            "type": "String",
            "metadata": {
                "description": "The list of child subscription IDs of the management group"
            }
        }
    },
    "variables": {},
    "functions": [],
    "resources": [
        {
            "type": "Microsoft.Management/managementGroups/subscriptions",
            "apiVersion": "2020-05-01",
            "name": "[concat(parameters('managementGroupName'), '/', parameters('childSubscription'))]"
        }
    ],
    "outputs": {}
}

1 个答案:

答案 0 :(得分:0)

必须在tenant level而不是管理组级别完成部署。然后资源定义变为:

{
  "type": "Microsoft.Management/managementGroups",
  "apiVersion": "2019-11-01",
  "name": "[variables('managementGroupName')]",
  "properties": {},
  "resources": [
    {
      "type": "subscriptions",
      "apiVersion": "2020-05-01",
      "name": "[parameters('childSubscriptionId')]",
      "dependsOn": [
        "[variables('managementGroupName')]"
      ]
    }
  ]
}