From ff31e0f9066ee3745ee42cdfbf79252422852853 Mon Sep 17 00:00:00 2001 From: MrMCake Date: Fri, 16 Sep 2022 10:58:48 +0200 Subject: [PATCH 1/3] Update Network NATGateway to new dependency approach --- .github/workflows/ms.network.natgateways.yml | 3 +- .../.test/common/dependencies.bicep | 14 ++++ .../.test/common/deploy.test.bicep | 74 +++++++++++++++++++ .../natGateways/.test/parameters.json | 40 ---------- .../Microsoft.Network/natGateways/readme.md | 28 +++---- 5 files changed, 103 insertions(+), 56 deletions(-) create mode 100644 modules/Microsoft.Network/natGateways/.test/common/dependencies.bicep create mode 100644 modules/Microsoft.Network/natGateways/.test/common/deploy.test.bicep delete mode 100644 modules/Microsoft.Network/natGateways/.test/parameters.json diff --git a/.github/workflows/ms.network.natgateways.yml b/.github/workflows/ms.network.natgateways.yml index 32143fca94..f300abab44 100644 --- a/.github/workflows/ms.network.natgateways.yml +++ b/.github/workflows/ms.network.natgateways.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.Network/natGateways/.test/common/dependencies.bicep b/modules/Microsoft.Network/natGateways/.test/common/dependencies.bicep new file mode 100644 index 0000000000..7371d4437b --- /dev/null +++ b/modules/Microsoft.Network/natGateways/.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.Network/natGateways/.test/common/deploy.test.bicep b/modules/Microsoft.Network/natGateways/.test/common/deploy.test.bicep new file mode 100644 index 0000000000..9f18d5b1f4 --- /dev/null +++ b/modules/Microsoft.Network/natGateways/.test/common/deploy.test.bicep @@ -0,0 +1,74 @@ +targetScope = 'subscription' + +// ========== // +// Parameters // +// ========== // +@description('Optional. The name of the resource group to deploy for a testing purposes') +@maxLength(90) +param resourceGroupName string = 'ms.network.natgateways-${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 = 'nngcom' + +// =========== // +// 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}' + } +} + +// 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' + diagnosticLogsRetentionInDays: 7 + diagnosticStorageAccountId: diagnosticDependencies.outputs.storageAccountResourceId + diagnosticWorkspaceId: diagnosticDependencies.outputs.logAnalyticsWorkspaceResourceId + diagnosticEventHubAuthorizationRuleId: diagnosticDependencies.outputs.eventHubAuthorizationRuleId + diagnosticEventHubName: diagnosticDependencies.outputs.eventHubNamespaceEventHubName + lock: 'CanNotDelete' + natGatewayPublicIpAddress: true + roleAssignments: [ + { + principalIds: [ + resourceGroupResources.outputs.managedIdentityPrincipalId + ] + roleDefinitionIdOrName: 'Reader' + } + ] + } +} diff --git a/modules/Microsoft.Network/natGateways/.test/parameters.json b/modules/Microsoft.Network/natGateways/.test/parameters.json deleted file mode 100644 index ec9c2014d9..0000000000 --- a/modules/Microsoft.Network/natGateways/.test/parameters.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", - "contentVersion": "1.0.0.0", - "parameters": { - "name": { - "value": "<>-az-ngw-x-001" - }, - "lock": { - "value": "CanNotDelete" - }, - "natGatewayPublicIpAddress": { - "value": true - }, - "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.Network/natGateways/readme.md b/modules/Microsoft.Network/natGateways/readme.md index c91215ddd6..7c637ca533 100644 --- a/modules/Microsoft.Network/natGateways/readme.md +++ b/modules/Microsoft.Network/natGateways/readme.md @@ -173,7 +173,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

@@ -181,22 +181,22 @@ The following module usage examples are retrieved from the content of the files ```bicep module natGateways './Microsoft.Network/natGateways/deploy.bicep' = { - name: '${uniqueString(deployment().name)}-NatGateways' + name: '${uniqueString(deployment().name)}-test-nngcom' params: { // Required parameters - name: '<>-az-ngw-x-001' + name: '<>nngcom001' // 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' + diagnosticEventHubAuthorizationRuleId: '' + diagnosticEventHubName: '' 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' + diagnosticStorageAccountId: '' + diagnosticWorkspaceId: '' lock: 'CanNotDelete' natGatewayPublicIpAddress: true roleAssignments: [ { principalIds: [ - '<>' + '' ] roleDefinitionIdOrName: 'Reader' } @@ -219,23 +219,23 @@ module natGateways './Microsoft.Network/natGateways/deploy.bicep' = { "parameters": { // Required parameters "name": { - "value": "<>-az-ngw-x-001" + "value": "<>nngcom001" }, // Non-required parameters "diagnosticEventHubAuthorizationRuleId": { - "value": "/subscriptions/<>/resourceGroups/validation-rg/providers/Microsoft.EventHub/namespaces/adp-<>-az-evhns-x-001/AuthorizationRules/RootManageSharedAccessKey" + "value": "" }, "diagnosticEventHubName": { - "value": "adp-<>-az-evh-x-001" + "value": "" }, "diagnosticLogsRetentionInDays": { "value": 7 }, "diagnosticStorageAccountId": { - "value": "/subscriptions/<>/resourceGroups/validation-rg/providers/Microsoft.Storage/storageAccounts/adp<>azsax001" + "value": "" }, "diagnosticWorkspaceId": { - "value": "/subscriptions/<>/resourcegroups/validation-rg/providers/microsoft.operationalinsights/workspaces/adp-<>-az-law-x-001" + "value": "" }, "lock": { "value": "CanNotDelete" @@ -247,7 +247,7 @@ module natGateways './Microsoft.Network/natGateways/deploy.bicep' = { "value": [ { "principalIds": [ - "<>" + "" ], "roleDefinitionIdOrName": "Reader" } From 5212338214879a18a44a70ad21e0b21faf9463f2 Mon Sep 17 00:00:00 2001 From: Alexander Sehr Date: Sun, 18 Sep 2022 23:47:10 +0200 Subject: [PATCH 2/3] Update modules/Microsoft.Network/natGateways/.test/common/deploy.test.bicep --- .../natGateways/.test/common/deploy.test.bicep | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/Microsoft.Network/natGateways/.test/common/deploy.test.bicep b/modules/Microsoft.Network/natGateways/.test/common/deploy.test.bicep index 9f18d5b1f4..e769166e73 100644 --- a/modules/Microsoft.Network/natGateways/.test/common/deploy.test.bicep +++ b/modules/Microsoft.Network/natGateways/.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.network.natgateways-${serviceShort}-rg' From 1acde2f63166159a36c65f8d4567034fac470637 Mon Sep 17 00:00:00 2001 From: MrMCake Date: Wed, 5 Oct 2022 21:15:47 +0200 Subject: [PATCH 3/3] Update to latest --- .../natGateways/.test/common/deploy.test.bicep | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/Microsoft.Network/natGateways/.test/common/deploy.test.bicep b/modules/Microsoft.Network/natGateways/.test/common/deploy.test.bicep index e769166e73..e9b3c79328 100644 --- a/modules/Microsoft.Network/natGateways/.test/common/deploy.test.bicep +++ b/modules/Microsoft.Network/natGateways/.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.network.natgateways-${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 = 'nngcom' // =========== //