|
| 1 | +--- |
| 2 | +title: Create resources at management group - Azure Resource Manager template |
| 3 | +description: Describes how to deploy resources at the management group scope in an Azure Resource Manager template. |
| 4 | +author: tfitzmac |
| 5 | +ms.service: azure-resource-manager |
| 6 | +ms.topic: conceptual |
| 7 | +ms.date: 11/07/2019 |
| 8 | +ms.author: tomfitz |
| 9 | +--- |
| 10 | + |
| 11 | +# Create resources at the management group level |
| 12 | + |
| 13 | +Typically, you deploy Azure resources to a resource group in your Azure subscription. However, you can also create resources at the management group level. You use management group level deployments to take actions that make sense at that level, such as assigning [role-based access control](../role-based-access-control/overview.md) or applying [policies](../governance/policy/overview.md). |
| 14 | + |
| 15 | +Currently, to deploy templates at the management group level, you must use the REST API. |
| 16 | + |
| 17 | +## Supported resources |
| 18 | + |
| 19 | +You can deploy the following resource types at the management group level: |
| 20 | + |
| 21 | +* [deployments](/azure/templates/microsoft.resources/deployments) |
| 22 | +* [policyAssignments](/azure/templates/microsoft.authorization/policyassignments) |
| 23 | +* [policyDefinitions](/azure/templates/microsoft.authorization/policydefinitions) |
| 24 | +* [policySetDefinitions](/azure/templates/microsoft.authorization/policysetdefinitions) |
| 25 | +* [roleAssignments](/azure/templates/microsoft.authorization/roleassignments) |
| 26 | +* [roleDefinitions](/azure/templates/microsoft.authorization/roledefinitions) |
| 27 | + |
| 28 | +### Schema |
| 29 | + |
| 30 | +The schema you use for management group deployments is different than the schema for resource group deployments. |
| 31 | + |
| 32 | +For templates, use: |
| 33 | + |
| 34 | +```json |
| 35 | +https://schema.management.azure.com/schemas/2019-08-01/managementGroupDeploymentTemplate.json# |
| 36 | +``` |
| 37 | + |
| 38 | +For parameter files, use: |
| 39 | + |
| 40 | +```json |
| 41 | +https://schema.management.azure.com/schemas/2019-08-01/managementGroupDeploymentParameters.json# |
| 42 | +``` |
| 43 | + |
| 44 | +## Deployment commands |
| 45 | + |
| 46 | +The command for management group deployments is different than the command for resource group deployments. |
| 47 | + |
| 48 | +For REST API, use [Deployments - Create At Management Group Scope](/rest/api/resources/deployments/createorupdateatmanagementgroupscope). |
| 49 | + |
| 50 | +## Deployment location and name |
| 51 | + |
| 52 | +For management group level deployments, you must provide a location for the deployment. The location of the deployment is separate from the location of the resources you deploy. The deployment location specifies where to store deployment data. |
| 53 | + |
| 54 | +You can provide a name for the deployment, or use the default deployment name. The default name is the name of the template file. For example, deploying a template named **azuredeploy.json** creates a default deployment name of **azuredeploy**. |
| 55 | + |
| 56 | +For each deployment name, the location is immutable. You can't create a deployment in one location when there's an existing deployment with the same name in a different location. If you get the error code `InvalidDeploymentLocation`, either use a different name or the same location as the previous deployment for that name. |
| 57 | + |
| 58 | +## Use template functions |
| 59 | + |
| 60 | +For management group deployments, there are some important considerations when using template functions: |
| 61 | + |
| 62 | +* The [resourceGroup()](resource-group-template-functions-resource.md#resourcegroup) function is **not** supported. |
| 63 | +* The [subscription()](resource-group-template-functions-resource.md#subscription) function is **not** supported. |
| 64 | +* The [resourceId()](resource-group-template-functions-resource.md#resourceid) function is supported. Use it to get the resource ID for resources that are used at management group level deployments. For example, get the resource ID for a policy definition with `resourceId('Microsoft.Authorization/roleDefinitions/', parameters('roleDefinition'))`. It returns the resource ID in the format `/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}`. |
| 65 | +* The [reference()](resource-group-template-functions-resource.md#reference) and [list()](resource-group-template-functions-resource.md#list) functions are supported. |
| 66 | + |
| 67 | +## Create policies |
| 68 | + |
| 69 | +### Define policy |
| 70 | + |
| 71 | +The following example shows how to [define](../governance/policy/concepts/definition-structure.md) a policy at the management group level. |
| 72 | + |
| 73 | +```json |
| 74 | +{ |
| 75 | + "$schema": "https://schema.management.azure.com/schemas/2019-08-01/managementGroupDeploymentTemplate.json#", |
| 76 | + "contentVersion": "1.0.0.0", |
| 77 | + "parameters": {}, |
| 78 | + "variables": {}, |
| 79 | + "resources": [ |
| 80 | + { |
| 81 | + "type": "Microsoft.Authorization/policyDefinitions", |
| 82 | + "name": "locationpolicy", |
| 83 | + "apiVersion": "2018-05-01", |
| 84 | + "properties": { |
| 85 | + "policyType": "Custom", |
| 86 | + "parameters": {}, |
| 87 | + "policyRule": { |
| 88 | + "if": { |
| 89 | + "field": "location", |
| 90 | + "equals": "northeurope" |
| 91 | + }, |
| 92 | + "then": { |
| 93 | + "effect": "deny" |
| 94 | + } |
| 95 | + } |
| 96 | + } |
| 97 | + } |
| 98 | + ] |
| 99 | +} |
| 100 | +``` |
| 101 | + |
| 102 | +### Assign policy |
| 103 | + |
| 104 | +The following example assigns an existing policy definition to the management group. If the policy takes parameters, provide them as an object. If the policy doesn't take parameters, use the default empty object. |
| 105 | + |
| 106 | +```json |
| 107 | +{ |
| 108 | + "$schema": "https://schema.management.azure.com/schemas/2019-08-01/managementGroupDeploymentTemplate.json#", |
| 109 | + "contentVersion": "1.0.0.0", |
| 110 | + "parameters": { |
| 111 | + "policyDefinitionID": { |
| 112 | + "type": "string" |
| 113 | + }, |
| 114 | + "policyName": { |
| 115 | + "type": "string" |
| 116 | + }, |
| 117 | + "policyParameters": { |
| 118 | + "type": "object", |
| 119 | + "defaultValue": {} |
| 120 | + } |
| 121 | + }, |
| 122 | + "variables": {}, |
| 123 | + "resources": [ |
| 124 | + { |
| 125 | + "type": "Microsoft.Authorization/policyAssignments", |
| 126 | + "name": "[parameters('policyName')]", |
| 127 | + "apiVersion": "2018-03-01", |
| 128 | + "properties": { |
| 129 | + "policyDefinitionId": "[parameters('policyDefinitionID')]", |
| 130 | + "parameters": "[parameters('policyParameters')]" |
| 131 | + } |
| 132 | + } |
| 133 | + ] |
| 134 | +} |
| 135 | +``` |
| 136 | + |
| 137 | + |
| 138 | + |
| 139 | +## Next steps |
| 140 | + |
| 141 | +* To learn about assigning roles, see [Manage access to Azure resources using RBAC and Azure Resource Manager templates](../role-based-access-control/role-assignments-template.md). |
| 142 | +* For an example of deploying workspace settings for Azure Security Center, see [deployASCwithWorkspaceSettings.json](https://github.com/krnese/AzureDeploy/blob/master/ARM/deployments/deployASCwithWorkspaceSettings.json). |
| 143 | +* To learn about creating Azure Resource Manager templates, see [Authoring templates](resource-group-authoring-templates.md). |
| 144 | +* For a list of the available functions in a template, see [Template functions](resource-group-template-functions.md). |
0 commit comments