diff --git a/modules/Microsoft.ContainerInstance/containerGroups/.test/min.parameters.json b/modules/Microsoft.ContainerInstance/containerGroups/.test/min.parameters.json new file mode 100644 index 0000000000..7240bf0494 --- /dev/null +++ b/modules/Microsoft.ContainerInstance/containerGroups/.test/min.parameters.json @@ -0,0 +1,60 @@ +{ + "$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/parameters.json b/modules/Microsoft.ContainerInstance/containerGroups/.test/parameters.json index cdbb1078cd..037d647af4 100644 --- a/modules/Microsoft.ContainerInstance/containerGroups/.test/parameters.json +++ b/modules/Microsoft.ContainerInstance/containerGroups/.test/parameters.json @@ -8,13 +8,55 @@ "lock": { "value": "CanNotDelete" }, - "containerName": { - "value": "<>-az-aci-x-001" - }, - "image": { - "value": "mcr.microsoft.com/azuredocs/aci-helloworld" + "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": [] + } + } + ] }, - "ports": { + "ipAddressPorts": { "value": [ { "protocol": "Tcp", @@ -23,6 +65,10 @@ { "protocol": "Tcp", "port": "443" + }, + { + "protocol": "Tcp", + "port": "8080" } ] }, diff --git a/modules/Microsoft.ContainerInstance/containerGroups/deploy.bicep b/modules/Microsoft.ContainerInstance/containerGroups/deploy.bicep index 457484992c..9e561416ff 100644 --- a/modules/Microsoft.ContainerInstance/containerGroups/deploy.bicep +++ b/modules/Microsoft.ContainerInstance/containerGroups/deploy.bicep @@ -1,25 +1,11 @@ @description('Required. Name for the container group.') param name string -@description('Required. Name for the container.') -param containername string +@description('Required. The containers and their respective config within the container group.') +param containers array -@description('Required. Name of the image.') -param image string - -@description('Optional. Port to open on the container and the public IP address.') -param ports array = [ - { - protocol: 'TCP' - port: '443' - } -] - -@description('Optional. The number of CPU cores to allocate to the container.') -param cpuCores int = 2 - -@description('Optional. The amount of memory to allocate to the container in gigabytes.') -param memoryInGB int = 2 +@description('Optional. Ports to open on the public IP address. Must include all ports assigned on container level.') +param ipAddressPorts array = [] @description('Optional. The operating system type required by the containers in the container group. - Windows or Linux.') param osType string = 'Linux' @@ -33,9 +19,6 @@ param ipAddressType string = 'Public' @description('Optional. The image registry credentials by which the container group is created from.') param imageRegistryCredentials array = [] -@description('Optional. Environment variables of the container group.') -param environmentVariables array = [] - @description('Optional. Location for all Resources.') param location string = resourceGroup().location @@ -84,29 +67,13 @@ resource containergroup 'Microsoft.ContainerInstance/containerGroups@2021-10-01' identity: identity tags: tags properties: { - containers: [ - { - name: containername - properties: { - command: [] - image: image - ports: ports - resources: { - requests: { - cpu: cpuCores - memoryInGB: memoryInGB - } - } - environmentVariables: environmentVariables - } - } - ] + containers: containers imageRegistryCredentials: imageRegistryCredentials restartPolicy: restartPolicy osType: osType ipAddress: { type: ipAddressType - ports: ports + ports: ipAddressPorts } } } diff --git a/modules/Microsoft.ContainerInstance/containerGroups/readme.md b/modules/Microsoft.ContainerInstance/containerGroups/readme.md index b3d210ef95..09c9f68333 100644 --- a/modules/Microsoft.ContainerInstance/containerGroups/readme.md +++ b/modules/Microsoft.ContainerInstance/containerGroups/readme.md @@ -25,24 +25,20 @@ The top-level resource in Azure Container Instances is the container group. A co | Parameter Name | Type | Description | | :-- | :-- | :-- | -| `containername` | string | Name for the container. | -| `image` | string | Name of the image. | +| `containers` | array | The containers and their respective config within the container group. | | `name` | string | Name for the container group. | **Optional parameters** | Parameter Name | Type | Default Value | Allowed Values | Description | | :-- | :-- | :-- | :-- | :-- | -| `cpuCores` | int | `2` | | The number of CPU cores to allocate to the container. | | `enableDefaultTelemetry` | bool | `True` | | Enable telemetry via the Customer Usage Attribution ID (GUID). | -| `environmentVariables` | array | `[]` | | Environment variables of the container group. | | `imageRegistryCredentials` | array | `[]` | | The image registry credentials by which the container group is created from. | +| `ipAddressPorts` | array | `[]` | | Ports to open on the public IP address. Must include all ports assigned on container level. | | `ipAddressType` | string | `'Public'` | | Specifies if the IP is exposed to the public internet or private VNET. - Public or Private. | | `location` | string | `[resourceGroup().location]` | | Location for all Resources. | | `lock` | string | `''` | `['', CanNotDelete, ReadOnly]` | Specify the type of lock. | -| `memoryInGB` | int | `2` | | The amount of memory to allocate to the container in gigabytes. | | `osType` | string | `'Linux'` | | The operating system type required by the containers in the container group. - Windows or Linux. | -| `ports` | array | `[System.Collections.Hashtable]` | | Port to open on the container and the public IP address. | | `restartPolicy` | string | `'Always'` | | Restart policy for all containers within the container group. - Always: Always restart. OnFailure: Restart on failure. Never: Never restart. - Always, OnFailure, Never. | | `systemAssignedIdentity` | bool | `False` | | Enables system assigned managed identity on the resource. | | `tags` | object | `{object}` | | Tags of the resource. | @@ -182,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: Parameters

+

Example 1: Min

@@ -193,12 +189,35 @@ module containerGroups './Microsoft.ContainerInstance/containerGroups/deploy.bic name: '${uniqueString(deployment().name)}-ContainerGroups' params: { // Required parameters - containerName: '<>-az-aci-x-001' - image: 'mcr.microsoft.com/azuredocs/aci-helloworld' + 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-acg-x-001' // Non-required parameters - lock: 'CanNotDelete' - ports: [ + ipAddressPorts: [ { port: '80' protocol: 'Tcp' @@ -208,6 +227,7 @@ module containerGroups './Microsoft.ContainerInstance/containerGroups/deploy.bic protocol: 'Tcp' } ] + lock: 'CanNotDelete' systemAssignedIdentity: true userAssignedIdentities: { '/subscriptions/<>/resourcegroups/validation-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/adp-<>-az-msi-x-001': {} @@ -229,20 +249,216 @@ module containerGroups './Microsoft.ContainerInstance/containerGroups/deploy.bic "contentVersion": "1.0.0.0", "parameters": { // Required parameters - "containerName": { - "value": "<>-az-aci-x-001" - }, - "image": { - "value": "mcr.microsoft.com/azuredocs/aci-helloworld" + "containers": { + "value": [ + { + "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": { "value": "<>-az-acg-x-001" }, // Non-required parameters + "ipAddressPorts": { + "value": [ + { + "port": "80", + "protocol": "Tcp" + }, + { + "port": "443", + "protocol": "Tcp" + } + ] + }, "lock": { "value": "CanNotDelete" }, - "ports": { + "systemAssignedIdentity": { + "value": true + }, + "userAssignedIdentities": { + "value": { + "/subscriptions/<>/resourcegroups/validation-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/adp-<>-az-msi-x-001": {} + } + } + } +} +``` + +
+

+ +

Example 2: Parameters

+ +
+ +via Bicep module + +```bicep +module containerGroups './Microsoft.ContainerInstance/containerGroups/deploy.bicep' = { + name: '${uniqueString(deployment().name)}-ContainerGroups' + 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' + } + ] + 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 + } + } + } + } + ] + name: '<>-az-acg-x-001' + // Non-required parameters + ipAddressPorts: [ + { + port: '80' + protocol: 'Tcp' + } + { + port: '443' + protocol: 'Tcp' + } + { + port: '8080' + protocol: 'Tcp' + } + ] + lock: 'CanNotDelete' + systemAssignedIdentity: true + userAssignedIdentities: { + '/subscriptions/<>/resourcegroups/validation-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/adp-<>-az-msi-x-001': {} + } + } +} +``` + +
+

+ +

+ +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 + "containers": { + "value": [ + { + "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 + } + } + } + } + ] + }, + "name": { + "value": "<>-az-acg-x-001" + }, + // Non-required parameters + "ipAddressPorts": { "value": [ { "port": "80", @@ -251,9 +467,16 @@ module containerGroups './Microsoft.ContainerInstance/containerGroups/deploy.bic { "port": "443", "protocol": "Tcp" + }, + { + "port": "8080", + "protocol": "Tcp" } ] }, + "lock": { + "value": "CanNotDelete" + }, "systemAssignedIdentity": { "value": true },