From ccbdd86f2c44eaf5ddf86347f45b47e25fc5f5a3 Mon Sep 17 00:00:00 2001 From: MrMCake Date: Sun, 18 Sep 2022 14:11:56 +0200 Subject: [PATCH 1/2] Updated Resources ResourceGroups to new dependencies approach --- .../workflows/ms.resources.resourcegroups.yml | 3 +- .../.test/common/dependencies.bicep | 14 +++++ .../.test/common/deploy.test.bicep | 56 +++++++++++++++++++ .../.test/min/dependencies.bicep | 14 +++++ .../.test/min/deploy.test.bicep | 18 ++++++ .../resourceGroups/.test/parameters.json | 27 --------- .../resourceGroups/readme.md | 49 ++++++++++++++-- 7 files changed, 146 insertions(+), 35 deletions(-) create mode 100644 modules/Microsoft.Resources/resourceGroups/.test/common/dependencies.bicep create mode 100644 modules/Microsoft.Resources/resourceGroups/.test/common/deploy.test.bicep create mode 100644 modules/Microsoft.Resources/resourceGroups/.test/min/dependencies.bicep create mode 100644 modules/Microsoft.Resources/resourceGroups/.test/min/deploy.test.bicep delete mode 100644 modules/Microsoft.Resources/resourceGroups/.test/parameters.json diff --git a/.github/workflows/ms.resources.resourcegroups.yml b/.github/workflows/ms.resources.resourcegroups.yml index 971887f25e..17916c688f 100644 --- a/.github/workflows/ms.resources.resourcegroups.yml +++ b/.github/workflows/ms.resources.resourcegroups.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.Resources/resourceGroups/.test/common/dependencies.bicep b/modules/Microsoft.Resources/resourceGroups/.test/common/dependencies.bicep new file mode 100644 index 0000000000..7371d4437b --- /dev/null +++ b/modules/Microsoft.Resources/resourceGroups/.test/common/dependencies.bicep @@ -0,0 +1,14 @@ +@description('Optional. The location to deploy to.') +param location string = resourceGroup().location + +@description('Required. The name of the Managed Identity to create.') +param managedIdentityName string + +resource managedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2018-11-30' = { + name: managedIdentityName + location: location +} + +@description('The principal ID of the created Managed Identity.') +output managedIdentityPrincipalId string = managedIdentity.properties.principalId + diff --git a/modules/Microsoft.Resources/resourceGroups/.test/common/deploy.test.bicep b/modules/Microsoft.Resources/resourceGroups/.test/common/deploy.test.bicep new file mode 100644 index 0000000000..24f5d3e0fc --- /dev/null +++ b/modules/Microsoft.Resources/resourceGroups/.test/common/deploy.test.bicep @@ -0,0 +1,56 @@ +targetScope = 'subscription' + +// ========== // +// Parameters // +// ========== // +@description('Optional. The name of the resource group to deploy for a testing purposes') +@maxLength(90) +param resourceGroupName string = 'ms.resources.resourcegroups-${serviceShort}-rg' + +@description('Optional. The location to deploy resources to') +param location string = deployment().location + +@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 = 'rrgcom' + +// =========== // +// Deployments // +// =========== // + +// General resources +// ================= +resource resourceGroup 'Microsoft.Resources/resourceGroups@2021-04-01' = { + name: resourceGroupName + location: location +} + +module resourceGroupResources 'dependencies.bicep' = { + scope: resourceGroup + name: '${uniqueString(deployment().name, location)}-paramNested' + params: { + managedIdentityName: 'dep-<>-msi-${serviceShort}' + } +} + +// ============== // +// Test Execution // +// ============== // + +module testDeployment '../../deploy.bicep' = { + name: '${uniqueString(deployment().name)}-test-${serviceShort}' + params: { + name: '<>${serviceShort}001' + lock: 'CanNotDelete' + roleAssignments: [ + { + principalIds: [ + resourceGroupResources.outputs.managedIdentityPrincipalId + ] + roleDefinitionIdOrName: 'Reader' + } + ] + tags: { + Test: 'Yes' + } + } +} diff --git a/modules/Microsoft.Resources/resourceGroups/.test/min/dependencies.bicep b/modules/Microsoft.Resources/resourceGroups/.test/min/dependencies.bicep new file mode 100644 index 0000000000..7371d4437b --- /dev/null +++ b/modules/Microsoft.Resources/resourceGroups/.test/min/dependencies.bicep @@ -0,0 +1,14 @@ +@description('Optional. The location to deploy to.') +param location string = resourceGroup().location + +@description('Required. The name of the Managed Identity to create.') +param managedIdentityName string + +resource managedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2018-11-30' = { + name: managedIdentityName + location: location +} + +@description('The principal ID of the created Managed Identity.') +output managedIdentityPrincipalId string = managedIdentity.properties.principalId + diff --git a/modules/Microsoft.Resources/resourceGroups/.test/min/deploy.test.bicep b/modules/Microsoft.Resources/resourceGroups/.test/min/deploy.test.bicep new file mode 100644 index 0000000000..21c26845a1 --- /dev/null +++ b/modules/Microsoft.Resources/resourceGroups/.test/min/deploy.test.bicep @@ -0,0 +1,18 @@ +targetScope = 'subscription' + +// ========== // +// 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 = 'rrgmin' + +// ============== // +// Test Execution // +// ============== // + +module testDeployment '../../deploy.bicep' = { + name: '${uniqueString(deployment().name)}-test-${serviceShort}' + params: { + name: '<>${serviceShort}001' + } +} diff --git a/modules/Microsoft.Resources/resourceGroups/.test/parameters.json b/modules/Microsoft.Resources/resourceGroups/.test/parameters.json deleted file mode 100644 index a132c26376..0000000000 --- a/modules/Microsoft.Resources/resourceGroups/.test/parameters.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", - "contentVersion": "1.0.0.0", - "parameters": { - "name": { - "value": "<>-az-rg-x-001" - }, - "lock": { - "value": "CanNotDelete" - }, - "tags": { - "value": { - "Test": "Yes" - } - }, - "roleAssignments": { - "value": [ - { - "roleDefinitionIdOrName": "Reader", - "principalIds": [ - "<>" - ] - } - ] - } - } -} diff --git a/modules/Microsoft.Resources/resourceGroups/readme.md b/modules/Microsoft.Resources/resourceGroups/readme.md index a49b5ec31f..465d3fef4b 100644 --- a/modules/Microsoft.Resources/resourceGroups/readme.md +++ b/modules/Microsoft.Resources/resourceGroups/readme.md @@ -163,7 +163,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

@@ -171,16 +171,16 @@ The following module usage examples are retrieved from the content of the files ```bicep module resourceGroups './Microsoft.Resources/resourceGroups/deploy.bicep' = { - name: '${uniqueString(deployment().name)}-ResourceGroups' + name: '${uniqueString(deployment().name)}-test-rrgcom' params: { // Required parameters - name: '<>-az-rg-x-001' + name: '<>rrgcom001' // Non-required parameters lock: 'CanNotDelete' roleAssignments: [ { principalIds: [ - '<>' + '' ] roleDefinitionIdOrName: 'Reader' } @@ -206,7 +206,7 @@ module resourceGroups './Microsoft.Resources/resourceGroups/deploy.bicep' = { "parameters": { // Required parameters "name": { - "value": "<>-az-rg-x-001" + "value": "<>rrgcom001" }, // Non-required parameters "lock": { @@ -216,7 +216,7 @@ module resourceGroups './Microsoft.Resources/resourceGroups/deploy.bicep' = { "value": [ { "principalIds": [ - "<>" + "" ], "roleDefinitionIdOrName": "Reader" } @@ -233,3 +233,40 @@ module resourceGroups './Microsoft.Resources/resourceGroups/deploy.bicep' = {

+ +

Example 2: Min

+ +
+ +via Bicep module + +```bicep +module resourceGroups './Microsoft.Resources/resourceGroups/deploy.bicep' = { + name: '${uniqueString(deployment().name)}-test-rrgmin' + params: { + name: '<>rrgmin001' + } +} +``` + +
+

+ +

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

From e34bc984b292c3194652bcfb495fd2e2b7b97528 Mon Sep 17 00:00:00 2001 From: MrMCake Date: Sun, 18 Sep 2022 22:30:24 +0200 Subject: [PATCH 2/2] Removed unused file --- .../resourceGroups/.test/min/dependencies.bicep | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 modules/Microsoft.Resources/resourceGroups/.test/min/dependencies.bicep diff --git a/modules/Microsoft.Resources/resourceGroups/.test/min/dependencies.bicep b/modules/Microsoft.Resources/resourceGroups/.test/min/dependencies.bicep deleted file mode 100644 index 7371d4437b..0000000000 --- a/modules/Microsoft.Resources/resourceGroups/.test/min/dependencies.bicep +++ /dev/null @@ -1,14 +0,0 @@ -@description('Optional. The location to deploy to.') -param location string = resourceGroup().location - -@description('Required. The name of the Managed Identity to create.') -param managedIdentityName string - -resource managedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2018-11-30' = { - name: managedIdentityName - location: location -} - -@description('The principal ID of the created Managed Identity.') -output managedIdentityPrincipalId string = managedIdentity.properties.principalId -