From 4e13265deabf39d768a95584f8f9db0798d8376e Mon Sep 17 00:00:00 2001 From: MrMCake Date: Sun, 18 Sep 2022 14:06:53 +0200 Subject: [PATCH 1/4] Updated EventGrid SystemTopics to new dependencies approach --- .../workflows/ms.eventgrid.systemtopics.yml | 3 +- .../.test/common/dependencies.bicep | 28 +++++ .../.test/common/deploy.test.bicep | 76 ++++++++++++ .../systemTopics/.test/min.parameters.json | 15 --- .../systemTopics/.test/min/dependencies.bicep | 17 +++ .../systemTopics/.test/min/deploy.test.bicep | 61 ++++++++++ .../systemTopics/.test/parameters.json | 43 ------- .../systemTopics/readme.md | 112 +++++++++--------- 8 files changed, 239 insertions(+), 116 deletions(-) create mode 100644 modules/Microsoft.EventGrid/systemTopics/.test/common/dependencies.bicep create mode 100644 modules/Microsoft.EventGrid/systemTopics/.test/common/deploy.test.bicep delete mode 100644 modules/Microsoft.EventGrid/systemTopics/.test/min.parameters.json create mode 100644 modules/Microsoft.EventGrid/systemTopics/.test/min/dependencies.bicep create mode 100644 modules/Microsoft.EventGrid/systemTopics/.test/min/deploy.test.bicep delete mode 100644 modules/Microsoft.EventGrid/systemTopics/.test/parameters.json diff --git a/.github/workflows/ms.eventgrid.systemtopics.yml b/.github/workflows/ms.eventgrid.systemtopics.yml index 84a69e853b..4d1bab8ec7 100644 --- a/.github/workflows/ms.eventgrid.systemtopics.yml +++ b/.github/workflows/ms.eventgrid.systemtopics.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.EventGrid/systemTopics/.test/common/dependencies.bicep b/modules/Microsoft.EventGrid/systemTopics/.test/common/dependencies.bicep new file mode 100644 index 0000000000..17482699ce --- /dev/null +++ b/modules/Microsoft.EventGrid/systemTopics/.test/common/dependencies.bicep @@ -0,0 +1,28 @@ +@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 Storage Account to create.') +param storageAccountName string + +resource managedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2018-11-30' = { + name: managedIdentityName + location: location +} + +resource storageAccount 'Microsoft.Storage/storageAccounts@2022-05-01' = { + name: storageAccountName + location: location + sku: { + name: 'Standard_LRS' + } + kind: 'StorageV2' +} + +@description('The principal ID of the created Managed Identity.') +output managedIdentityPrincipalId string = managedIdentity.properties.principalId + +@description('The resource ID of the created Storage Account.') +output storageAccountResourceId string = storageAccount.id diff --git a/modules/Microsoft.EventGrid/systemTopics/.test/common/deploy.test.bicep b/modules/Microsoft.EventGrid/systemTopics/.test/common/deploy.test.bicep new file mode 100644 index 0000000000..8ecc112218 --- /dev/null +++ b/modules/Microsoft.EventGrid/systemTopics/.test/common/deploy.test.bicep @@ -0,0 +1,76 @@ +targetScope = 'subscription' + +// ========== // +// Parameters // +// ========== // +@description('Optional. The name of the resource group to deploy for a testing purposes') +@maxLength(90) +param resourceGroupName string = 'ms.eventgrid.systemtopics-${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 = 'egstcom' + +// =========== // +// 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}' + storageAccountName: 'dep<>sa${serviceShort}' + } +} + +// Diagnostics +// =========== +module diagnosticDependencies '../../../../.shared/dependencyConstructs/diagnostic.dependencies.bicep' = { + scope: resourceGroup + name: '${uniqueString(deployment().name, location)}-diagnosticDependencies' + params: { + storageAccountName: 'dep<>diasa${serviceShort}01' + logAnalyticsWorkspaceName: 'dep-<>-law-${serviceShort}' + eventHubNamespaceEventHubName: 'dep-<>-evh-${serviceShort}' + eventHubNamespaceName: 'dep-<>-evhns-${serviceShort}' + location: location + } +} + +// ============== // +// Test Execution // +// ============== // + +module testDeployment '../../deploy.bicep' = { + scope: resourceGroup + name: '${uniqueString(deployment().name)}-test-${serviceShort}' + params: { + name: '<>${serviceShort}001' + source: resourceGroupResources.outputs.storageAccountResourceId + topicType: 'Microsoft.Storage.StorageAccounts' + diagnosticLogsRetentionInDays: 7 + diagnosticStorageAccountId: diagnosticDependencies.outputs.storageAccountResourceId + diagnosticWorkspaceId: diagnosticDependencies.outputs.logAnalyticsWorkspaceResourceId + diagnosticEventHubAuthorizationRuleId: diagnosticDependencies.outputs.eventHubAuthorizationRuleId + diagnosticEventHubName: diagnosticDependencies.outputs.eventHubNamespaceEventHubName + lock: 'CanNotDelete' + roleAssignments: [ + { + principalIds: [ + resourceGroupResources.outputs.managedIdentityPrincipalId + ] + roleDefinitionIdOrName: 'Reader' + } + ] + } +} diff --git a/modules/Microsoft.EventGrid/systemTopics/.test/min.parameters.json b/modules/Microsoft.EventGrid/systemTopics/.test/min.parameters.json deleted file mode 100644 index 87be2f37f1..0000000000 --- a/modules/Microsoft.EventGrid/systemTopics/.test/min.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": { - "name": { - "value": "<>-az-egstn-x-002" - }, - "source": { - "value": "/subscriptions/<>/resourceGroups/validation-rg/providers/Microsoft.Storage/storageAccounts/adp<>azsax001" - }, - "topicType": { - "value": "Microsoft.Storage.StorageAccounts" - } - } -} diff --git a/modules/Microsoft.EventGrid/systemTopics/.test/min/dependencies.bicep b/modules/Microsoft.EventGrid/systemTopics/.test/min/dependencies.bicep new file mode 100644 index 0000000000..61ebc54d90 --- /dev/null +++ b/modules/Microsoft.EventGrid/systemTopics/.test/min/dependencies.bicep @@ -0,0 +1,17 @@ +@description('Optional. The location to deploy to.') +param location string = resourceGroup().location + +@description('Required. The name of the Storage Account to create.') +param storageAccountName string + +resource storageAccount 'Microsoft.Storage/storageAccounts@2022-05-01' = { + name: storageAccountName + location: location + sku: { + name: 'Standard_LRS' + } + kind: 'StorageV2' +} + +@description('The resource ID of the created Storage Account.') +output storageAccountResourceId string = storageAccount.id diff --git a/modules/Microsoft.EventGrid/systemTopics/.test/min/deploy.test.bicep b/modules/Microsoft.EventGrid/systemTopics/.test/min/deploy.test.bicep new file mode 100644 index 0000000000..e6e1636a33 --- /dev/null +++ b/modules/Microsoft.EventGrid/systemTopics/.test/min/deploy.test.bicep @@ -0,0 +1,61 @@ +targetScope = 'subscription' + +// ========== // +// Parameters // +// ========== // +@description('Optional. The name of the resource group to deploy for a testing purposes') +@maxLength(90) +param resourceGroupName string = 'ms.eventgrid.systemtopics-${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 = 'egstmin' + +// =========== // +// 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: { + storageAccountName: 'dep<>sa${serviceShort}' + } +} + +// Diagnostics +// =========== +module diagnosticDependencies '../../../../.shared/dependencyConstructs/diagnostic.dependencies.bicep' = { + scope: resourceGroup + name: '${uniqueString(deployment().name, location)}-diagnosticDependencies' + params: { + storageAccountName: 'dep<>diasa${serviceShort}01' + logAnalyticsWorkspaceName: 'dep-<>-law-${serviceShort}' + eventHubNamespaceEventHubName: 'dep-<>-evh-${serviceShort}' + eventHubNamespaceName: 'dep-<>-evhns-${serviceShort}' + location: location + } +} + +// ============== // +// Test Execution // +// ============== // + +module testDeployment '../../deploy.bicep' = { + scope: resourceGroup + name: '${uniqueString(deployment().name)}-test-${serviceShort}' + params: { + name: '<>${serviceShort}001' + source: resourceGroupResources.outputs.storageAccountResourceId + topicType: 'Microsoft.Storage.StorageAccounts' + } +} diff --git a/modules/Microsoft.EventGrid/systemTopics/.test/parameters.json b/modules/Microsoft.EventGrid/systemTopics/.test/parameters.json deleted file mode 100644 index 5a415c770e..0000000000 --- a/modules/Microsoft.EventGrid/systemTopics/.test/parameters.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", - "contentVersion": "1.0.0.0", - "parameters": { - "name": { - "value": "<>-az-egstn-x-001" - }, - "lock": { - "value": "CanNotDelete" - }, - "source": { - "value": "/subscriptions/<>/resourceGroups/validation-rg/providers/Microsoft.Storage/storageAccounts/adp<>azsax001" - }, - "topicType": { - "value": "Microsoft.Storage.StorageAccounts" - }, - "roleAssignments": { - "value": [ - { - "roleDefinitionIdOrName": "Reader", - "principalIds": [ - "<>" - ] - } - ] - }, - "diagnosticLogsRetentionInDays": { - "value": 7 - }, - "diagnosticStorageAccountId": { - "value": "/subscriptions/<>/resourceGroups/validation-rg/providers/Microsoft.Storage/storageAccounts/adp<>azsax001" - }, - "diagnosticWorkspaceId": { - "value": "/subscriptions/<>/resourcegroups/validation-rg/providers/microsoft.operationalinsights/workspaces/adp-<>-az-law-x-001" - }, - "diagnosticEventHubAuthorizationRuleId": { - "value": "/subscriptions/<>/resourceGroups/validation-rg/providers/Microsoft.EventHub/namespaces/adp-<>-az-evhns-x-001/AuthorizationRules/RootManageSharedAccessKey" - }, - "diagnosticEventHubName": { - "value": "adp-<>-az-evh-x-001" - } - } -} diff --git a/modules/Microsoft.EventGrid/systemTopics/readme.md b/modules/Microsoft.EventGrid/systemTopics/readme.md index 2dc595c041..188ee5423e 100644 --- a/modules/Microsoft.EventGrid/systemTopics/readme.md +++ b/modules/Microsoft.EventGrid/systemTopics/readme.md @@ -279,7 +279,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: Min

+

Example 1: Common

@@ -287,12 +287,27 @@ The following module usage examples are retrieved from the content of the files ```bicep module systemTopics './Microsoft.EventGrid/systemTopics/deploy.bicep' = { - name: '${uniqueString(deployment().name)}-SystemTopics' + name: '${uniqueString(deployment().name)}-test-egstcom' params: { // Required parameters - name: '<>-az-egstn-x-002' - source: '/subscriptions/<>/resourceGroups/validation-rg/providers/Microsoft.Storage/storageAccounts/adp<>azsax001' + name: '<>egstcom001' + source: '' topicType: 'Microsoft.Storage.StorageAccounts' + // Non-required parameters + diagnosticEventHubAuthorizationRuleId: '' + diagnosticEventHubName: '' + diagnosticLogsRetentionInDays: 7 + diagnosticStorageAccountId: '' + diagnosticWorkspaceId: '' + lock: 'CanNotDelete' + roleAssignments: [ + { + principalIds: [ + '' + ] + roleDefinitionIdOrName: 'Reader' + } + ] } } ``` @@ -311,13 +326,42 @@ module systemTopics './Microsoft.EventGrid/systemTopics/deploy.bicep' = { "parameters": { // Required parameters "name": { - "value": "<>-az-egstn-x-002" + "value": "<>egstcom001" }, "source": { - "value": "/subscriptions/<>/resourceGroups/validation-rg/providers/Microsoft.Storage/storageAccounts/adp<>azsax001" + "value": "" }, "topicType": { "value": "Microsoft.Storage.StorageAccounts" + }, + // Non-required parameters + "diagnosticEventHubAuthorizationRuleId": { + "value": "" + }, + "diagnosticEventHubName": { + "value": "" + }, + "diagnosticLogsRetentionInDays": { + "value": 7 + }, + "diagnosticStorageAccountId": { + "value": "" + }, + "diagnosticWorkspaceId": { + "value": "" + }, + "lock": { + "value": "CanNotDelete" + }, + "roleAssignments": { + "value": [ + { + "principalIds": [ + "" + ], + "roleDefinitionIdOrName": "Reader" + } + ] } } } @@ -326,7 +370,7 @@ module systemTopics './Microsoft.EventGrid/systemTopics/deploy.bicep' = {

-

Example 2: Parameters

+

Example 2: Min

@@ -334,27 +378,12 @@ module systemTopics './Microsoft.EventGrid/systemTopics/deploy.bicep' = { ```bicep module systemTopics './Microsoft.EventGrid/systemTopics/deploy.bicep' = { - name: '${uniqueString(deployment().name)}-SystemTopics' + name: '${uniqueString(deployment().name)}-test-egstmin' params: { // Required parameters - name: '<>-az-egstn-x-001' - source: '/subscriptions/<>/resourceGroups/validation-rg/providers/Microsoft.Storage/storageAccounts/adp<>azsax001' + name: '<>egstmin001' + source: '' topicType: 'Microsoft.Storage.StorageAccounts' - // Non-required parameters - diagnosticEventHubAuthorizationRuleId: '/subscriptions/<>/resourceGroups/validation-rg/providers/Microsoft.EventHub/namespaces/adp-<>-az-evhns-x-001/AuthorizationRules/RootManageSharedAccessKey' - diagnosticEventHubName: 'adp-<>-az-evh-x-001' - diagnosticLogsRetentionInDays: 7 - diagnosticStorageAccountId: '/subscriptions/<>/resourceGroups/validation-rg/providers/Microsoft.Storage/storageAccounts/adp<>azsax001' - diagnosticWorkspaceId: '/subscriptions/<>/resourcegroups/validation-rg/providers/microsoft.operationalinsights/workspaces/adp-<>-az-law-x-001' - lock: 'CanNotDelete' - roleAssignments: [ - { - principalIds: [ - '<>' - ] - roleDefinitionIdOrName: 'Reader' - } - ] } } ``` @@ -373,42 +402,13 @@ module systemTopics './Microsoft.EventGrid/systemTopics/deploy.bicep' = { "parameters": { // Required parameters "name": { - "value": "<>-az-egstn-x-001" + "value": "<>egstmin001" }, "source": { - "value": "/subscriptions/<>/resourceGroups/validation-rg/providers/Microsoft.Storage/storageAccounts/adp<>azsax001" + "value": "" }, "topicType": { "value": "Microsoft.Storage.StorageAccounts" - }, - // Non-required parameters - "diagnosticEventHubAuthorizationRuleId": { - "value": "/subscriptions/<>/resourceGroups/validation-rg/providers/Microsoft.EventHub/namespaces/adp-<>-az-evhns-x-001/AuthorizationRules/RootManageSharedAccessKey" - }, - "diagnosticEventHubName": { - "value": "adp-<>-az-evh-x-001" - }, - "diagnosticLogsRetentionInDays": { - "value": 7 - }, - "diagnosticStorageAccountId": { - "value": "/subscriptions/<>/resourceGroups/validation-rg/providers/Microsoft.Storage/storageAccounts/adp<>azsax001" - }, - "diagnosticWorkspaceId": { - "value": "/subscriptions/<>/resourcegroups/validation-rg/providers/microsoft.operationalinsights/workspaces/adp-<>-az-law-x-001" - }, - "lock": { - "value": "CanNotDelete" - }, - "roleAssignments": { - "value": [ - { - "principalIds": [ - "<>" - ], - "roleDefinitionIdOrName": "Reader" - } - ] } } } From b4deb46739ee7dabc6bdbe34dcc00fdd2305b28c Mon Sep 17 00:00:00 2001 From: Alexander Sehr Date: Sun, 18 Sep 2022 22:42:40 +0200 Subject: [PATCH 2/4] Update modules/Microsoft.EventGrid/systemTopics/.test/common/deploy.test.bicep --- .../systemTopics/.test/common/deploy.test.bicep | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/Microsoft.EventGrid/systemTopics/.test/common/deploy.test.bicep b/modules/Microsoft.EventGrid/systemTopics/.test/common/deploy.test.bicep index 8ecc112218..df34fc99fc 100644 --- a/modules/Microsoft.EventGrid/systemTopics/.test/common/deploy.test.bicep +++ b/modules/Microsoft.EventGrid/systemTopics/.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(90) param resourceGroupName string = 'ms.eventgrid.systemtopics-${serviceShort}-rg' From 290008690116cdca2223127a308bb4f15300f422 Mon Sep 17 00:00:00 2001 From: Alexander Sehr Date: Sun, 18 Sep 2022 22:43:10 +0200 Subject: [PATCH 3/4] Update modules/Microsoft.EventGrid/systemTopics/.test/min/deploy.test.bicep --- .../systemTopics/.test/min/deploy.test.bicep | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/Microsoft.EventGrid/systemTopics/.test/min/deploy.test.bicep b/modules/Microsoft.EventGrid/systemTopics/.test/min/deploy.test.bicep index e6e1636a33..40a13d08fa 100644 --- a/modules/Microsoft.EventGrid/systemTopics/.test/min/deploy.test.bicep +++ b/modules/Microsoft.EventGrid/systemTopics/.test/min/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(90) param resourceGroupName string = 'ms.eventgrid.systemtopics-${serviceShort}-rg' From 521d8e39afc9f11bae7199ddf1b36afb4b4f8c55 Mon Sep 17 00:00:00 2001 From: MrMCake Date: Wed, 5 Oct 2022 19:01:02 +0200 Subject: [PATCH 4/4] Update to latest --- .../systemTopics/.test/common/deploy.test.bicep | 6 +++--- .../systemTopics/.test/min/deploy.test.bicep | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/Microsoft.EventGrid/systemTopics/.test/common/deploy.test.bicep b/modules/Microsoft.EventGrid/systemTopics/.test/common/deploy.test.bicep index df34fc99fc..1efe3f41e1 100644 --- a/modules/Microsoft.EventGrid/systemTopics/.test/common/deploy.test.bicep +++ b/modules/Microsoft.EventGrid/systemTopics/.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.eventgrid.systemtopics-${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 = 'egstcom' // =========== // diff --git a/modules/Microsoft.EventGrid/systemTopics/.test/min/deploy.test.bicep b/modules/Microsoft.EventGrid/systemTopics/.test/min/deploy.test.bicep index 40a13d08fa..da56a466b7 100644 --- a/modules/Microsoft.EventGrid/systemTopics/.test/min/deploy.test.bicep +++ b/modules/Microsoft.EventGrid/systemTopics/.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.eventgrid.systemtopics-${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 = 'egstmin' // =========== //