|
| 1 | +param name string |
| 2 | +param location string = resourceGroup().location |
| 3 | +param tags object = {} |
| 4 | + |
| 5 | +param containerAppsEnvironmentName string |
| 6 | +param containerName string = 'main' |
| 7 | +param containerRegistryName string |
| 8 | + |
| 9 | +@description('Minimum number of replicas to run') |
| 10 | +@minValue(1) |
| 11 | +param containerMinReplicas int = 1 |
| 12 | +@description('Maximum number of replicas to run') |
| 13 | +@minValue(1) |
| 14 | +param containerMaxReplicas int = 10 |
| 15 | + |
| 16 | +param secrets array = [] |
| 17 | +param env array = [] |
| 18 | +param external bool = true |
| 19 | +param imageName string |
| 20 | +param targetPort int = 80 |
| 21 | + |
| 22 | +@description('User assigned identity name') |
| 23 | +param identityName string |
| 24 | + |
| 25 | +@description('Enabled Ingress for container app') |
| 26 | +param ingressEnabled bool = true |
| 27 | + |
| 28 | +// Dapr Options |
| 29 | +@description('Enable Dapr') |
| 30 | +param daprEnabled bool = false |
| 31 | +@description('Dapr app ID') |
| 32 | +param daprAppId string = containerName |
| 33 | +@allowed([ 'http', 'grpc' ]) |
| 34 | +@description('Protocol used by Dapr to connect to the app, e.g. http or grpc') |
| 35 | +param daprAppProtocol string = 'http' |
| 36 | + |
| 37 | +@description('CPU cores allocated to a single container instance, e.g. 0.5') |
| 38 | +param containerCpuCoreCount string = '0.5' |
| 39 | + |
| 40 | +@description('Memory allocated to a single container instance, e.g. 1Gi') |
| 41 | +param containerMemory string = '1.0Gi' |
| 42 | + |
| 43 | +@description('Workload profile name to use for the container app when using private ingress') |
| 44 | +param workloadProfileName string = 'Warm' |
| 45 | + |
| 46 | +resource userIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' existing = { |
| 47 | + name: identityName |
| 48 | +} |
| 49 | + |
| 50 | +module containerRegistryAccess '../security/registry-access.bicep' = { |
| 51 | + name: '${deployment().name}-registry-access' |
| 52 | + params: { |
| 53 | + containerRegistryName: containerRegistryName |
| 54 | + principalId: userIdentity.properties.principalId |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +resource app 'Microsoft.App/containerApps@2025-01-01' = { |
| 59 | + name: name |
| 60 | + location: location |
| 61 | + tags: tags |
| 62 | + // It is critical that the identity is granted ACR pull access before the app is created |
| 63 | + // otherwise the container app will throw a provision error |
| 64 | + // This also forces us to use an user assigned managed identity since there would no way to |
| 65 | + // provide the system assigned identity with the ACR pull access before the app is created |
| 66 | + dependsOn: [ containerRegistryAccess ] |
| 67 | + identity: { |
| 68 | + type: 'UserAssigned' |
| 69 | + userAssignedIdentities: { '${userIdentity.id}': {} } |
| 70 | + } |
| 71 | + properties: { |
| 72 | + managedEnvironmentId: containerAppsEnvironment.id |
| 73 | + configuration: { |
| 74 | + activeRevisionsMode: 'single' |
| 75 | + ingress: ingressEnabled ? { |
| 76 | + external: external |
| 77 | + targetPort: targetPort |
| 78 | + transport: 'auto' |
| 79 | + } : null |
| 80 | + dapr: daprEnabled ? { |
| 81 | + enabled: true |
| 82 | + appId: daprAppId |
| 83 | + appProtocol: daprAppProtocol |
| 84 | + appPort: ingressEnabled ? targetPort : 0 |
| 85 | + } : { enabled: false } |
| 86 | + secrets: secrets |
| 87 | + registries: [ |
| 88 | + { |
| 89 | + server: '${containerRegistry.name}.azurecr.io' |
| 90 | + identity: userIdentity.id |
| 91 | + } |
| 92 | + ] |
| 93 | + } |
| 94 | + template: { |
| 95 | + containers: [ |
| 96 | + { |
| 97 | + image: !empty(imageName) ? imageName : 'mcr.microsoft.com/azuredocs/containerapps-helloworld:latest' |
| 98 | + name: containerName |
| 99 | + env: env |
| 100 | + resources: { |
| 101 | + cpu: json(containerCpuCoreCount) |
| 102 | + memory: containerMemory |
| 103 | + } |
| 104 | + } |
| 105 | + ] |
| 106 | + scale: { |
| 107 | + minReplicas: containerMinReplicas |
| 108 | + maxReplicas: containerMaxReplicas |
| 109 | + } |
| 110 | + } |
| 111 | + } |
| 112 | +} |
| 113 | + |
| 114 | +resource containerAppsEnvironment 'Microsoft.App/managedEnvironments@2022-03-01' existing = { |
| 115 | + name: containerAppsEnvironmentName |
| 116 | +} |
| 117 | + |
| 118 | +// 2022-02-01-preview needed for anonymousPullEnabled |
| 119 | +resource containerRegistry 'Microsoft.ContainerRegistry/registries@2022-02-01-preview' existing = { |
| 120 | + name: containerRegistryName |
| 121 | +} |
| 122 | + |
| 123 | +output defaultDomain string = containerAppsEnvironment.properties.defaultDomain |
| 124 | +output imageName string = imageName |
| 125 | +output name string = app.name |
| 126 | +output hostName string = app.properties.configuration.ingress.fqdn |
| 127 | +output uri string = ingressEnabled ? 'https://${app.properties.configuration.ingress.fqdn}' : '' |
0 commit comments