From 79271955bc1072dd42ab54ad2654a951ee4a0398 Mon Sep 17 00:00:00 2001 From: MrMCake Date: Wed, 21 Sep 2022 21:50:37 +0200 Subject: [PATCH 1/8] Updated Insight ActionGroups to new dependencies approach --- .../workflows/ms.insights.actiongroups.yml | 3 +- .../.test/common/dependencies.bicep | 14 ++++ .../.test/common/deploy.test.bicep | 73 +++++++++++++++++++ .../actionGroups/.test/min/deploy.test.bicep | 38 ++++++++++ .../actionGroups/.test/parameters.json | 45 ------------ .../Microsoft.Insights/actionGroups/readme.md | 61 ++++++++++++++-- .../staticValidation/module.tests.ps1 | 8 +- 7 files changed, 186 insertions(+), 56 deletions(-) create mode 100644 modules/Microsoft.Insights/actionGroups/.test/common/dependencies.bicep create mode 100644 modules/Microsoft.Insights/actionGroups/.test/common/deploy.test.bicep create mode 100644 modules/Microsoft.Insights/actionGroups/.test/min/deploy.test.bicep delete mode 100644 modules/Microsoft.Insights/actionGroups/.test/parameters.json diff --git a/.github/workflows/ms.insights.actiongroups.yml b/.github/workflows/ms.insights.actiongroups.yml index 34b2279df5..32c5bd8483 100644 --- a/.github/workflows/ms.insights.actiongroups.yml +++ b/.github/workflows/ms.insights.actiongroups.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.Insights/actionGroups/.test/common/dependencies.bicep b/modules/Microsoft.Insights/actionGroups/.test/common/dependencies.bicep new file mode 100644 index 0000000000..7371d4437b --- /dev/null +++ b/modules/Microsoft.Insights/actionGroups/.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.Insights/actionGroups/.test/common/deploy.test.bicep b/modules/Microsoft.Insights/actionGroups/.test/common/deploy.test.bicep new file mode 100644 index 0000000000..ea3374c1c4 --- /dev/null +++ b/modules/Microsoft.Insights/actionGroups/.test/common/deploy.test.bicep @@ -0,0 +1,73 @@ +targetScope = 'subscription' + +// ========== // +// Parameters // +// ========== // +@description('Optional. The name of the resource group to deploy for testing purposes') +@maxLength(90) +param resourceGroupName string = 'ms.insights.actiongroups-${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 = 'iagcom' + +// =========== // +// 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' + groupShortName: 'ag${serviceShort}001' + emailReceivers: [ + { + emailAddress: 'test.user@testcompany.com' + name: 'TestUser_-EmailAction-' + useCommonAlertSchema: true + } + { + emailAddress: 'test.user2@testcompany.com' + name: 'TestUser2' + useCommonAlertSchema: true + } + ] + roleAssignments: [ + { + principalIds: [ + resourceGroupResources.outputs.managedIdentityPrincipalId + ] + roleDefinitionIdOrName: 'Reader' + } + ] + smsReceivers: [ + { + countryCode: '1' + name: 'TestUser_-SMSAction-' + phoneNumber: '2345678901' + } + ] + } +} diff --git a/modules/Microsoft.Insights/actionGroups/.test/min/deploy.test.bicep b/modules/Microsoft.Insights/actionGroups/.test/min/deploy.test.bicep new file mode 100644 index 0000000000..7f3f15e1b9 --- /dev/null +++ b/modules/Microsoft.Insights/actionGroups/.test/min/deploy.test.bicep @@ -0,0 +1,38 @@ +targetScope = 'subscription' + +// ========== // +// Parameters // +// ========== // +@description('Optional. The name of the resource group to deploy for testing purposes') +@maxLength(90) +param resourceGroupName string = 'ms.insights.actiongroups-${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 = 'iagmin' + +// =========== // +// 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' + groupShortName: 'ag${serviceShort}001' + } +} diff --git a/modules/Microsoft.Insights/actionGroups/.test/parameters.json b/modules/Microsoft.Insights/actionGroups/.test/parameters.json deleted file mode 100644 index 32c9e76062..0000000000 --- a/modules/Microsoft.Insights/actionGroups/.test/parameters.json +++ /dev/null @@ -1,45 +0,0 @@ -{ - "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", - "contentVersion": "1.0.0.0", - "parameters": { - "name": { - "value": "<>-az-ag-x-001" - }, - "groupShortName": { - "value": "azagweux001" - }, - "roleAssignments": { - "value": [ - { - "roleDefinitionIdOrName": "Reader", - "principalIds": [ - "<>" - ] - } - ] - }, - "emailReceivers": { - "value": [ - { - "name": "TestUser_-EmailAction-", - "emailAddress": "test.user@testcompany.com", - "useCommonAlertSchema": true - }, - { - "name": "TestUser2", - "emailAddress": "test.user2@testcompany.com", - "useCommonAlertSchema": true - } - ] - }, - "smsReceivers": { - "value": [ - { - "name": "TestUser_-SMSAction-", - "countryCode": "1", - "phoneNumber": "2345678901" - } - ] - } - } -} diff --git a/modules/Microsoft.Insights/actionGroups/readme.md b/modules/Microsoft.Insights/actionGroups/readme.md index 21b0ddd97f..24614d4170 100644 --- a/modules/Microsoft.Insights/actionGroups/readme.md +++ b/modules/Microsoft.Insights/actionGroups/readme.md @@ -20,12 +20,14 @@ This module deploys an Action Group. ## Parameters **Required parameters** + | Parameter Name | Type | Description | | :-- | :-- | :-- | | `groupShortName` | string | The short name of the action group. | | `name` | string | The name of the action group. | **Optional parameters** + | Parameter Name | Type | Default Value | Description | | :-- | :-- | :-- | :-- | | `armRoleReceivers` | array | `[]` | The list of ARM role receivers that are part of this action group. Roles are Azure RBAC roles and only built-in roles are supported. | @@ -242,7 +244,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

@@ -250,11 +252,11 @@ The following module usage examples are retrieved from the content of the files ```bicep module actionGroups './Microsoft.Insights/actionGroups/deploy.bicep' = { - name: '${uniqueString(deployment().name)}-ActionGroups' + name: '${uniqueString(deployment().name)}-test-iagcom' params: { // Required parameters - groupShortName: 'azagweux001' - name: '<>-az-ag-x-001' + groupShortName: 'agiagcom001' + name: '<>iagcom001' // Non-required parameters emailReceivers: [ { @@ -271,7 +273,7 @@ module actionGroups './Microsoft.Insights/actionGroups/deploy.bicep' = { roleAssignments: [ { principalIds: [ - '<>' + '' ] roleDefinitionIdOrName: 'Reader' } @@ -301,10 +303,10 @@ module actionGroups './Microsoft.Insights/actionGroups/deploy.bicep' = { "parameters": { // Required parameters "groupShortName": { - "value": "azagweux001" + "value": "agiagcom001" }, "name": { - "value": "<>-az-ag-x-001" + "value": "<>iagcom001" }, // Non-required parameters "emailReceivers": { @@ -325,7 +327,7 @@ module actionGroups './Microsoft.Insights/actionGroups/deploy.bicep' = { "value": [ { "principalIds": [ - "<>" + "" ], "roleDefinitionIdOrName": "Reader" } @@ -346,3 +348,46 @@ module actionGroups './Microsoft.Insights/actionGroups/deploy.bicep' = {

+ +

Example 2: Min

+ +
+ +via Bicep module + +```bicep +module actionGroups './Microsoft.Insights/actionGroups/deploy.bicep' = { + name: '${uniqueString(deployment().name)}-test-iagmin' + params: { + // Required parameters + groupShortName: 'agiagmin001' + name: '<>iagmin001' + } +} +``` + +
+

+ +

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

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 c5bb43d543bbead96a1cfb1e7475b148b5c0f561 Mon Sep 17 00:00:00 2001 From: Alexander Sehr Date: Wed, 5 Oct 2022 14:47:08 +0200 Subject: [PATCH 2/8] Update modules/Microsoft.Insights/actionGroups/.test/common/deploy.test.bicep Co-authored-by: Rainer Halanek <61878316+rahalan@users.noreply.github.com> --- .../actionGroups/.test/common/deploy.test.bicep | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/Microsoft.Insights/actionGroups/.test/common/deploy.test.bicep b/modules/Microsoft.Insights/actionGroups/.test/common/deploy.test.bicep index ea3374c1c4..5f9303126f 100644 --- a/modules/Microsoft.Insights/actionGroups/.test/common/deploy.test.bicep +++ b/modules/Microsoft.Insights/actionGroups/.test/common/deploy.test.bicep @@ -10,7 +10,7 @@ param resourceGroupName string = 'ms.insights.actiongroups-${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') +@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 = 'iagcom' // =========== // From 2d2a8da4c691f734e0ea10059f9dec6adf817b1c Mon Sep 17 00:00:00 2001 From: Alexander Sehr Date: Wed, 5 Oct 2022 14:47:12 +0200 Subject: [PATCH 3/8] Update modules/Microsoft.Insights/actionGroups/.test/common/deploy.test.bicep Co-authored-by: Rainer Halanek <61878316+rahalan@users.noreply.github.com> --- .../actionGroups/.test/common/deploy.test.bicep | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/Microsoft.Insights/actionGroups/.test/common/deploy.test.bicep b/modules/Microsoft.Insights/actionGroups/.test/common/deploy.test.bicep index 5f9303126f..d0696266c2 100644 --- a/modules/Microsoft.Insights/actionGroups/.test/common/deploy.test.bicep +++ b/modules/Microsoft.Insights/actionGroups/.test/common/deploy.test.bicep @@ -3,7 +3,7 @@ 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.insights.actiongroups-${serviceShort}-rg' From ce3549f7cc6aae04235eeb6d32e82613bf8b9f83 Mon Sep 17 00:00:00 2001 From: Alexander Sehr Date: Wed, 5 Oct 2022 14:47:18 +0200 Subject: [PATCH 4/8] Update modules/Microsoft.Insights/actionGroups/.test/common/deploy.test.bicep Co-authored-by: Rainer Halanek <61878316+rahalan@users.noreply.github.com> --- .../actionGroups/.test/common/deploy.test.bicep | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/Microsoft.Insights/actionGroups/.test/common/deploy.test.bicep b/modules/Microsoft.Insights/actionGroups/.test/common/deploy.test.bicep index d0696266c2..102d0d23c6 100644 --- a/modules/Microsoft.Insights/actionGroups/.test/common/deploy.test.bicep +++ b/modules/Microsoft.Insights/actionGroups/.test/common/deploy.test.bicep @@ -7,7 +7,7 @@ targetScope = 'subscription' @maxLength(90) param resourceGroupName string = 'ms.insights.actiongroups-${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.') From 1f269cadf889ff39b0141fccec642d2fe09c030f Mon Sep 17 00:00:00 2001 From: Alexander Sehr Date: Wed, 5 Oct 2022 14:47:22 +0200 Subject: [PATCH 5/8] Update modules/Microsoft.Insights/actionGroups/.test/min/deploy.test.bicep Co-authored-by: Rainer Halanek <61878316+rahalan@users.noreply.github.com> --- .../Microsoft.Insights/actionGroups/.test/min/deploy.test.bicep | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/Microsoft.Insights/actionGroups/.test/min/deploy.test.bicep b/modules/Microsoft.Insights/actionGroups/.test/min/deploy.test.bicep index 7f3f15e1b9..80031a485e 100644 --- a/modules/Microsoft.Insights/actionGroups/.test/min/deploy.test.bicep +++ b/modules/Microsoft.Insights/actionGroups/.test/min/deploy.test.bicep @@ -3,7 +3,7 @@ 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.insights.actiongroups-${serviceShort}-rg' From 58ba76f648d438ad552afdda8993c6c59b76eb51 Mon Sep 17 00:00:00 2001 From: Alexander Sehr Date: Wed, 5 Oct 2022 14:47:28 +0200 Subject: [PATCH 6/8] Update modules/Microsoft.Insights/actionGroups/.test/min/deploy.test.bicep Co-authored-by: Rainer Halanek <61878316+rahalan@users.noreply.github.com> --- .../Microsoft.Insights/actionGroups/.test/min/deploy.test.bicep | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/Microsoft.Insights/actionGroups/.test/min/deploy.test.bicep b/modules/Microsoft.Insights/actionGroups/.test/min/deploy.test.bicep index 80031a485e..203eae7748 100644 --- a/modules/Microsoft.Insights/actionGroups/.test/min/deploy.test.bicep +++ b/modules/Microsoft.Insights/actionGroups/.test/min/deploy.test.bicep @@ -7,7 +7,7 @@ targetScope = 'subscription' @maxLength(90) param resourceGroupName string = 'ms.insights.actiongroups-${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') From 4f77b29959ae6e57a48f5bec10be473e4a069348 Mon Sep 17 00:00:00 2001 From: Alexander Sehr Date: Wed, 5 Oct 2022 14:47:36 +0200 Subject: [PATCH 7/8] Update modules/Microsoft.Insights/actionGroups/.test/min/deploy.test.bicep Co-authored-by: Rainer Halanek <61878316+rahalan@users.noreply.github.com> --- .../Microsoft.Insights/actionGroups/.test/min/deploy.test.bicep | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/Microsoft.Insights/actionGroups/.test/min/deploy.test.bicep b/modules/Microsoft.Insights/actionGroups/.test/min/deploy.test.bicep index 203eae7748..fef1c58e1c 100644 --- a/modules/Microsoft.Insights/actionGroups/.test/min/deploy.test.bicep +++ b/modules/Microsoft.Insights/actionGroups/.test/min/deploy.test.bicep @@ -10,7 +10,7 @@ param resourceGroupName string = 'ms.insights.actiongroups-${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') +@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 = 'iagmin' // =========== // From 3ef5463fc54c77362ad81d57672526f063bf6fbb Mon Sep 17 00:00:00 2001 From: MrMCake Date: Wed, 5 Oct 2022 14:50:30 +0200 Subject: [PATCH 8/8] Update to latest --- utilities/pipelines/staticValidation/module.tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utilities/pipelines/staticValidation/module.tests.ps1 b/utilities/pipelines/staticValidation/module.tests.ps1 index 1fe2cb1057..d6fa0761f0 100644 --- a/utilities/pipelines/staticValidation/module.tests.ps1 +++ b/utilities/pipelines/staticValidation/module.tests.ps1 @@ -342,6 +342,7 @@ Describe 'Readme tests' -Tag Readme { $expectedColumnsInOrder += @('Description') $readMeCategoryIndex = $readMeContent | Select-String -Pattern "^\*\*$paramCategory parameters\*\*$" | ForEach-Object { $_.LineNumber } + $tableStartIndex = $readMeCategoryIndex while ($readMeContent[$tableStartIndex] -notlike '*|*' -and -not ($tableStartIndex -ge $readMeContent.count)) { $tableStartIndex++ @@ -1318,4 +1319,3 @@ Describe "API version tests [All apiVersions in the template should be 'recent'] ($approvedApiVersions | Select-Object -Unique) | Should -Contain $TargetApi } } -}