From be993b5de264cf99e5c84f32d843e8c8fbc40cd3 Mon Sep 17 00:00:00 2001 From: MrMCake Date: Fri, 9 Sep 2022 15:15:18 +0200 Subject: [PATCH 1/7] Updated ManagementGroup to new dependency approach --- .../ms.management.managementgroups.yml | 3 +-- .../.test/common/deploy.test.bicep | 20 +++++++++++++++++++ .../managementGroups/.test/parameters.json | 15 -------------- .../managementGroups/readme.md | 12 +++++------ 4 files changed, 27 insertions(+), 23 deletions(-) create mode 100644 modules/Microsoft.Management/managementGroups/.test/common/deploy.test.bicep delete mode 100644 modules/Microsoft.Management/managementGroups/.test/parameters.json 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..2ae9bf81d8 --- /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 = 'mmgcommon' + +// ============== // +// Test Execution // +// ============== // + +module testDeployment '../../deploy.bicep' = { + name: '${uniqueString(deployment().name)}-test-${serviceShort}' + params: { + name: '<>${serviceShort}001' + displayName: 'Test MG' + parentId: managementGroup().id + } +} 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/readme.md b/modules/Microsoft.Management/managementGroups/readme.md index 258b1bcf95..b03fe64c80 100644 --- a/modules/Microsoft.Management/managementGroups/readme.md +++ b/modules/Microsoft.Management/managementGroups/readme.md @@ -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-mmgcommon' params: { // Required parameters - name: 'testMG' + name: '<>mmgcommon001' // Non-required parameters displayName: 'Test MG' - parentId: '<>' + parentId: '' } } ``` @@ -166,14 +166,14 @@ module managementGroups './Microsoft.Management/managementGroups/deploy.bicep' = "parameters": { // Required parameters "name": { - "value": "testMG" + "value": "<>mmgcommon001" }, // Non-required parameters "displayName": { "value": "Test MG" }, "parentId": { - "value": "<>" + "value": "" } } } From b0804ef59e3189713f8414a8ea3451b5f516c9d3 Mon Sep 17 00:00:00 2001 From: MrMCake Date: Fri, 9 Sep 2022 15:46:00 +0200 Subject: [PATCH 2/7] Updated id handling --- .../managementGroups/.test/common/deploy.test.bicep | 2 +- modules/Microsoft.Management/managementGroups/deploy.bicep | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/Microsoft.Management/managementGroups/.test/common/deploy.test.bicep b/modules/Microsoft.Management/managementGroups/.test/common/deploy.test.bicep index 2ae9bf81d8..094d35ac70 100644 --- a/modules/Microsoft.Management/managementGroups/.test/common/deploy.test.bicep +++ b/modules/Microsoft.Management/managementGroups/.test/common/deploy.test.bicep @@ -15,6 +15,6 @@ module testDeployment '../../deploy.bicep' = { params: { name: '<>${serviceShort}001' displayName: 'Test MG' - parentId: managementGroup().id + parentId: split(managementGroup().name, '/')[-1] } } diff --git a/modules/Microsoft.Management/managementGroups/deploy.bicep b/modules/Microsoft.Management/managementGroups/deploy.bicep index 932752c182..993d81c9d4 100644 --- a/modules/Microsoft.Management/managementGroups/deploy.bicep +++ b/modules/Microsoft.Management/managementGroups/deploy.bicep @@ -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 } From ffc1d6c8410c751548438cc6a6ecd126ce228c06 Mon Sep 17 00:00:00 2001 From: MrMCake Date: Fri, 9 Sep 2022 15:54:43 +0200 Subject: [PATCH 3/7] Update to latest --- .../managementGroups/.test/common/deploy.test.bicep | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/Microsoft.Management/managementGroups/.test/common/deploy.test.bicep b/modules/Microsoft.Management/managementGroups/.test/common/deploy.test.bicep index 094d35ac70..9ae37a78b5 100644 --- a/modules/Microsoft.Management/managementGroups/.test/common/deploy.test.bicep +++ b/modules/Microsoft.Management/managementGroups/.test/common/deploy.test.bicep @@ -15,6 +15,6 @@ module testDeployment '../../deploy.bicep' = { params: { name: '<>${serviceShort}001' displayName: 'Test MG' - parentId: split(managementGroup().name, '/')[-1] + parentId: split(managementGroup().id, '/')[-1] } } From 8fe47c805ca6d9eab84367f3f9ffc41de54899ad Mon Sep 17 00:00:00 2001 From: MrMCake Date: Fri, 9 Sep 2022 16:11:45 +0200 Subject: [PATCH 4/7] Update to latest --- .../managementGroups/.test/common/deploy.test.bicep | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/Microsoft.Management/managementGroups/.test/common/deploy.test.bicep b/modules/Microsoft.Management/managementGroups/.test/common/deploy.test.bicep index 9ae37a78b5..19e09b6305 100644 --- a/modules/Microsoft.Management/managementGroups/.test/common/deploy.test.bicep +++ b/modules/Microsoft.Management/managementGroups/.test/common/deploy.test.bicep @@ -15,6 +15,6 @@ module testDeployment '../../deploy.bicep' = { params: { name: '<>${serviceShort}001' displayName: 'Test MG' - parentId: split(managementGroup().id, '/')[-1] + parentId: last(split(managementGroup().id, '/')) } } From 37187de27a2351aa5d38dab3216ddc625af1fe26 Mon Sep 17 00:00:00 2001 From: MrMCake Date: Wed, 5 Oct 2022 20:16:25 +0200 Subject: [PATCH 5/7] Update to latest --- .../managementGroups/.test/common/deploy.test.bicep | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/Microsoft.Management/managementGroups/.test/common/deploy.test.bicep b/modules/Microsoft.Management/managementGroups/.test/common/deploy.test.bicep index 19e09b6305..87210701d0 100644 --- a/modules/Microsoft.Management/managementGroups/.test/common/deploy.test.bicep +++ b/modules/Microsoft.Management/managementGroups/.test/common/deploy.test.bicep @@ -3,7 +3,7 @@ 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') +@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 = 'mmgcommon' // ============== // From 9bed1e9bb3d8f0932d6a34572d0b8d8a90832ea2 Mon Sep 17 00:00:00 2001 From: MrMCake Date: Mon, 10 Oct 2022 19:48:57 +0200 Subject: [PATCH 6/7] Update to latest --- modules/Microsoft.Management/managementGroups/deploy.bicep | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/Microsoft.Management/managementGroups/deploy.bicep b/modules/Microsoft.Management/managementGroups/deploy.bicep index 993d81c9d4..f847671be5 100644 --- a/modules/Microsoft.Management/managementGroups/deploy.bicep +++ b/modules/Microsoft.Management/managementGroups/deploy.bicep @@ -9,7 +9,7 @@ param displayName string = '' @description('Optional. The management group parent ID. Defaults to current scope.') param parentId string = '' -@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).') From 30e7dbb5728eb9000e1e079364222cba65a2d020 Mon Sep 17 00:00:00 2001 From: MrMCake Date: Mon, 10 Oct 2022 19:53:35 +0200 Subject: [PATCH 7/7] Added default value + min test --- .../.test/common/deploy.test.bicep | 2 +- .../.test/min/deploy.test.bicep | 18 ++++++++ .../managementGroups/deploy.bicep | 2 +- .../managementGroups/readme.md | 45 +++++++++++++++++-- 4 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 modules/Microsoft.Management/managementGroups/.test/min/deploy.test.bicep diff --git a/modules/Microsoft.Management/managementGroups/.test/common/deploy.test.bicep b/modules/Microsoft.Management/managementGroups/.test/common/deploy.test.bicep index 87210701d0..2e3f776cc7 100644 --- a/modules/Microsoft.Management/managementGroups/.test/common/deploy.test.bicep +++ b/modules/Microsoft.Management/managementGroups/.test/common/deploy.test.bicep @@ -4,7 +4,7 @@ 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 = 'mmgcommon' +param serviceShort string = 'mmgcom' // ============== // // Test Execution // 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/deploy.bicep b/modules/Microsoft.Management/managementGroups/deploy.bicep index f847671be5..dcd2872b84 100644 --- a/modules/Microsoft.Management/managementGroups/deploy.bicep +++ b/modules/Microsoft.Management/managementGroups/deploy.bicep @@ -7,7 +7,7 @@ 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, '/')) @description('Optional. Location deployment metadata.') param location string = deployment().location diff --git a/modules/Microsoft.Management/managementGroups/readme.md b/modules/Microsoft.Management/managementGroups/readme.md index b03fe64c80..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` @@ -141,10 +141,10 @@ 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)}-test-mmgcommon' + name: '${uniqueString(deployment().name)}-test-mmgcom' params: { // Required parameters - name: '<>mmgcommon001' + name: '<>mmgcom001' // Non-required parameters displayName: 'Test MG' parentId: '' @@ -166,7 +166,7 @@ module managementGroups './Microsoft.Management/managementGroups/deploy.bicep' = "parameters": { // Required parameters "name": { - "value": "<>mmgcommon001" + "value": "<>mmgcom001" }, // Non-required parameters "displayName": { @@ -181,3 +181,40 @@ module managementGroups './Microsoft.Management/managementGroups/deploy.bicep' =

+ +

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" + } + } +} +``` + +
+