Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add new ptn modules avm/ptn/azd/acr-container-app #3234

Merged
merged 12 commits into from
Oct 11, 2024
73 changes: 49 additions & 24 deletions avm/ptn/azd/container-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@ Creates a container app in an Azure Container App environment.
| `Microsoft.App/containerApps` | [2024-03-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.App/2024-03-01/containerApps) |
| `Microsoft.Authorization/locks` | [2020-05-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Authorization/2020-05-01/locks) |
| `Microsoft.Authorization/roleAssignments` | [2022-04-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Authorization/2022-04-01/roleAssignments) |
| `Microsoft.ContainerRegistry/registries` | [2023-06-01-preview](https://learn.microsoft.com/en-us/azure/templates/Microsoft.ContainerRegistry/registries) |
| `Microsoft.ContainerRegistry/registries/cacheRules` | [2023-06-01-preview](https://learn.microsoft.com/en-us/azure/templates/Microsoft.ContainerRegistry/registries/cacheRules) |
| `Microsoft.ContainerRegistry/registries/credentialSets` | [2023-11-01-preview](https://learn.microsoft.com/en-us/azure/templates/Microsoft.ContainerRegistry/registries/credentialSets) |
| `Microsoft.ContainerRegistry/registries/replications` | [2023-06-01-preview](https://learn.microsoft.com/en-us/azure/templates/Microsoft.ContainerRegistry/registries/replications) |
| `Microsoft.ContainerRegistry/registries/scopeMaps` | [2023-06-01-preview](https://learn.microsoft.com/en-us/azure/templates/Microsoft.ContainerRegistry/registries/scopeMaps) |
| `Microsoft.ContainerRegistry/registries/webhooks` | [2023-06-01-preview](https://learn.microsoft.com/en-us/azure/templates/Microsoft.ContainerRegistry/registries/webhooks) |
| `Microsoft.Insights/diagnosticSettings` | [2021-05-01-preview](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Insights/2021-05-01-preview/diagnosticSettings) |
| `Microsoft.Network/privateEndpoints` | [2023-04-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Network/2023-04-01/privateEndpoints) |
| `Microsoft.Network/privateEndpoints/privateDnsZoneGroups` | [2023-04-01](https://learn.microsoft.com/en-us/azure/templates/Microsoft.Network/2023-04-01/privateEndpoints/privateDnsZoneGroups) |

## Usage examples

Expand All @@ -52,8 +43,8 @@ module containerApp 'br/public:avm/ptn/azd/container-app:<version>' = {
name: 'containerAppDeployment'
params: {
// Required parameters
containerAppName: 'acamin001'
containerAppsEnvironmentName: '<containerAppsEnvironmentName>'
name: 'acamin001'
// Non-required parameters
location: '<location>'
}
Expand All @@ -73,12 +64,12 @@ module containerApp 'br/public:avm/ptn/azd/container-app:<version>' = {
"contentVersion": "1.0.0.0",
"parameters": {
// Required parameters
"containerAppName": {
"value": "acamin001"
},
"containerAppsEnvironmentName": {
"value": "<containerAppsEnvironmentName>"
},
"name": {
"value": "acamin001"
},
// Non-required parameters
"location": {
"value": "<location>"
Expand All @@ -96,8 +87,8 @@ module containerApp 'br/public:avm/ptn/azd/container-app:<version>' = {

| Parameter | Type | Description |
| :-- | :-- | :-- |
| [`containerAppName`](#parameter-containerappname) | string | The name of the Container App. |
| [`containerAppsEnvironmentName`](#parameter-containerappsenvironmentname) | string | Name of the environment for container apps. |
| [`name`](#parameter-name) | string | The name of the Container App. |

**Optional parameters**

Expand Down Expand Up @@ -133,18 +124,18 @@ module containerApp 'br/public:avm/ptn/azd/container-app:<version>' = {
| [`serviceType`](#parameter-servicetype) | string | The name of the container apps add-on to use. e.g. redis. |
| [`tags`](#parameter-tags) | object | Tags of the resource. |
| [`targetPort`](#parameter-targetport) | int | The target port for the container. |
| [`userIdentityId`](#parameter-useridentityid) | string | The id of the user identity. |
| [`userAssignedIdentityResourceId`](#parameter-userassignedidentityresourceid) | string | The resource id of the user-assigned identity. |

### Parameter: `containerAppName`
### Parameter: `containerAppsEnvironmentName`

The name of the Container App.
Name of the environment for container apps.

- Required: Yes
- Type: string

### Parameter: `containerAppsEnvironmentName`
### Parameter: `name`

Name of the environment for container apps.
The name of the Container App.

- Required: Yes
- Type: string
Expand Down Expand Up @@ -258,7 +249,40 @@ The environment variables for the container.

- Required: No
- Type: array
- Default: `[]`

**Required parameters**

| Parameter | Type | Description |
| :-- | :-- | :-- |
| [`name`](#parameter-envname) | string | Environment variable name. |

**Optional parameters**

| Parameter | Type | Description |
| :-- | :-- | :-- |
| [`secretRef`](#parameter-envsecretref) | string | Name of the Container App secret from which to pull the environment variable value. |
| [`value`](#parameter-envvalue) | string | Non-secret environment variable value. |

### Parameter: `env.name`

Environment variable name.

- Required: Yes
- Type: string

### Parameter: `env.secretRef`

Name of the Container App secret from which to pull the environment variable value.

- Required: No
- Type: string

### Parameter: `env.value`

Non-secret environment variable value.

- Required: No
- Type: string

### Parameter: `external`

Expand Down Expand Up @@ -419,9 +443,9 @@ The target port for the container.
- Type: int
- Default: `80`

### Parameter: `userIdentityId`
### Parameter: `userAssignedIdentityResourceId`

The id of the user identity.
The resource id of the user-assigned identity.

- Required: No
- Type: string
Expand All @@ -431,11 +455,12 @@ The id of the user identity.

| Output | Type | Description |
| :-- | :-- | :-- |
| `containerAppName` | string | The name of the Container App. |
| `defaultDomain` | string | The Default domain of the Managed Environment. |
| `identityPrincipalId` | string | The principal ID of the identity. |
| `imageName` | string | The name of the container image. |
| `name` | string | The name of the Container App. |
| `resourceGroupName` | string | The name of the resource group the Container App was deployed into. |
| `resourceId` | string | The resource ID of the Container App. |
| `serviceBind` | object | The service binds associated with the container. |
| `uri` | string | The uri of the Container App. |

Expand All @@ -445,8 +470,8 @@ This section gives you an overview of all local-referenced module files (i.e., o

| Reference | Type |
| :-- | :-- |
| `br/public:avm/ptn/authorization/resource-role-assignment:0.1.1` | Remote reference |
| `br/public:avm/res/app/container-app:0.10.0` | Remote reference |
| `br/public:avm/res/container-registry/registry:0.4.0` | Remote reference |

## Data Collection

Expand Down
32 changes: 23 additions & 9 deletions avm/ptn/azd/container-app/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ metadata description = 'Creates a container app in an Azure Container App enviro
metadata owner = 'Azure/module-maintainers'

@description('Required. The name of the Container App.')
param containerAppName string
param name string

@description('Optional. Location for all Resources.')
param location string = resourceGroup().location
Expand Down Expand Up @@ -50,7 +50,7 @@ param daprAppId string = containerName
param daprEnabled bool = false

@description('Optional. The environment variables for the container.')
param env array = []
param env environmentVar[]?

@description('Optional. Specifies if the resource ingress is exposed externally.')
param external bool = true
Expand Down Expand Up @@ -109,8 +109,8 @@ param includeAddOns bool = false
@description('Optional. The principal ID of the principal to assign the role to.')
param principalId string = ''

@description('Optional. The id of the user identity.')
param userIdentityId string = ''
@description('Optional. The resource id of the user-assigned identity.')
param userAssignedIdentityResourceId string = ''

@description('Optional. Enable/Disable usage telemetry for module.')
param enableTelemetry bool = true
Expand Down Expand Up @@ -143,11 +143,11 @@ resource avmTelemetry 'Microsoft.Resources/deployments@2024-03-01' = if (enableT
module containerApp 'br/public:avm/res/app/container-app:0.10.0' = {
name: '${uniqueString(deployment().name, location)}-container-app'
params: {
name: containerAppName
name: name
location: location
tags: tags
managedIdentities: !empty(identityName) && normalizedIdentityType == 'UserAssigned'
? { userAssignedResourceIds: [userIdentityId] }
? { userAssignedResourceIds: [userAssignedIdentityResourceId] }
: { systemAssigned: normalizedIdentityType == 'SystemAssigned' }
environmentResourceId: containerAppsEnvironment.id
activeRevisionsMode: revisionMode
Expand Down Expand Up @@ -175,7 +175,7 @@ module containerApp 'br/public:avm/res/app/container-app:0.10.0' = {
? [
{
server: '${containerRegistryName}.${containerRegistryHostSuffix}'
identity: userIdentityId
identity: userAssignedIdentityResourceId
}
]
: []
Expand All @@ -200,7 +200,7 @@ module containerApp 'br/public:avm/res/app/container-app:0.10.0' = {
module containerRegistryAccess 'modules/registry-access.bicep' = if (usePrivateRegistry) {
name: '${uniqueString(deployment().name, location)}-registry-access'
params: {
name: containerRegistryName
containerRegistryName: containerRegistryName
principalId: usePrivateRegistry ? principalId : ''
}
}
Expand All @@ -224,7 +224,7 @@ output identityPrincipalId string = normalizedIdentityType == 'None'
output imageName string = imageName

@description('The name of the Container App.')
output containerAppName string = containerApp.outputs.name
output name string = containerApp.outputs.name

@description('The service binds associated with the container.')
output serviceBind object = !empty(serviceType)
Expand All @@ -233,3 +233,17 @@ output serviceBind object = !empty(serviceType)

@description('The uri of the Container App.')
output uri string = ingressEnabled ? 'https://${containerApp.outputs.fqdn}' : ''

@description('The resource ID of the Container App.')
output resourceId string = containerApp.outputs.resourceId

type environmentVar = {
NanaXiong00 marked this conversation as resolved.
Show resolved Hide resolved
@description('Required. Environment variable name.')
name: string

@description('Optional. Name of the Container App secret from which to pull the environment variable value.')
secretRef: string?

@description('Optional. Non-secret environment variable value.')
value: string?
}
Loading