Skip to content

Instantly share code, notes, and snippets.

@rjygraham
Last active February 24, 2022 16:26
Show Gist options
  • Save rjygraham/43912b7fc9b58a9f112f597c9332e89c to your computer and use it in GitHub Desktop.
Save rjygraham/43912b7fc9b58a9f112f597c9332e89c to your computer and use it in GitHub Desktop.
Bicep Management Group template cycle error
New-AzTenantDeployment -TemplateFile .\managementGroups.bicep -TemplateParameterFile .\managementGroupsHierarchy.parameters.json -Location eastus
targetScope = 'tenant'
param parParentManagmentGroupId string
param parManagementGroupName string
param parManagementGroupDisplayName string
param parChildrenManagementGroups array = []
resource resParentedManagementGroup 'Microsoft.Management/managementGroups@2021-04-01' = if(!empty(parParentManagmentGroupId)) {
name: parManagementGroupName
properties: {
displayName: parManagementGroupDisplayName
details: {
parent: {
id: parParentManagmentGroupId
}
}
}
}
resource resManagementGroup 'Microsoft.Management/managementGroups@2021-04-01' = if(empty(parParentManagmentGroupId)) {
name: parManagementGroupName
properties: {
displayName: parManagementGroupDisplayName
details: {
}
}
}
module modChildrenManagementGroups 'managementGroups.bicep' = if (length(parChildrenManagementGroups) > 0) {
name: '${parManagementGroupName}-children'
params: {
parParentManagmentGroupId: if(empty(parParentManagmentGroupId)) ? resManagementGroup.id : resParentedManagementGroup.id
parManagementGroupHierarchy: parChildrenManagementGroups
}
}
targetScope = 'tenant'
@description('Resource ID of the parent Management Group')
param parParentManagmentGroupId string = ''
@description('Management group hierarchy to be deployed.')
param parManagementGroupHierarchy array
module modManagementGroup 'managementGroup.bicep' = [for (mg, i) in parManagementGroupHierarchy: {
name: '${mg.name}'
params: {
parParentManagmentGroupId: parParentManagmentGroupId
parManagementGroupName: mg.name
parManagementGroupDisplayName: mg.displayName
parChildrenManagementGroups: mg.children
}
}]
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"parManagementGroupHierarchy": {
"value": [
{
"name": "alz",
"displayName": "Azure Landing Zones",
"children": [
{
"name": "alz-decommissioned",
"displayName": "Decommissioned",
"children": []
},
{
"name": "alz-landingzones",
"displayName": "Landing Zones",
"children": [
{
"name": "alz-landingzones-corp",
"displayName": "Corp",
"children": []
},
{
"name": "alz-landingzones-online",
"displayName": "Online",
"children": []
}
]
},
{
"name": "alz-platform",
"displayName": "Platform",
"children": [
{
"name": "alz-platform-connectivity",
"displayName": "Connectivity",
"children": []
},
{
"name": "alz-platform-identity",
"displayName": "Identity",
"children": []
},
{
"name": "alz-platform-management",
"displayName": "Management",
"children": []
}
]
},
{
"name": "alz-sandbox",
"displayName": "Sandbox",
"children": []
}
]
}
]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment