From 3411b81239d2fa44ee42109f3f26ebb635f40e4c Mon Sep 17 00:00:00 2001 From: MrMCake Date: Wed, 21 Sep 2022 20:52:49 +0200 Subject: [PATCH 1/2] Updated HealthBots to new dependencies approach & Updated readme script to deal better with empty lines --- .github/workflows/ms.healthbot.healthbots.yml | 3 +- .../.test/common/dependencies.bicep | 14 +++++ .../healthBots/.test/common/deploy.test.bicep | 54 +++++++++++++++++++ .../healthBots/.test/min/deploy.test.bicep | 37 +++++++++++++ .../healthBots/.test/parameters.json | 22 -------- .../Microsoft.HealthBot/healthBots/readme.md | 51 +++++++++++++++--- .../staticValidation/module.tests.ps1 | 8 ++- 7 files changed, 158 insertions(+), 31 deletions(-) create mode 100644 modules/Microsoft.HealthBot/healthBots/.test/common/dependencies.bicep create mode 100644 modules/Microsoft.HealthBot/healthBots/.test/common/deploy.test.bicep create mode 100644 modules/Microsoft.HealthBot/healthBots/.test/min/deploy.test.bicep delete mode 100644 modules/Microsoft.HealthBot/healthBots/.test/parameters.json diff --git a/.github/workflows/ms.healthbot.healthbots.yml b/.github/workflows/ms.healthbot.healthbots.yml index 85fe41f8a0..1c66933056 100644 --- a/.github/workflows/ms.healthbot.healthbots.yml +++ b/.github/workflows/ms.healthbot.healthbots.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.HealthBot/healthBots/.test/common/dependencies.bicep b/modules/Microsoft.HealthBot/healthBots/.test/common/dependencies.bicep new file mode 100644 index 0000000000..7371d4437b --- /dev/null +++ b/modules/Microsoft.HealthBot/healthBots/.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.HealthBot/healthBots/.test/common/deploy.test.bicep b/modules/Microsoft.HealthBot/healthBots/.test/common/deploy.test.bicep new file mode 100644 index 0000000000..55859d5981 --- /dev/null +++ b/modules/Microsoft.HealthBot/healthBots/.test/common/deploy.test.bicep @@ -0,0 +1,54 @@ +targetScope = 'subscription' + +// ========== // +// Parameters // +// ========== // +@description('Optional. The name of the resource group to deploy for testing purposes') +@maxLength(90) +param resourceGroupName string = 'ms.healthbot.healthbots-${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 = 'hbhbcom' + +// =========== // +// 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' = { + scope: resourceGroup + name: '${uniqueString(deployment().name)}-test-${serviceShort}' + params: { + name: '<>${serviceShort}001' + lock: 'CanNotDelete' + roleAssignments: [ + { + principalIds: [ + resourceGroupResources.outputs.managedIdentityPrincipalId + ] + roleDefinitionIdOrName: 'Reader' + } + ] + } +} diff --git a/modules/Microsoft.HealthBot/healthBots/.test/min/deploy.test.bicep b/modules/Microsoft.HealthBot/healthBots/.test/min/deploy.test.bicep new file mode 100644 index 0000000000..2849eaf958 --- /dev/null +++ b/modules/Microsoft.HealthBot/healthBots/.test/min/deploy.test.bicep @@ -0,0 +1,37 @@ +targetScope = 'subscription' + +// ========== // +// Parameters // +// ========== // +@description('Optional. The name of the resource group to deploy for testing purposes') +@maxLength(90) +param resourceGroupName string = 'ms.healthbot.healthbots-${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 = 'hbhbmin' + +// =========== // +// Deployments // +// =========== // + +// General resources +// ================= +resource resourceGroup 'Microsoft.Resources/resourceGroups@2021-04-01' = { + name: resourceGroupName + location: location +} + +// ============== // +// Test Execution // +// ============== // + +module testDeployment '../../deploy.bicep' = { + scope: resourceGroup + name: '${uniqueString(deployment().name)}-test-${serviceShort}' + params: { + name: '<>${serviceShort}001' + } +} diff --git a/modules/Microsoft.HealthBot/healthBots/.test/parameters.json b/modules/Microsoft.HealthBot/healthBots/.test/parameters.json deleted file mode 100644 index fef2b742de..0000000000 --- a/modules/Microsoft.HealthBot/healthBots/.test/parameters.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", - "contentVersion": "1.0.0.0", - "parameters": { - "name": { - "value": "<>-az-ahb-x-001" - }, - "lock": { - "value": "CanNotDelete" - }, - "roleAssignments": { - "value": [ - { - "roleDefinitionIdOrName": "Reader", - "principalIds": [ - "<>" - ] - } - ] - } - } -} diff --git a/modules/Microsoft.HealthBot/healthBots/readme.md b/modules/Microsoft.HealthBot/healthBots/readme.md index b6321201fd..bb3be3cff9 100644 --- a/modules/Microsoft.HealthBot/healthBots/readme.md +++ b/modules/Microsoft.HealthBot/healthBots/readme.md @@ -21,11 +21,13 @@ This module deploys an Azure Health Bot. ## Parameters **Required parameters** + | Parameter Name | Type | Description | | :-- | :-- | :-- | | `name` | string | Name of the resource. | **Optional parameters** + | Parameter Name | Type | Default Value | Allowed Values | Description | | :-- | :-- | :-- | :-- | :-- | | `enableDefaultTelemetry` | bool | `True` | | Enable telemetry via the Customer Usage Attribution ID (GUID). | @@ -156,7 +158,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

@@ -164,16 +166,16 @@ The following module usage examples are retrieved from the content of the files ```bicep module healthBots './Microsoft.HealthBot/healthBots/deploy.bicep' = { - name: '${uniqueString(deployment().name)}-HealthBots' + name: '${uniqueString(deployment().name)}-test-hbhbcom' params: { // Required parameters - name: '<>-az-ahb-x-001' + name: '<>hbhbcom001' // Non-required parameters lock: 'CanNotDelete' roleAssignments: [ { principalIds: [ - '<>' + '' ] roleDefinitionIdOrName: 'Reader' } @@ -196,7 +198,7 @@ module healthBots './Microsoft.HealthBot/healthBots/deploy.bicep' = { "parameters": { // Required parameters "name": { - "value": "<>-az-ahb-x-001" + "value": "<>hbhbcom001" }, // Non-required parameters "lock": { @@ -206,7 +208,7 @@ module healthBots './Microsoft.HealthBot/healthBots/deploy.bicep' = { "value": [ { "principalIds": [ - "<>" + "" ], "roleDefinitionIdOrName": "Reader" } @@ -218,3 +220,40 @@ module healthBots './Microsoft.HealthBot/healthBots/deploy.bicep' = {

+ +

Example 2: Min

+ +
+ +via Bicep module + +```bicep +module healthBots './Microsoft.HealthBot/healthBots/deploy.bicep' = { + name: '${uniqueString(deployment().name)}-test-hbhbmin' + params: { + name: '<>hbhbmin001' + } +} +``` + +
+

+ +

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

diff --git a/utilities/pipelines/staticValidation/module.tests.ps1 b/utilities/pipelines/staticValidation/module.tests.ps1 index 5148281387..b005759b0d 100644 --- a/utilities/pipelines/staticValidation/module.tests.ps1 +++ b/utilities/pipelines/staticValidation/module.tests.ps1 @@ -342,7 +342,13 @@ Describe 'Readme tests' -Tag Readme { $expectedColumnsInOrder += @('Description') $readMeCategoryIndex = $readMeContent | Select-String -Pattern "^\*\*$paramCategory parameters\*\*$" | ForEach-Object { $_.LineNumber } - $readmeCategoryColumns = ($readMeContent[$readMeCategoryIndex] -split '\|') | ForEach-Object { $_.Trim() } | Where-Object { -not [String]::IsNullOrEmpty($_) } + + $tableStartIndex = $readMeCategoryIndex + while ($readMeContent[$tableStartIndex] -notlike '*|*' -and -not ($tableStartIndex -ge $readMeContent.count)) { + $tableStartIndex++ + } + + $readmeCategoryColumns = ($readMeContent[$tableStartIndex] -split '\|') | ForEach-Object { $_.Trim() } | Where-Object { -not [String]::IsNullOrEmpty($_) } $readmeCategoryColumns | Should -Be $expectedColumnsInOrder } From f5006109836642cbd6dbdb84cef68857a74c6bdc Mon Sep 17 00:00:00 2001 From: MrMCake Date: Wed, 5 Oct 2022 14:52:57 +0200 Subject: [PATCH 2/2] Update to latest --- .../healthBots/.test/common/deploy.test.bicep | 6 +++--- .../healthBots/.test/min/deploy.test.bicep | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/Microsoft.HealthBot/healthBots/.test/common/deploy.test.bicep b/modules/Microsoft.HealthBot/healthBots/.test/common/deploy.test.bicep index 55859d5981..d3a2a939a4 100644 --- a/modules/Microsoft.HealthBot/healthBots/.test/common/deploy.test.bicep +++ b/modules/Microsoft.HealthBot/healthBots/.test/common/deploy.test.bicep @@ -3,14 +3,14 @@ targetScope = 'subscription' // ========== // // Parameters // // ========== // -@description('Optional. The name of the resource group to deploy for testing purposes') +@description('Optional. The name of the resource group to deploy for testing purposes.') @maxLength(90) param resourceGroupName string = 'ms.healthbot.healthbots-${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 = 'hbhbcom' // =========== // diff --git a/modules/Microsoft.HealthBot/healthBots/.test/min/deploy.test.bicep b/modules/Microsoft.HealthBot/healthBots/.test/min/deploy.test.bicep index 2849eaf958..3594e54c60 100644 --- a/modules/Microsoft.HealthBot/healthBots/.test/min/deploy.test.bicep +++ b/modules/Microsoft.HealthBot/healthBots/.test/min/deploy.test.bicep @@ -3,14 +3,14 @@ targetScope = 'subscription' // ========== // // Parameters // // ========== // -@description('Optional. The name of the resource group to deploy for testing purposes') +@description('Optional. The name of the resource group to deploy for testing purposes.') @maxLength(90) param resourceGroupName string = 'ms.healthbot.healthbots-${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 = 'hbhbmin' // =========== //