diff --git a/.github/workflows/ms.management.managementgroups.yml b/.github/workflows/ms.management.managementgroups.yml index 3f0258f95e..3f0b2e12ab 100644 --- a/.github/workflows/ms.management.managementgroups.yml +++ b/.github/workflows/ms.management.managementgroups.yml @@ -106,8 +106,7 @@ jobs: - name: 'Using test file [${{ matrix.moduleTestFilePaths }}]' uses: ./.github/actions/templates/validateModuleDeployment with: - templateFilePath: '${{ env.modulePath }}/deploy.bicep' - parameterFilePath: '${{ env.modulePath }}/${{ matrix.moduleTestFilePaths }}' + templateFilePath: '${{ env.modulePath }}/${{ matrix.moduleTestFilePaths }}' location: '${{ env.location }}' resourceGroupName: '${{ env.resourceGroupName }}' subscriptionId: '${{ secrets.ARM_SUBSCRIPTION_ID }}' diff --git a/modules/Microsoft.Management/managementGroups/.test/common/deploy.test.bicep b/modules/Microsoft.Management/managementGroups/.test/common/deploy.test.bicep new file mode 100644 index 0000000000..2e3f776cc7 --- /dev/null +++ b/modules/Microsoft.Management/managementGroups/.test/common/deploy.test.bicep @@ -0,0 +1,20 @@ +targetScope = 'managementGroup' + +// ========== // +// Parameters // +// ========== // +@description('Optional. A short identifier for the kind of deployment. Should be kept short to not run into resource-name length-constraints.') +param serviceShort string = 'mmgcom' + +// ============== // +// Test Execution // +// ============== // + +module testDeployment '../../deploy.bicep' = { + name: '${uniqueString(deployment().name)}-test-${serviceShort}' + params: { + name: '<>${serviceShort}001' + displayName: 'Test MG' + parentId: last(split(managementGroup().id, '/')) + } +} diff --git a/modules/Microsoft.Management/managementGroups/.test/min/deploy.test.bicep b/modules/Microsoft.Management/managementGroups/.test/min/deploy.test.bicep new file mode 100644 index 0000000000..f12739a8b5 --- /dev/null +++ b/modules/Microsoft.Management/managementGroups/.test/min/deploy.test.bicep @@ -0,0 +1,18 @@ +targetScope = 'managementGroup' + +// ========== // +// Parameters // +// ========== // +@description('Optional. A short identifier for the kind of deployment. Should be kept short to not run into resource-name length-constraints.') +param serviceShort string = 'mmgmin' + +// ============== // +// Test Execution // +// ============== // + +module testDeployment '../../deploy.bicep' = { + name: '${uniqueString(deployment().name)}-test-${serviceShort}' + params: { + name: '<>${serviceShort}001' + } +} diff --git a/modules/Microsoft.Management/managementGroups/.test/parameters.json b/modules/Microsoft.Management/managementGroups/.test/parameters.json deleted file mode 100644 index 21e2524a5f..0000000000 --- a/modules/Microsoft.Management/managementGroups/.test/parameters.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", - "contentVersion": "1.0.0.0", - "parameters": { - "name": { - "value": "testMG" - }, - "displayName": { - "value": "Test MG" - }, - "parentId": { - "value": "<>" - } - } -} diff --git a/modules/Microsoft.Management/managementGroups/deploy.bicep b/modules/Microsoft.Management/managementGroups/deploy.bicep index 932752c182..dcd2872b84 100644 --- a/modules/Microsoft.Management/managementGroups/deploy.bicep +++ b/modules/Microsoft.Management/managementGroups/deploy.bicep @@ -7,9 +7,9 @@ param name string param displayName string = '' @description('Optional. The management group parent ID. Defaults to current scope.') -param parentId string = '' +param parentId string = last(split(az.managementGroup().id, '/')) -@sys.description('Optional. Location deployment metadata.') +@description('Optional. Location deployment metadata.') param location string = deployment().location @description('Optional. Enable telemetry via the Customer Usage Attribution ID (GUID).') @@ -28,6 +28,11 @@ resource defaultTelemetry 'Microsoft.Resources/deployments@2021-04-01' = if (ena } } +resource parentManagementGroup 'Microsoft.Management/managementGroups@2021-04-01' existing = { + name: parentId + scope: tenant() +} + resource managementGroup 'Microsoft.Management/managementGroups@2021-04-01' = { name: name scope: tenant() @@ -35,7 +40,7 @@ resource managementGroup 'Microsoft.Management/managementGroups@2021-04-01' = { displayName: displayName details: !empty(parentId) ? { parent: { - id: '/providers/Microsoft.Management/managementGroups/${parentId}' + id: parentManagementGroup.id } } : null } diff --git a/modules/Microsoft.Management/managementGroups/readme.md b/modules/Microsoft.Management/managementGroups/readme.md index 258b1bcf95..e0e34b0617 100644 --- a/modules/Microsoft.Management/managementGroups/readme.md +++ b/modules/Microsoft.Management/managementGroups/readme.md @@ -35,7 +35,7 @@ This module has some known **limitations**: | `displayName` | string | `''` | The friendly name of the management group. If no value is passed then this field will be set to the group ID. | | `enableDefaultTelemetry` | bool | `True` | Enable telemetry via the Customer Usage Attribution ID (GUID). | | `location` | string | `[deployment().location]` | Location deployment metadata. | -| `parentId` | string | `''` | The management group parent ID. Defaults to current scope. | +| `parentId` | string | `[last(split(managementGroup().id, '/'))]` | The management group parent ID. Defaults to current scope. | ### Parameter Usage: `roleAssignments` @@ -133,7 +133,7 @@ The following module usage examples are retrieved from the content of the files >**Note**: Each example lists all the required parameters first, followed by the rest - each in alphabetical order. -

Example 1: Parameters

+

Example 1: Common

@@ -141,13 +141,13 @@ The following module usage examples are retrieved from the content of the files ```bicep module managementGroups './Microsoft.Management/managementGroups/deploy.bicep' = { - name: '${uniqueString(deployment().name)}-ManagementGroups' + name: '${uniqueString(deployment().name)}-test-mmgcom' params: { // Required parameters - name: 'testMG' + name: '<>mmgcom001' // Non-required parameters displayName: 'Test MG' - parentId: '<>' + parentId: '' } } ``` @@ -166,14 +166,51 @@ module managementGroups './Microsoft.Management/managementGroups/deploy.bicep' = "parameters": { // Required parameters "name": { - "value": "testMG" + "value": "<>mmgcom001" }, // Non-required parameters "displayName": { "value": "Test MG" }, "parentId": { - "value": "<>" + "value": "" + } + } +} +``` + +
+

+ +

Example 2: Min

+ +
+ +via Bicep module + +```bicep +module managementGroups './Microsoft.Management/managementGroups/deploy.bicep' = { + name: '${uniqueString(deployment().name)}-test-mmgmin' + params: { + name: '<>mmgmin001' + } +} +``` + +
+

+ +

+ +via JSON Parameter file + +```json +{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "name": { + "value": "<>mmgmin001" } } }