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..102d0d23c6 --- /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..fef1c58e1c --- /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 513cd09170..24614d4170 100644 --- a/modules/Microsoft.Insights/actionGroups/readme.md +++ b/modules/Microsoft.Insights/actionGroups/readme.md @@ -244,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

@@ -252,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: [ { @@ -273,7 +273,7 @@ module actionGroups './Microsoft.Insights/actionGroups/deploy.bicep' = { roleAssignments: [ { principalIds: [ - '<>' + '' ] roleDefinitionIdOrName: 'Reader' } @@ -303,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": { @@ -327,7 +327,7 @@ module actionGroups './Microsoft.Insights/actionGroups/deploy.bicep' = { "value": [ { "principalIds": [ - "<>" + "" ], "roleDefinitionIdOrName": "Reader" } @@ -348,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" + } + } +} +``` + +
+