diff --git a/.github/workflows/ms.compute.galleries.yml b/.github/workflows/ms.compute.galleries.yml index e45bf278bd..3e340a80cc 100644 --- a/.github/workflows/ms.compute.galleries.yml +++ b/.github/workflows/ms.compute.galleries.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.Compute/galleries/.test/common/dependencies.bicep b/modules/Microsoft.Compute/galleries/.test/common/dependencies.bicep new file mode 100644 index 0000000000..7371d4437b --- /dev/null +++ b/modules/Microsoft.Compute/galleries/.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.Compute/galleries/.test/common/deploy.test.bicep b/modules/Microsoft.Compute/galleries/.test/common/deploy.test.bicep new file mode 100644 index 0000000000..ca9eafbd53 --- /dev/null +++ b/modules/Microsoft.Compute/galleries/.test/common/deploy.test.bicep @@ -0,0 +1,54 @@ +targetScope = 'subscription' + +// ========== // +// Parameters // +// ========== // +@description('Optional. The name of the resource group to deploy for testing purposes.') +@maxLength(90) +param resourceGroupName string = 'ms.compute.galleries-${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 = 'cgcom' + +// =========== // +// 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' + lock: 'CanNotDelete' + roleAssignments: [ + { + principalIds: [ + resourceGroupResources.outputs.managedIdentityPrincipalId + ] + roleDefinitionIdOrName: 'Reader' + } + ] + } +} diff --git a/modules/Microsoft.Compute/galleries/.test/images.parameters.json b/modules/Microsoft.Compute/galleries/.test/images.parameters.json deleted file mode 100644 index 78a802c198..0000000000 --- a/modules/Microsoft.Compute/galleries/.test/images.parameters.json +++ /dev/null @@ -1,50 +0,0 @@ -{ - "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", - "contentVersion": "1.0.0.0", - "parameters": { - "name": { - "value": "<>azsigweuimages001" - }, - "images": { - "value": [ - { - "name": "<>-az-imgd-x-003" - }, - { - "name": "<>-az-imgd-x-001", - "osType": "Windows", - "osState": "Generalized", - "publisher": "MicrosoftWindowsServer", - "offer": "WindowsServer", - "sku": "2022-datacenter-azure-edition", - "minRecommendedvCPUs": 2, - "maxRecommendedvCPUs": 8, - "minRecommendedMemory": 4, - "maxRecommendedMemory": 16, - "hyperVGeneration": "V1", - "roleAssignments": [ - { - "roleDefinitionIdOrName": "Reader", - "principalIds": [ - "<>" - ] - } - ] - }, - { - "name": "<>-az-imgd-x-002", - "osType": "Linux", - "osState": "Generalized", - "publisher": "canonical", - "offer": "0001-com-ubuntu-server-focal", - "sku": "20_04-lts-gen2", - "minRecommendedvCPUs": 1, - "maxRecommendedvCPUs": 4, - "minRecommendedMemory": 4, - "maxRecommendedMemory": 32, - "hyperVGeneration": "V2" - } - ] - } - } -} diff --git a/modules/Microsoft.Compute/galleries/.test/images/dependencies.bicep b/modules/Microsoft.Compute/galleries/.test/images/dependencies.bicep new file mode 100644 index 0000000000..7371d4437b --- /dev/null +++ b/modules/Microsoft.Compute/galleries/.test/images/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.Compute/galleries/.test/images/deploy.test.bicep b/modules/Microsoft.Compute/galleries/.test/images/deploy.test.bicep new file mode 100644 index 0000000000..fe7a001f4a --- /dev/null +++ b/modules/Microsoft.Compute/galleries/.test/images/deploy.test.bicep @@ -0,0 +1,84 @@ +targetScope = 'subscription' + +// ========== // +// Parameters // +// ========== // +@description('Optional. The name of the resource group to deploy for testing purposes.') +@maxLength(90) +param resourceGroupName string = 'ms.compute.galleries-${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 = 'cgimages' + +// =========== // +// 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' + images: [ + { + name: '<>-${serviceShort}-imgd-001' + } + { + hyperVGeneration: 'V1' + maxRecommendedMemory: 16 + maxRecommendedvCPUs: 8 + minRecommendedMemory: 4 + minRecommendedvCPUs: 2 + name: '<>-az-imgd-x-001' + offer: 'WindowsServer' + osState: 'Generalized' + osType: 'Windows' + publisher: 'MicrosoftWindowsServer' + roleAssignments: [ + { + principalIds: [ + resourceGroupResources.outputs.managedIdentityPrincipalId + ] + roleDefinitionIdOrName: 'Reader' + } + ] + sku: '2022-datacenter-azure-edition' + } + { + hyperVGeneration: 'V2' + maxRecommendedMemory: 32 + maxRecommendedvCPUs: 4 + minRecommendedMemory: 4 + minRecommendedvCPUs: 1 + name: '<>-az-imgd-x-002' + offer: '0001-com-ubuntu-server-focal' + osState: 'Generalized' + osType: 'Linux' + publisher: 'canonical' + sku: '20_04-lts-gen2' + } + ] + } +} diff --git a/modules/Microsoft.Compute/galleries/.test/parameters.json b/modules/Microsoft.Compute/galleries/.test/parameters.json deleted file mode 100644 index 960e0365b2..0000000000 --- a/modules/Microsoft.Compute/galleries/.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": "<>azsigweux001" - }, - "lock": { - "value": "CanNotDelete" - }, - "roleAssignments": { - "value": [ - { - "roleDefinitionIdOrName": "Reader", - "principalIds": [ - "<>" - ] - } - ] - } - } -} diff --git a/modules/Microsoft.Compute/galleries/readme.md b/modules/Microsoft.Compute/galleries/readme.md index 31fe3d9802..c61b2aa3f1 100644 --- a/modules/Microsoft.Compute/galleries/readme.md +++ b/modules/Microsoft.Compute/galleries/readme.md @@ -160,7 +160,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: Images

+

Example 1: Common

@@ -168,14 +168,77 @@ The following module usage examples are retrieved from the content of the files ```bicep module galleries './Microsoft.Compute/galleries/deploy.bicep' = { - name: '${uniqueString(deployment().name)}-Galleries' + name: '${uniqueString(deployment().name)}-test-cgcom' params: { // Required parameters - name: '<>azsigweuimages001' + name: '<>cgcom001' + // Non-required parameters + lock: 'CanNotDelete' + roleAssignments: [ + { + principalIds: [ + '' + ] + roleDefinitionIdOrName: 'Reader' + } + ] + } +} +``` + +
+

+ +

+ +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": "<>cgcom001" + }, + // Non-required parameters + "lock": { + "value": "CanNotDelete" + }, + "roleAssignments": { + "value": [ + { + "principalIds": [ + "" + ], + "roleDefinitionIdOrName": "Reader" + } + ] + } + } +} +``` + +
+

+ +

Example 2: Images

+ +
+ +via Bicep module + +```bicep +module galleries './Microsoft.Compute/galleries/deploy.bicep' = { + name: '${uniqueString(deployment().name)}-test-cgimages' + params: { + // Required parameters + name: '<>cgimages001' // Non-required parameters images: [ { - name: '<>-az-imgd-x-003' + name: '<>-cgimages-imgd-001' } { hyperVGeneration: 'V1' @@ -191,7 +254,7 @@ module galleries './Microsoft.Compute/galleries/deploy.bicep' = { roleAssignments: [ { principalIds: [ - '<>' + '' ] roleDefinitionIdOrName: 'Reader' } @@ -230,13 +293,13 @@ module galleries './Microsoft.Compute/galleries/deploy.bicep' = { "parameters": { // Required parameters "name": { - "value": "<>azsigweuimages001" + "value": "<>cgimages001" }, // Non-required parameters "images": { "value": [ { - "name": "<>-az-imgd-x-003" + "name": "<>-cgimages-imgd-001" }, { "hyperVGeneration": "V1", @@ -252,7 +315,7 @@ module galleries './Microsoft.Compute/galleries/deploy.bicep' = { "roleAssignments": [ { "principalIds": [ - "<>" + "" ], "roleDefinitionIdOrName": "Reader" } @@ -280,66 +343,3 @@ module galleries './Microsoft.Compute/galleries/deploy.bicep' = {

- -

Example 2: Parameters

- -
- -via Bicep module - -```bicep -module galleries './Microsoft.Compute/galleries/deploy.bicep' = { - name: '${uniqueString(deployment().name)}-Galleries' - params: { - // Required parameters - name: '<>azsigweux001' - // Non-required parameters - lock: 'CanNotDelete' - roleAssignments: [ - { - principalIds: [ - '<>' - ] - roleDefinitionIdOrName: 'Reader' - } - ] - } -} -``` - -
-

- -

- -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": "<>azsigweux001" - }, - // Non-required parameters - "lock": { - "value": "CanNotDelete" - }, - "roleAssignments": { - "value": [ - { - "principalIds": [ - "<>" - ], - "roleDefinitionIdOrName": "Reader" - } - ] - } - } -} -``` - -
-