From d16a64bf0dc4e431295f58a938d564d09b19021b Mon Sep 17 00:00:00 2001 From: MrMCake Date: Wed, 21 Sep 2022 21:57:38 +0200 Subject: [PATCH 1/7] Updated Insight Components to new dependencies approach --- .github/workflows/ms.insights.components.yml | 3 +- .../.test/common/dependencies.bicep | 24 ++++++++ .../components/.test/common/deploy.test.bicep | 55 +++++++++++++++++ .../components/.test/min/dependencies.bicep | 13 ++++ .../components/.test/min/deploy.test.bicep | 46 ++++++++++++++ .../components/.test/parameters.json | 22 ------- .../Microsoft.Insights/components/readme.md | 61 ++++++++++++++++--- .../staticValidation/module.tests.ps1 | 8 ++- 8 files changed, 199 insertions(+), 33 deletions(-) create mode 100644 modules/Microsoft.Insights/components/.test/common/dependencies.bicep create mode 100644 modules/Microsoft.Insights/components/.test/common/deploy.test.bicep create mode 100644 modules/Microsoft.Insights/components/.test/min/dependencies.bicep create mode 100644 modules/Microsoft.Insights/components/.test/min/deploy.test.bicep delete mode 100644 modules/Microsoft.Insights/components/.test/parameters.json diff --git a/.github/workflows/ms.insights.components.yml b/.github/workflows/ms.insights.components.yml index 032cae919c..f166a3cb72 100644 --- a/.github/workflows/ms.insights.components.yml +++ b/.github/workflows/ms.insights.components.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/components/.test/common/dependencies.bicep b/modules/Microsoft.Insights/components/.test/common/dependencies.bicep new file mode 100644 index 0000000000..9e9a8f2510 --- /dev/null +++ b/modules/Microsoft.Insights/components/.test/common/dependencies.bicep @@ -0,0 +1,24 @@ +@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 + +@description('Required. The name of the Log Analytics Workspace to create.') +param logAnalyticsWorkspaceName string + +resource managedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2018-11-30' = { + name: managedIdentityName + location: location +} + +resource logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2021-06-01' = { + name: logAnalyticsWorkspaceName + location: location +} + +@description('The principal ID of the created Managed Identity.') +output managedIdentityPrincipalId string = managedIdentity.properties.principalId + +@description('The resource ID of the created Log Analytics Workspace.') +output logAnalyticsWorkspaceResourceId string = logAnalyticsWorkspace.id diff --git a/modules/Microsoft.Insights/components/.test/common/deploy.test.bicep b/modules/Microsoft.Insights/components/.test/common/deploy.test.bicep new file mode 100644 index 0000000000..f458c31aad --- /dev/null +++ b/modules/Microsoft.Insights/components/.test/common/deploy.test.bicep @@ -0,0 +1,55 @@ +targetScope = 'subscription' + +// ========== // +// Parameters // +// ========== // +@description('Optional. The name of the resource group to deploy for testing purposes') +@maxLength(90) +param resourceGroupName string = 'ms.insights.components-${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 = 'iccom' + +// =========== // +// 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}' + logAnalyticsWorkspaceName: 'dep-<>-law-${serviceShort}' + } +} + +// ============== // +// Test Execution // +// ============== // + +module testDeployment '../../deploy.bicep' = { + scope: resourceGroup + name: '${uniqueString(deployment().name)}-test-${serviceShort}' + params: { + name: '<>${serviceShort}001' + workspaceResourceId: resourceGroupResources.outputs.logAnalyticsWorkspaceResourceId + roleAssignments: [ + { + principalIds: [ + resourceGroupResources.outputs.managedIdentityPrincipalId + ] + roleDefinitionIdOrName: 'Reader' + } + ] + } +} diff --git a/modules/Microsoft.Insights/components/.test/min/dependencies.bicep b/modules/Microsoft.Insights/components/.test/min/dependencies.bicep new file mode 100644 index 0000000000..cc24476629 --- /dev/null +++ b/modules/Microsoft.Insights/components/.test/min/dependencies.bicep @@ -0,0 +1,13 @@ +@description('Optional. The location to deploy to.') +param location string = resourceGroup().location + +@description('Required. The name of the Log Analytics Workspace to create.') +param logAnalyticsWorkspaceName string + +resource logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2021-06-01' = { + name: logAnalyticsWorkspaceName + location: location +} + +@description('The resource ID of the created Log Analytics Workspace.') +output logAnalyticsWorkspaceResourceId string = logAnalyticsWorkspace.id diff --git a/modules/Microsoft.Insights/components/.test/min/deploy.test.bicep b/modules/Microsoft.Insights/components/.test/min/deploy.test.bicep new file mode 100644 index 0000000000..95db27dd4a --- /dev/null +++ b/modules/Microsoft.Insights/components/.test/min/deploy.test.bicep @@ -0,0 +1,46 @@ +targetScope = 'subscription' + +// ========== // +// Parameters // +// ========== // +@description('Optional. The name of the resource group to deploy for testing purposes') +@maxLength(90) +param resourceGroupName string = 'ms.insights.components-${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 = 'icmin' + +// =========== // +// 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: { + logAnalyticsWorkspaceName: 'dep-<>-law-${serviceShort}' + } +} + +// ============== // +// Test Execution // +// ============== // + +module testDeployment '../../deploy.bicep' = { + scope: resourceGroup + name: '${uniqueString(deployment().name)}-test-${serviceShort}' + params: { + name: '<>${serviceShort}001' + workspaceResourceId: resourceGroupResources.outputs.logAnalyticsWorkspaceResourceId + } +} diff --git a/modules/Microsoft.Insights/components/.test/parameters.json b/modules/Microsoft.Insights/components/.test/parameters.json deleted file mode 100644 index 636d9f6c7d..0000000000 --- a/modules/Microsoft.Insights/components/.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-appi-x-001" - }, - "workspaceResourceId": { - "value": "/subscriptions/<>/resourcegroups/validation-rg/providers/microsoft.operationalinsights/workspaces/adp-<>-az-law-appi-001" - }, - "roleAssignments": { - "value": [ - { - "roleDefinitionIdOrName": "Reader", - "principalIds": [ - "<>" - ] - } - ] - } - } -} diff --git a/modules/Microsoft.Insights/components/readme.md b/modules/Microsoft.Insights/components/readme.md index 6677bca0c8..af11d5e063 100644 --- a/modules/Microsoft.Insights/components/readme.md +++ b/modules/Microsoft.Insights/components/readme.md @@ -18,12 +18,14 @@ ## Parameters **Required parameters** + | Parameter Name | Type | Description | | :-- | :-- | :-- | | `name` | string | Name of the Application Insights. | | `workspaceResourceId` | string | Resource ID of the log analytics workspace which the data will be ingested to. This property is required to create an application with this API version. Applications from older versions will not have this property. | **Optional parameters** + | Parameter Name | Type | Default Value | Allowed Values | Description | | :-- | :-- | :-- | :-- | :-- | | `appInsightsType` | string | `'web'` | `[other, web]` | Application type. | @@ -160,7 +162,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

@@ -168,16 +170,16 @@ The following module usage examples are retrieved from the content of the files ```bicep module components './Microsoft.Insights/components/deploy.bicep' = { - name: '${uniqueString(deployment().name)}-Components' + name: '${uniqueString(deployment().name)}-test-iccom' params: { // Required parameters - name: '<>-az-appi-x-001' - workspaceResourceId: '/subscriptions/<>/resourcegroups/validation-rg/providers/microsoft.operationalinsights/workspaces/adp-<>-az-law-appi-001' + name: '<>iccom001' + workspaceResourceId: '' // Non-required parameters roleAssignments: [ { principalIds: [ - '<>' + '' ] roleDefinitionIdOrName: 'Reader' } @@ -200,17 +202,17 @@ module components './Microsoft.Insights/components/deploy.bicep' = { "parameters": { // Required parameters "name": { - "value": "<>-az-appi-x-001" + "value": "<>iccom001" }, "workspaceResourceId": { - "value": "/subscriptions/<>/resourcegroups/validation-rg/providers/microsoft.operationalinsights/workspaces/adp-<>-az-law-appi-001" + "value": "" }, // Non-required parameters "roleAssignments": { "value": [ { "principalIds": [ - "<>" + "" ], "roleDefinitionIdOrName": "Reader" } @@ -222,3 +224,46 @@ module components './Microsoft.Insights/components/deploy.bicep' = {

+ +

Example 2: Min

+ +
+ +via Bicep module + +```bicep +module components './Microsoft.Insights/components/deploy.bicep' = { + name: '${uniqueString(deployment().name)}-test-icmin' + params: { + // Required parameters + name: '<>icmin001' + workspaceResourceId: '' + } +} +``` + +
+

+ +

+ +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 + "name": { + "value": "<>icmin001" + }, + "workspaceResourceId": { + "value": "" + } + } +} +``` + +
+

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 1533c701fff48a40ff099b51ae3aacb216b2ac78 Mon Sep 17 00:00:00 2001 From: Alexander Sehr Date: Mon, 3 Oct 2022 11:38:06 +0200 Subject: [PATCH 2/7] Update modules/Microsoft.Insights/components/.test/common/deploy.test.bicep Co-authored-by: Erika Gressi <56914614+eriqua@users.noreply.github.com> --- .../components/.test/common/deploy.test.bicep | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/Microsoft.Insights/components/.test/common/deploy.test.bicep b/modules/Microsoft.Insights/components/.test/common/deploy.test.bicep index f458c31aad..a5c208ef28 100644 --- a/modules/Microsoft.Insights/components/.test/common/deploy.test.bicep +++ b/modules/Microsoft.Insights/components/.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.components-${serviceShort}-rg' From b7c335a3c1a95dd7d08eff33538e0b98423493f2 Mon Sep 17 00:00:00 2001 From: Alexander Sehr Date: Mon, 3 Oct 2022 11:38:12 +0200 Subject: [PATCH 3/7] Update modules/Microsoft.Insights/components/.test/common/deploy.test.bicep Co-authored-by: Erika Gressi <56914614+eriqua@users.noreply.github.com> --- .../components/.test/common/deploy.test.bicep | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/Microsoft.Insights/components/.test/common/deploy.test.bicep b/modules/Microsoft.Insights/components/.test/common/deploy.test.bicep index a5c208ef28..cca240f609 100644 --- a/modules/Microsoft.Insights/components/.test/common/deploy.test.bicep +++ b/modules/Microsoft.Insights/components/.test/common/deploy.test.bicep @@ -7,7 +7,7 @@ targetScope = 'subscription' @maxLength(90) param resourceGroupName string = 'ms.insights.components-${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 be16aad80468aac20c276609b47974cba5d0612b Mon Sep 17 00:00:00 2001 From: Alexander Sehr Date: Mon, 3 Oct 2022 11:38:20 +0200 Subject: [PATCH 4/7] Update modules/Microsoft.Insights/components/.test/common/deploy.test.bicep Co-authored-by: Erika Gressi <56914614+eriqua@users.noreply.github.com> --- .../components/.test/common/deploy.test.bicep | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/Microsoft.Insights/components/.test/common/deploy.test.bicep b/modules/Microsoft.Insights/components/.test/common/deploy.test.bicep index cca240f609..f36cffdc8b 100644 --- a/modules/Microsoft.Insights/components/.test/common/deploy.test.bicep +++ b/modules/Microsoft.Insights/components/.test/common/deploy.test.bicep @@ -10,7 +10,7 @@ param resourceGroupName string = 'ms.insights.components-${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 = 'iccom' // =========== // From 21fd711f97db16d5bf77aa7317abd3dcbdfcee69 Mon Sep 17 00:00:00 2001 From: Alexander Sehr Date: Mon, 3 Oct 2022 11:38:27 +0200 Subject: [PATCH 5/7] Update modules/Microsoft.Insights/components/.test/min/deploy.test.bicep Co-authored-by: Erika Gressi <56914614+eriqua@users.noreply.github.com> --- .../Microsoft.Insights/components/.test/min/deploy.test.bicep | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/Microsoft.Insights/components/.test/min/deploy.test.bicep b/modules/Microsoft.Insights/components/.test/min/deploy.test.bicep index 95db27dd4a..e81a51fad2 100644 --- a/modules/Microsoft.Insights/components/.test/min/deploy.test.bicep +++ b/modules/Microsoft.Insights/components/.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.components-${serviceShort}-rg' From 56613580f72638129bf4048e9fda1b26ee5b6349 Mon Sep 17 00:00:00 2001 From: Alexander Sehr Date: Mon, 3 Oct 2022 11:38:35 +0200 Subject: [PATCH 6/7] Update modules/Microsoft.Insights/components/.test/min/deploy.test.bicep Co-authored-by: Erika Gressi <56914614+eriqua@users.noreply.github.com> --- .../Microsoft.Insights/components/.test/min/deploy.test.bicep | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/Microsoft.Insights/components/.test/min/deploy.test.bicep b/modules/Microsoft.Insights/components/.test/min/deploy.test.bicep index e81a51fad2..3d11822e3c 100644 --- a/modules/Microsoft.Insights/components/.test/min/deploy.test.bicep +++ b/modules/Microsoft.Insights/components/.test/min/deploy.test.bicep @@ -7,7 +7,7 @@ targetScope = 'subscription' @maxLength(90) param resourceGroupName string = 'ms.insights.components-${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 70d10a38f2e1e7a6597f8ed243c59d37b088ea37 Mon Sep 17 00:00:00 2001 From: Alexander Sehr Date: Mon, 3 Oct 2022 11:38:41 +0200 Subject: [PATCH 7/7] Update modules/Microsoft.Insights/components/.test/min/deploy.test.bicep Co-authored-by: Erika Gressi <56914614+eriqua@users.noreply.github.com> --- .../Microsoft.Insights/components/.test/min/deploy.test.bicep | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/Microsoft.Insights/components/.test/min/deploy.test.bicep b/modules/Microsoft.Insights/components/.test/min/deploy.test.bicep index 3d11822e3c..df3dfd93cd 100644 --- a/modules/Microsoft.Insights/components/.test/min/deploy.test.bicep +++ b/modules/Microsoft.Insights/components/.test/min/deploy.test.bicep @@ -10,7 +10,7 @@ param resourceGroupName string = 'ms.insights.components-${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 = 'icmin' // =========== //