@@ -9,69 +9,75 @@ param allowedOrigins array = []
9
9
@description ('Name of the environment for container apps' )
10
10
param containerAppsEnvironmentName string
11
11
12
+ @description ('CPU cores allocated to a single container instance, e.g., 0.5' )
13
+ param containerCpuCoreCount string = '0.5'
14
+
15
+ @description ('The maximum number of replicas to run. Must be at least 1.' )
16
+ @minValue (1 )
17
+ param containerMaxReplicas int = 10
18
+
19
+ @description ('Memory allocated to a single container instance, e.g., 1Gi' )
20
+ param containerMemory string = '1.0Gi'
21
+
22
+ @description ('The minimum number of replicas to run. Must be at least 1.' )
23
+ param containerMinReplicas int = 1
24
+
12
25
@description ('The name of the container' )
13
26
param containerName string = 'main'
14
27
15
28
@description ('The name of the container registry' )
16
- param containerRegistryName string
29
+ param containerRegistryName string = ''
17
30
18
31
@description ('Hostname suffix for container registry. Set when deploying to sovereign clouds' )
19
32
param containerRegistryHostSuffix string = 'azurecr.io'
20
33
21
- @description ('Minimum number of replicas to run' )
22
- @minValue (1 )
23
- param containerMinReplicas int = 1
24
- @description ('Maximum number of replicas to run' )
25
- @minValue (1 )
26
- param containerMaxReplicas int = 10
34
+ @description ('The protocol used by Dapr to connect to the app, e.g., http or grpc' )
35
+ @allowed ([ 'http' , 'grpc' ])
36
+ param daprAppProtocol string = 'http'
27
37
28
- @description ('The secrets required for the container' )
29
- @secure ()
30
- param secrets object = {}
38
+ @description ('The Dapr app ID' )
39
+ param daprAppId string = containerName
40
+
41
+ @description ('Enable Dapr' )
42
+ param daprEnabled bool = false
31
43
32
44
@description ('The environment variables for the container' )
33
45
param env array = []
34
46
35
47
@description ('Specifies if the resource ingress is exposed externally' )
36
48
param external bool = true
37
49
38
- @description ('User assigned identity name ' )
39
- param identityName string
50
+ @description ('The name of the user- assigned identity' )
51
+ param identityName string = ''
40
52
41
53
@description ('The type of identity for the resource' )
42
54
@allowed ([ 'None' , 'SystemAssigned' , 'UserAssigned' ])
43
55
param identityType string = 'None'
44
56
45
57
@description ('The name of the container image' )
46
- param imageName string
58
+ param imageName string = ''
47
59
48
- @description ('Enabled Ingress for container app' )
60
+ @description ('Specifies if Ingress is enabled for the container app' )
49
61
param ingressEnabled bool = true
50
62
51
63
param revisionMode string = 'Single'
52
64
53
- @description ('The target port for the container' )
54
- param targetPort int = 80
65
+ @description ('The secrets required for the container' )
66
+ @secure ()
67
+ param secrets object = {}
55
68
56
- // Dapr Options
57
- @description ('Enable Dapr' )
58
- param daprEnabled bool = false
59
- @description ('Dapr app ID' )
60
- param daprAppId string = containerName
61
- @allowed ([ 'http' , 'grpc' ])
62
- @description ('Protocol used by Dapr to connect to the app, e.g. http or grpc' )
63
- param daprAppProtocol string = 'http'
69
+ @description ('The keyvault identities required for the container' )
70
+ @secure ()
71
+ param keyvaultIdentities object = {}
64
72
65
- @description ('CPU cores allocated to a single container instance, e.g. 0.5 ' )
66
- param containerCpuCoreCount string = '0.5'
73
+ @description ('The service binds associated with the container' )
74
+ param serviceBinds array = []
67
75
68
- @description ('Memory allocated to a single container instance, e.g. 1Gi ' )
69
- param containerMemory string = '1.0Gi '
76
+ @description ('The name of the container apps add-on to use. e.g. redis ' )
77
+ param serviceType string = ''
70
78
71
- var keyvalueSecrets = [for secret in items (secrets ): {
72
- name : secret .key
73
- value : secret .value
74
- }]
79
+ @description ('The target port for the container' )
80
+ param targetPort int = 80
75
81
76
82
resource userIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' existing = if (!empty (identityName )) {
77
83
name : identityName
@@ -83,6 +89,17 @@ var usePrivateRegistry = !empty(identityName) && !empty(containerRegistryName)
83
89
// Automatically set to `UserAssigned` when an `identityName` has been set
84
90
var normalizedIdentityType = !empty (identityName ) ? 'UserAssigned' : identityType
85
91
92
+ var keyvalueSecrets = [for secret in items (secrets ): {
93
+ name : secret .key
94
+ value : secret .value
95
+ }]
96
+
97
+ var keyvaultIdentitySecrets = [for secret in items (keyvaultIdentities ): {
98
+ name : secret .key
99
+ keyVaultUrl : secret .value .keyVaultUrl
100
+ identity : secret .value .identity
101
+ }]
102
+
86
103
module containerRegistryAccess '../security/registry-access.bicep' = if (usePrivateRegistry ) {
87
104
name : '${deployment ().name }-registry-access'
88
105
params : {
@@ -92,7 +109,7 @@ module containerRegistryAccess '../security/registry-access.bicep' = if (usePriv
92
109
}
93
110
94
111
resource app 'Microsoft.App/containerApps@2023-05-02-preview' = {
95
- name : name
112
+ name : name
96
113
location : location
97
114
tags : tags
98
115
// It is critical that the identity is granted ACR pull access before the app is created
@@ -122,7 +139,8 @@ name: name
122
139
appProtocol : daprAppProtocol
123
140
appPort : ingressEnabled ? targetPort : 0
124
141
} : { enabled : false }
125
- secrets : keyvalueSecrets
142
+ secrets : concat (keyvalueSecrets , keyvaultIdentitySecrets )
143
+ service : !empty (serviceType ) ? { type : serviceType } : null
126
144
registries : usePrivateRegistry ? [
127
145
{
128
146
server : '${containerRegistryName }.${containerRegistryHostSuffix }'
@@ -131,6 +149,7 @@ name: name
131
149
] : []
132
150
}
133
151
template : {
152
+ serviceBinds : !empty (serviceBinds ) ? serviceBinds : null
134
153
containers : [
135
154
{
136
155
image : !empty (imageName ) ? imageName : 'mcr.microsoft.com/azuredocs/containerapps-helloworld:latest'
@@ -155,9 +174,10 @@ resource containerAppsEnvironment 'Microsoft.App/managedEnvironments@2023-05-01'
155
174
}
156
175
157
176
output defaultDomain string = containerAppsEnvironment .properties .defaultDomain
158
- output identityPrincipalId string = userIdentity .properties .principalId
159
- output identityResourceId string = resourceId ('Microsoft.ManagedIdentity/userAssignedIdentities' , userIdentity .name )
177
+ output identityPrincipalId string = normalizedIdentityType == 'None' ? '' : ( empty ( identityName ) ? app . identity . principalId : userIdentity .properties .principalId )
178
+ output identityResourceId string = normalizedIdentityType == 'UserAssigned' ? resourceId ('Microsoft.ManagedIdentity/userAssignedIdentities' , userIdentity .name ) : ''
160
179
output imageName string = imageName
161
180
output name string = app .name
181
+ output serviceBind object = !empty (serviceType ) ? { serviceId : app .id , name : name } : {}
162
182
output uri string = ingressEnabled ? 'https://${app .properties .configuration .ingress .fqdn }' : ''
163
183
output id string = app .id
0 commit comments