From c14fb0963f34c09109e7d524e1071945ae8161dc Mon Sep 17 00:00:00 2001 From: MrMCake Date: Tue, 30 Aug 2022 20:33:09 +0200 Subject: [PATCH 01/10] First commit --- .../locks/.test/default/deploy.test.bicep | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 modules/Microsoft.Authorization/locks/.test/default/deploy.test.bicep diff --git a/modules/Microsoft.Authorization/locks/.test/default/deploy.test.bicep b/modules/Microsoft.Authorization/locks/.test/default/deploy.test.bicep new file mode 100644 index 0000000000..b5d1fdf8b3 --- /dev/null +++ b/modules/Microsoft.Authorization/locks/.test/default/deploy.test.bicep @@ -0,0 +1,38 @@ +targetScope = 'subscription' + +// ========== // +// Parameters // +// ========== // +@description('Optional. The name of the resource group to deploy for a testing purposes') +@maxLength(80) +param resourceGroupName string = 'ms.authorization.locks-${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 = 'aldef' + +// =========== // +// Deployments // +// =========== // + +// General resources +// ================= +resource resourceGroup 'Microsoft.Resources/resourceGroups@2021-04-01' = { + name: resourceGroupName + location: location +} + +// ============== // +// Test Execution // +// ============== // + +module testDeployment '../../deploy.bicep' = { + name: '${uniqueString(deployment().name)}-test-${serviceShort}' + params: { + level: 'CanNotDelete' + resourceGroupName: resourceGroup.name + subscriptionId: subscription().subscriptionId + } +} From 1c63c84d7b92dbe908a90d02e3e340a478563cb9 Mon Sep 17 00:00:00 2001 From: MrMCake Date: Tue, 30 Aug 2022 20:33:55 +0200 Subject: [PATCH 02/10] [Modules] Updated Authorization/Locks to new dependency approach --- .github/workflows/ms.authorization.locks.yml | 3 +-- .../locks/.test/rg.parameters.json | 15 --------------- modules/Microsoft.Authorization/locks/readme.md | 14 +++++++------- 3 files changed, 8 insertions(+), 24 deletions(-) delete mode 100644 modules/Microsoft.Authorization/locks/.test/rg.parameters.json diff --git a/.github/workflows/ms.authorization.locks.yml b/.github/workflows/ms.authorization.locks.yml index 0372a1090d..0f274136fc 100644 --- a/.github/workflows/ms.authorization.locks.yml +++ b/.github/workflows/ms.authorization.locks.yml @@ -109,8 +109,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.Authorization/locks/.test/rg.parameters.json b/modules/Microsoft.Authorization/locks/.test/rg.parameters.json deleted file mode 100644 index dc4870ce99..0000000000 --- a/modules/Microsoft.Authorization/locks/.test/rg.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": { - "level": { - "value": "CanNotDelete" - }, - "resourceGroupName": { - "value": "adp-<>-az-locks-rg-001" - }, - "subscriptionId": { - "value": "<>" - } - } -} diff --git a/modules/Microsoft.Authorization/locks/readme.md b/modules/Microsoft.Authorization/locks/readme.md index 9533d2924d..63f95d8f14 100644 --- a/modules/Microsoft.Authorization/locks/readme.md +++ b/modules/Microsoft.Authorization/locks/readme.md @@ -51,21 +51,21 @@ The following module usage examples are retrieved from the content of the files >**Note**: The name of each example is based on the name of the file from which it is taken. >**Note**: Each example lists all the required parameters first, followed by the rest - each in alphabetical order. -

Example 1: Rg

+

Example 1: Default

via Bicep module ```bicep -module locks './Microsoft.Authorization/locks/deploy.bicep' = { - name: '${uniqueString(deployment().name)}-locks' +module Locks './Microsoft.Authorization/Locks/deploy.bicep' = { + name: '${uniqueString(deployment().name)}-test-aldef' params: { // Required parameters level: 'CanNotDelete' // Non-required parameters - resourceGroupName: 'adp-<>-az-locks-rg-001' - subscriptionId: '<>' + resourceGroupName: '' + subscriptionId: '' } } ``` @@ -88,10 +88,10 @@ module locks './Microsoft.Authorization/locks/deploy.bicep' = { }, // Non-required parameters "resourceGroupName": { - "value": "adp-<>-az-locks-rg-001" + "value": "" }, "subscriptionId": { - "value": "<>" + "value": "" } } } From d5df6801cbb9a2bef86f84bb1580f13af656b083 Mon Sep 17 00:00:00 2001 From: MrMCake Date: Tue, 30 Aug 2022 20:46:17 +0200 Subject: [PATCH 03/10] Updated readme --- utilities/tools/Set-ModuleReadMe.ps1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utilities/tools/Set-ModuleReadMe.ps1 b/utilities/tools/Set-ModuleReadMe.ps1 index a1074fed21..6b922d65e8 100644 --- a/utilities/tools/Set-ModuleReadMe.ps1 +++ b/utilities/tools/Set-ModuleReadMe.ps1 @@ -883,9 +883,10 @@ function Set-DeploymentExamplesSection { '' ) + $TextInfo = (Get-Culture -Name 'en-US').TextInfo $moduleRoot = Split-Path $TemplateFilePath -Parent - $resourceTypeIdentifier = $moduleRoot.Replace('\', '/').Split('/modules/')[1].TrimStart('/') - $resourceType = $resourceTypeIdentifier.Split('/')[1] + $resourceTypeIdentifier = $TextInfo.ToTitleCase($moduleRoot.Replace('\', '/').Split('/modules/')[1].TrimStart('/')) + $resourceType = $TextInfo.ToTitleCase($resourceTypeIdentifier.Split('/')[1]) $testFilePaths = Get-ModuleTestFileList -ModulePath $moduleRoot | ForEach-Object { Join-Path $moduleRoot $_ } $RequiredParametersList = $TemplateFileContent.parameters.Keys | Where-Object { $TemplateFileContent.parameters[$_].Keys -notcontains 'defaultValue' } | Sort-Object @@ -906,7 +907,6 @@ function Set-DeploymentExamplesSection { } else { $exampleTitle = ((Split-Path $testFilePath -LeafBase) -replace '\.', ' ') -replace ' parameters', '' } - $TextInfo = (Get-Culture -Name 'en-US').TextInfo $exampleTitle = $TextInfo.ToTitleCase($exampleTitle) $SectionContent += @( '

Example {0}: {1}

' -f $pathIndex, $exampleTitle From eb630525b820a81309cdc2eb116dca4b8fdbbe2d Mon Sep 17 00:00:00 2001 From: MrMCake Date: Thu, 1 Sep 2022 10:13:38 +0200 Subject: [PATCH 04/10] Update to latest --- utilities/tools/Set-ModuleReadMe.ps1 | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/utilities/tools/Set-ModuleReadMe.ps1 b/utilities/tools/Set-ModuleReadMe.ps1 index 6b922d65e8..25d22f3fff 100644 --- a/utilities/tools/Set-ModuleReadMe.ps1 +++ b/utilities/tools/Set-ModuleReadMe.ps1 @@ -51,7 +51,7 @@ function Set-ResourceTypesSection { $RelevantResourceTypeObjects = Get-NestedResourceList $TemplateFileContent | Where-Object { $_.type -notin $ResourceTypesToExclude -and $_ - } | Select-Object 'Type', 'ApiVersion' -Unique | Sort-Object Type -Culture en-US + } | Select-Object 'Type', 'ApiVersion' -Unique | Sort-Object Type -Culture 'en-US' foreach ($resourceTypeObject in $RelevantResourceTypeObjects) { $ProviderNamespace, $ResourceType = $resourceTypeObject.Type -split '/', 2 @@ -280,7 +280,7 @@ function Set-OutputsSection { '| Output Name | Type | Description |', '| :-- | :-- | :-- |' ) - foreach ($outputName in ($templateFileContent.outputs.Keys | Sort-Object -Culture en-US)) { + foreach ($outputName in ($templateFileContent.outputs.Keys | Sort-Object -Culture 'en-US')) { $output = $TemplateFileContent.outputs[$outputName] $description = $output.metadata.description.Replace("`r`n", '

').Replace("`n", '

') $SectionContent += ("| ``{0}`` | {1} | {2} |" -f $outputName, $output.type, $description) @@ -290,7 +290,7 @@ function Set-OutputsSection { '| Output Name | Type |', '| :-- | :-- |' ) - foreach ($outputName in ($templateFileContent.outputs.Keys | Sort-Object -Culture en-US)) { + foreach ($outputName in ($templateFileContent.outputs.Keys | Sort-Object -Culture 'en-US')) { $output = $TemplateFileContent.outputs[$outputName] $SectionContent += ("| ``{0}`` | {1} |" -f $outputName, $output.type) } @@ -883,10 +883,16 @@ function Set-DeploymentExamplesSection { '' ) - $TextInfo = (Get-Culture -Name 'en-US').TextInfo $moduleRoot = Split-Path $TemplateFilePath -Parent - $resourceTypeIdentifier = $TextInfo.ToTitleCase($moduleRoot.Replace('\', '/').Split('/modules/')[1].TrimStart('/')) - $resourceType = $TextInfo.ToTitleCase($resourceTypeIdentifier.Split('/')[1]) + $fullIdentifier = $moduleRoot.Replace('\', '/').Split('/modules/')[1].TrimStart('/') + + # Get resource type and make first letter upper case. Requires manual handling as ToTitleCase lowercases everything but the first letter + $providerNamespace = ($fullIdentifier.Split('/')[0] -split '\.' | ForEach-Object { $_.Substring(0, 1).ToUpper() + $_.Substring(1) }) -join '.' + $resourceType = $fullIdentifier.Split('/')[1] + $resourceTypeUpper = $resourceType.Substring(0, 1).ToUpper() + $resourceType.Substring(1) + + $resourceTypeIdentifier = "$providerNamespace/$resourceType" + $testFilePaths = Get-ModuleTestFileList -ModulePath $moduleRoot | ForEach-Object { Join-Path $moduleRoot $_ } $RequiredParametersList = $TemplateFileContent.parameters.Keys | Where-Object { $TemplateFileContent.parameters[$_].Keys -notcontains 'defaultValue' } | Sort-Object @@ -907,7 +913,8 @@ function Set-DeploymentExamplesSection { } else { $exampleTitle = ((Split-Path $testFilePath -LeafBase) -replace '\.', ' ') -replace ' parameters', '' } - $exampleTitle = $TextInfo.ToTitleCase($exampleTitle) + $textInfo = (Get-Culture -Name 'en-US').TextInfo + $exampleTitle = $textInfo.ToTitleCase($exampleTitle) $SectionContent += @( '

Example {0}: {1}

' -f $pathIndex, $exampleTitle ) @@ -1138,7 +1145,7 @@ function Set-DeploymentExamplesSection { '```bicep', $extendedKeyVaultReferences, "module $resourceType './$resourceTypeIdentifier/deploy.bicep' = {" - " name: '`${uniqueString(deployment().name)}-$resourceType'" + " name: '`${uniqueString(deployment().name)}-$resourceTypeUpper'" ' params: {' $bicepExample.TrimEnd(), ' }' From e3e743e6562005c4a018bceec6a1cce90c85438d Mon Sep 17 00:00:00 2001 From: MrMCake Date: Thu, 1 Sep 2022 11:30:09 +0200 Subject: [PATCH 05/10] Update to latest --- modules/Microsoft.Authorization/locks/readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/Microsoft.Authorization/locks/readme.md b/modules/Microsoft.Authorization/locks/readme.md index 14296aef23..63f95d8f14 100644 --- a/modules/Microsoft.Authorization/locks/readme.md +++ b/modules/Microsoft.Authorization/locks/readme.md @@ -58,8 +58,8 @@ The following module usage examples are retrieved from the content of the files via Bicep module ```bicep -module locks './Microsoft.Authorization/locks/deploy.bicep' = { - name: '${uniqueString(deployment().name)}-Locks' +module Locks './Microsoft.Authorization/Locks/deploy.bicep' = { + name: '${uniqueString(deployment().name)}-test-aldef' params: { // Required parameters level: 'CanNotDelete' From 3d4d70cb52b3203d96db199b1e24224fd3069cfd Mon Sep 17 00:00:00 2001 From: MrMCake Date: Thu, 8 Sep 2022 18:47:02 +0200 Subject: [PATCH 06/10] Updated folder default to common. --- .../locks/.test/{default => common}/deploy.test.bicep | 0 modules/Microsoft.Authorization/locks/readme.md | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) rename modules/Microsoft.Authorization/locks/.test/{default => common}/deploy.test.bicep (100%) diff --git a/modules/Microsoft.Authorization/locks/.test/default/deploy.test.bicep b/modules/Microsoft.Authorization/locks/.test/common/deploy.test.bicep similarity index 100% rename from modules/Microsoft.Authorization/locks/.test/default/deploy.test.bicep rename to modules/Microsoft.Authorization/locks/.test/common/deploy.test.bicep diff --git a/modules/Microsoft.Authorization/locks/readme.md b/modules/Microsoft.Authorization/locks/readme.md index 63f95d8f14..b04758e06d 100644 --- a/modules/Microsoft.Authorization/locks/readme.md +++ b/modules/Microsoft.Authorization/locks/readme.md @@ -51,14 +51,14 @@ The following module usage examples are retrieved from the content of the files >**Note**: The name of each example is based on the name of the file from which it is taken. >**Note**: Each example lists all the required parameters first, followed by the rest - each in alphabetical order. -

Example 1: Default

+

Example 1: Common

via Bicep module ```bicep -module Locks './Microsoft.Authorization/Locks/deploy.bicep' = { +module locks './Microsoft.Authorization/locks/deploy.bicep' = { name: '${uniqueString(deployment().name)}-test-aldef' params: { // Required parameters From 76ac4e04cdb83bcd6b8af41433e5b444eb27924f Mon Sep 17 00:00:00 2001 From: MrMCake Date: Fri, 9 Sep 2022 12:49:08 +0200 Subject: [PATCH 07/10] Update to latest --- .../locks/.test/common/deploy.test.bicep | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/Microsoft.Authorization/locks/.test/common/deploy.test.bicep b/modules/Microsoft.Authorization/locks/.test/common/deploy.test.bicep index b5d1fdf8b3..c19cb822cb 100644 --- a/modules/Microsoft.Authorization/locks/.test/common/deploy.test.bicep +++ b/modules/Microsoft.Authorization/locks/.test/common/deploy.test.bicep @@ -10,8 +10,8 @@ param resourceGroupName string = 'ms.authorization.locks-${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 = 'aldef' +@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 = 'alcom' // =========== // // Deployments // From 8de2fa1e77c2e00f92bfc7b32701b0aab77e7a70 Mon Sep 17 00:00:00 2001 From: MrMCake Date: Fri, 9 Sep 2022 13:02:00 +0200 Subject: [PATCH 08/10] Update to latest --- .../locks/.test/common/deploy.test.bicep | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/Microsoft.Authorization/locks/.test/common/deploy.test.bicep b/modules/Microsoft.Authorization/locks/.test/common/deploy.test.bicep index c19cb822cb..6c1b4e551e 100644 --- a/modules/Microsoft.Authorization/locks/.test/common/deploy.test.bicep +++ b/modules/Microsoft.Authorization/locks/.test/common/deploy.test.bicep @@ -3,14 +3,14 @@ targetScope = 'subscription' // ========== // // Parameters // // ========== // -@description('Optional. The name of the resource group to deploy for a testing purposes') +@description('Optional. The name of the resource group to deploy for a testing purposes.') @maxLength(80) param resourceGroupName string = 'ms.authorization.locks-${serviceShort}-rg' -@description('Optional. The location to deploy resources to') +@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') +@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 = 'alcom' // =========== // From e842f6354a59f5fe039ff728b050150a42e0ae58 Mon Sep 17 00:00:00 2001 From: MrMCake Date: Fri, 9 Sep 2022 13:24:04 +0200 Subject: [PATCH 09/10] Update to latest --- modules/Microsoft.Authorization/locks/readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/Microsoft.Authorization/locks/readme.md b/modules/Microsoft.Authorization/locks/readme.md index 3c633d51dd..8d25b60f2c 100644 --- a/modules/Microsoft.Authorization/locks/readme.md +++ b/modules/Microsoft.Authorization/locks/readme.md @@ -60,7 +60,7 @@ The following module usage examples are retrieved from the content of the files ```bicep module locks './Microsoft.Authorization/locks/deploy.bicep' = { - name: '${uniqueString(deployment().name)}-test-aldef' + name: '${uniqueString(deployment().name)}-test-alcom' params: { // Required parameters level: 'CanNotDelete' From 22669f5feb79c148f63e96bc31e32c632cb0db18 Mon Sep 17 00:00:00 2001 From: MrMCake Date: Sun, 18 Sep 2022 22:59:29 +0200 Subject: [PATCH 10/10] Update to latest --- .../locks/.test/common/deploy.test.bicep | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/Microsoft.Authorization/locks/.test/common/deploy.test.bicep b/modules/Microsoft.Authorization/locks/.test/common/deploy.test.bicep index 6c1b4e551e..6509778d79 100644 --- a/modules/Microsoft.Authorization/locks/.test/common/deploy.test.bicep +++ b/modules/Microsoft.Authorization/locks/.test/common/deploy.test.bicep @@ -3,7 +3,7 @@ targetScope = 'subscription' // ========== // // Parameters // // ========== // -@description('Optional. The name of the resource group to deploy for a testing purposes.') +@description('Optional. The name of the resource group to deploy for testing purposes.') @maxLength(80) param resourceGroupName string = 'ms.authorization.locks-${serviceShort}-rg'