diff --git a/.github/workflows/ms.containerinstance.containergroups.yml b/.github/workflows/ms.containerinstance.containergroups.yml index 5d96b96c02..c919dc4a49 100644 --- a/.github/workflows/ms.containerinstance.containergroups.yml +++ b/.github/workflows/ms.containerinstance.containergroups.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.ContainerInstance/containerGroups/.test/common/dependencies.bicep b/modules/Microsoft.ContainerInstance/containerGroups/.test/common/dependencies.bicep new file mode 100644 index 0000000000..66dc10c2f2 --- /dev/null +++ b/modules/Microsoft.ContainerInstance/containerGroups/.test/common/dependencies.bicep @@ -0,0 +1,13 @@ +@description('Required. The name of the managed identity to create.') +param managedIdentityName string + +@description('Optional. The location to deploy resources to.') +param location string = resourceGroup().location + +resource managedIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2018-11-30' = { + name: managedIdentityName + location: location +} + +@description('The resource ID of the created managed identity.') +output managedIdentityResourceId string = managedIdentity.id diff --git a/modules/Microsoft.ContainerInstance/containerGroups/.test/common/deploy.test.bicep b/modules/Microsoft.ContainerInstance/containerGroups/.test/common/deploy.test.bicep new file mode 100644 index 0000000000..98a017e298 --- /dev/null +++ b/modules/Microsoft.ContainerInstance/containerGroups/.test/common/deploy.test.bicep @@ -0,0 +1,106 @@ +targetScope = 'subscription' + +// ========== // +// Parameters // +// ========== // +@description('Optional. The name of the resource group to deploy for testing purposes.') +@maxLength(90) +param resourceGroupName string = 'ms.containerinstance.containergroups-${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 = 'cicgcom' + +// =========== // +// 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' + containers: [ + { + name: '<>-az-aci-x-001' + properties: { + command: [] + environmentVariables: [] + image: 'mcr.microsoft.com/azuredocs/aci-helloworld' + ports: [ + { + port: '80' + protocol: 'Tcp' + } + { + port: '443' + protocol: 'Tcp' + } + ] + resources: { + requests: { + cpu: 2 + memoryInGB: 2 + } + } + } + } + { + name: '<>-az-aci-x-002' + properties: { + command: [] + environmentVariables: [] + image: 'mcr.microsoft.com/azuredocs/aci-helloworld' + ports: [ + { + port: '8080' + protocol: 'Tcp' + } + ] + resources: { + requests: { + cpu: 2 + memoryInGB: 2 + } + } + } + } + ] + ipAddressPorts: [ + { + protocol: 'Tcp' + port: 80 + } + { + protocol: 'Tcp' + port: 443 + } + ] + systemAssignedIdentity: true + userAssignedIdentities: { + '${resourceGroupResources.outputs.managedIdentityResourceId}': {} + } + } +} diff --git a/modules/Microsoft.ContainerInstance/containerGroups/.test/min.parameters.json b/modules/Microsoft.ContainerInstance/containerGroups/.test/min.parameters.json deleted file mode 100644 index 7240bf0494..0000000000 --- a/modules/Microsoft.ContainerInstance/containerGroups/.test/min.parameters.json +++ /dev/null @@ -1,60 +0,0 @@ -{ - "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", - "contentVersion": "1.0.0.0", - "parameters": { - "name": { - "value": "<>-az-acg-x-001" - }, - "lock": { - "value": "CanNotDelete" - }, - "containers": { - "value": [ - { - "name": "<>-az-aci-x-001", - "properties": { - "command": [], - "image": "mcr.microsoft.com/azuredocs/aci-helloworld", - "ports": [ - { - "protocol": "Tcp", - "port": "80" - }, - { - "protocol": "Tcp", - "port": "443" - } - ], - "resources": { - "requests": { - "cpu": 2, - "memoryInGB": 2 - } - }, - "environmentVariables": [] - } - } - ] - }, - "ipAddressPorts": { - "value": [ - { - "protocol": "Tcp", - "port": "80" - }, - { - "protocol": "Tcp", - "port": "443" - } - ] - }, - "systemAssignedIdentity": { - "value": true - }, - "userAssignedIdentities": { - "value": { - "/subscriptions/<>/resourcegroups/validation-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/adp-<>-az-msi-x-001": {} - } - } - } -} diff --git a/modules/Microsoft.ContainerInstance/containerGroups/.test/min/deploy.test.bicep b/modules/Microsoft.ContainerInstance/containerGroups/.test/min/deploy.test.bicep new file mode 100644 index 0000000000..8b69864c1c --- /dev/null +++ b/modules/Microsoft.ContainerInstance/containerGroups/.test/min/deploy.test.bicep @@ -0,0 +1,63 @@ +targetScope = 'subscription' + +// ========== // +// Parameters // +// ========== // +@description('Optional. The name of the resource group to deploy for testing purposes.') +@maxLength(90) +param resourceGroupName string = 'ms.containerinstance.containergroups-${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 = 'cicgmin' + +// =========== // +// 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' + containers: [ + { + name: '<>-az-aci-x-001' + properties: { + image: 'mcr.microsoft.com/azuredocs/aci-helloworld' + ports: [ + { + port: '443' + protocol: 'Tcp' + } + ] + resources: { + requests: { + cpu: 2 + memoryInGB: 2 + } + } + } + } + ] + ipAddressPorts: [ + { + protocol: 'Tcp' + port: 443 + } + ] + } +} diff --git a/modules/Microsoft.ContainerInstance/containerGroups/.test/parameters.json b/modules/Microsoft.ContainerInstance/containerGroups/.test/parameters.json deleted file mode 100644 index 037d647af4..0000000000 --- a/modules/Microsoft.ContainerInstance/containerGroups/.test/parameters.json +++ /dev/null @@ -1,84 +0,0 @@ -{ - "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#", - "contentVersion": "1.0.0.0", - "parameters": { - "name": { - "value": "<>-az-acg-x-001" - }, - "lock": { - "value": "CanNotDelete" - }, - "containers": { - "value": [ - { - "name": "<>-az-aci-x-001", - "properties": { - "command": [], - "image": "mcr.microsoft.com/azuredocs/aci-helloworld", - "ports": [ - { - "protocol": "Tcp", - "port": "80" - }, - { - "protocol": "Tcp", - "port": "443" - } - ], - "resources": { - "requests": { - "cpu": 2, - "memoryInGB": 2 - } - }, - "environmentVariables": [] - } - }, - { - "name": "<>-az-aci-x-002", - "properties": { - "command": [], - "image": "mcr.microsoft.com/azuredocs/aci-helloworld", - "ports": [ - { - "protocol": "Tcp", - "port": "8080" - } - ], - "resources": { - "requests": { - "cpu": 2, - "memoryInGB": 2 - } - }, - "environmentVariables": [] - } - } - ] - }, - "ipAddressPorts": { - "value": [ - { - "protocol": "Tcp", - "port": "80" - }, - { - "protocol": "Tcp", - "port": "443" - }, - { - "protocol": "Tcp", - "port": "8080" - } - ] - }, - "systemAssignedIdentity": { - "value": true - }, - "userAssignedIdentities": { - "value": { - "/subscriptions/<>/resourcegroups/validation-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/adp-<>-az-msi-x-001": {} - } - } - } -} diff --git a/modules/Microsoft.ContainerInstance/containerGroups/readme.md b/modules/Microsoft.ContainerInstance/containerGroups/readme.md index 09c9f68333..2250848253 100644 --- a/modules/Microsoft.ContainerInstance/containerGroups/readme.md +++ b/modules/Microsoft.ContainerInstance/containerGroups/readme.md @@ -178,7 +178,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

@@ -186,7 +186,7 @@ The following module usage examples are retrieved from the content of the files ```bicep module containerGroups './Microsoft.ContainerInstance/containerGroups/deploy.bicep' = { - name: '${uniqueString(deployment().name)}-ContainerGroups' + name: '${uniqueString(deployment().name)}-test-cicgcom' params: { // Required parameters containers: [ @@ -214,23 +214,43 @@ module containerGroups './Microsoft.ContainerInstance/containerGroups/deploy.bic } } } + { + name: '<>-az-aci-x-002' + properties: { + command: [] + environmentVariables: [] + image: 'mcr.microsoft.com/azuredocs/aci-helloworld' + ports: [ + { + port: '8080' + protocol: 'Tcp' + } + ] + resources: { + requests: { + cpu: 2 + memoryInGB: 2 + } + } + } + } ] - name: '<>-az-acg-x-001' + name: '<>cicgcom001' // Non-required parameters ipAddressPorts: [ { - port: '80' + port: 80 protocol: 'Tcp' } { - port: '443' + port: 443 protocol: 'Tcp' } ] lock: 'CanNotDelete' systemAssignedIdentity: true userAssignedIdentities: { - '/subscriptions/<>/resourcegroups/validation-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/adp-<>-az-msi-x-001': {} + '': {} } } } @@ -274,21 +294,41 @@ module containerGroups './Microsoft.ContainerInstance/containerGroups/deploy.bic } } } + }, + { + "name": "<>-az-aci-x-002", + "properties": { + "command": [], + "environmentVariables": [], + "image": "mcr.microsoft.com/azuredocs/aci-helloworld", + "ports": [ + { + "port": "8080", + "protocol": "Tcp" + } + ], + "resources": { + "requests": { + "cpu": 2, + "memoryInGB": 2 + } + } + } } ] }, "name": { - "value": "<>-az-acg-x-001" + "value": "<>cicgcom001" }, // Non-required parameters "ipAddressPorts": { "value": [ { - "port": "80", + "port": 80, "protocol": "Tcp" }, { - "port": "443", + "port": 443, "protocol": "Tcp" } ] @@ -301,7 +341,7 @@ module containerGroups './Microsoft.ContainerInstance/containerGroups/deploy.bic }, "userAssignedIdentities": { "value": { - "/subscriptions/<>/resourcegroups/validation-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/adp-<>-az-msi-x-001": {} + "": {} } } } @@ -311,7 +351,7 @@ module containerGroups './Microsoft.ContainerInstance/containerGroups/deploy.bic

-

Example 2: Parameters

+

Example 2: Min

@@ -319,21 +359,15 @@ module containerGroups './Microsoft.ContainerInstance/containerGroups/deploy.bic ```bicep module containerGroups './Microsoft.ContainerInstance/containerGroups/deploy.bicep' = { - name: '${uniqueString(deployment().name)}-ContainerGroups' + name: '${uniqueString(deployment().name)}-test-cicgmin' params: { // Required parameters containers: [ { name: '<>-az-aci-x-001' properties: { - command: [] - environmentVariables: [] image: 'mcr.microsoft.com/azuredocs/aci-helloworld' ports: [ - { - port: '80' - protocol: 'Tcp' - } { port: '443' protocol: 'Tcp' @@ -347,48 +381,15 @@ module containerGroups './Microsoft.ContainerInstance/containerGroups/deploy.bic } } } - { - name: '<>-az-aci-x-002' - properties: { - command: [] - environmentVariables: [] - image: 'mcr.microsoft.com/azuredocs/aci-helloworld' - ports: [ - { - port: '8080' - protocol: 'Tcp' - } - ] - resources: { - requests: { - cpu: 2 - memoryInGB: 2 - } - } - } - } ] - name: '<>-az-acg-x-001' + name: '<>cicgmin001' // Non-required parameters ipAddressPorts: [ { - port: '80' - protocol: 'Tcp' - } - { - port: '443' - protocol: 'Tcp' - } - { - port: '8080' + port: 443 protocol: 'Tcp' } ] - lock: 'CanNotDelete' - systemAssignedIdentity: true - userAssignedIdentities: { - '/subscriptions/<>/resourcegroups/validation-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/adp-<>-az-msi-x-001': {} - } } } ``` @@ -411,14 +412,8 @@ module containerGroups './Microsoft.ContainerInstance/containerGroups/deploy.bic { "name": "<>-az-aci-x-001", "properties": { - "command": [], - "environmentVariables": [], "image": "mcr.microsoft.com/azuredocs/aci-helloworld", "ports": [ - { - "port": "80", - "protocol": "Tcp" - }, { "port": "443", "protocol": "Tcp" @@ -431,59 +426,20 @@ module containerGroups './Microsoft.ContainerInstance/containerGroups/deploy.bic } } } - }, - { - "name": "<>-az-aci-x-002", - "properties": { - "command": [], - "environmentVariables": [], - "image": "mcr.microsoft.com/azuredocs/aci-helloworld", - "ports": [ - { - "port": "8080", - "protocol": "Tcp" - } - ], - "resources": { - "requests": { - "cpu": 2, - "memoryInGB": 2 - } - } - } } ] }, "name": { - "value": "<>-az-acg-x-001" + "value": "<>cicgmin001" }, // Non-required parameters "ipAddressPorts": { "value": [ { - "port": "80", - "protocol": "Tcp" - }, - { - "port": "443", - "protocol": "Tcp" - }, - { - "port": "8080", + "port": 443, "protocol": "Tcp" } ] - }, - "lock": { - "value": "CanNotDelete" - }, - "systemAssignedIdentity": { - "value": true - }, - "userAssignedIdentities": { - "value": { - "/subscriptions/<>/resourcegroups/validation-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/adp-<>-az-msi-x-001": {} - } } } }