@@ -14,6 +14,9 @@ param location string
1414@description ('Id of the principal to assign database and application roles.' )
1515param deploymentUserPrincipalId string = ''
1616
17+ // serviceName is used as value for the tag (azd-service-name) azd uses to identify deployment host
18+ param serviceName string = 'web'
19+
1720var resourceToken = toLower (uniqueString (resourceGroup ().id , environmentName , location ))
1821var tags = {
1922 'azd-env-name' : environmentName
@@ -87,7 +90,125 @@ module cosmosDbAccount 'br/public:avm/res/document-db/database-account:0.8.1' =
8790 }
8891}
8992
93+ module containerRegistry 'br/public:avm/res/container-registry/registry:0.5.1' = {
94+ name : 'container-registry'
95+ params : {
96+ name : 'containerreg${resourceToken }'
97+ location : location
98+ tags : tags
99+ acrAdminUserEnabled : false
100+ anonymousPullEnabled : true
101+ publicNetworkAccess : 'Enabled'
102+ acrSku : 'Standard'
103+ }
104+ }
105+
106+ var containerRegistryRole = subscriptionResourceId (
107+ 'Microsoft.Authorization/roleDefinitions' ,
108+ '8311e382-0749-4cb8-b61a-304f252e45ec'
109+ ) // AcrPush built-in role
110+
111+ module registryUserAssignment 'br/public:avm/ptn/authorization/resource-role-assignment:0.1.1' = if (!empty (deploymentUserPrincipalId )) {
112+ name : 'container-registry-role-assignment-push-user'
113+ params : {
114+ principalId : deploymentUserPrincipalId
115+ resourceId : containerRegistry .outputs .resourceId
116+ roleDefinitionId : containerRegistryRole
117+ }
118+ }
119+
120+ module logAnalyticsWorkspace 'br/public:avm/res/operational-insights/workspace:0.7.0' = {
121+ name : 'log-analytics-workspace'
122+ params : {
123+ name : 'log-analytics-${resourceToken }'
124+ location : location
125+ tags : tags
126+ }
127+ }
128+
129+ module containerAppsEnvironment 'br/public:avm/res/app/managed-environment:0.8.0' = {
130+ name : 'container-apps-env'
131+ params : {
132+ name : 'container-env-${resourceToken }'
133+ location : location
134+ tags : tags
135+ logAnalyticsWorkspaceResourceId : logAnalyticsWorkspace .outputs .resourceId
136+ zoneRedundant : false
137+ }
138+ }
139+
140+ module containerAppsApp 'br/public:avm/res/app/container-app:0.9.0' = {
141+ name : 'container-apps-app'
142+ params : {
143+ name : 'container-app-${resourceToken }'
144+ environmentResourceId : containerAppsEnvironment .outputs .resourceId
145+ location : location
146+ tags : union (tags , { 'azd-service-name' : serviceName })
147+ ingressTargetPort : 3030
148+ ingressExternal : true
149+ ingressTransport : 'auto'
150+ stickySessionsAffinity : 'sticky'
151+ scaleMaxReplicas : 1
152+ scaleMinReplicas : 1
153+ corsPolicy : {
154+ allowCredentials : true
155+ allowedOrigins : [
156+ '*'
157+ ]
158+ }
159+ managedIdentities : {
160+ systemAssigned : false
161+ userAssignedResourceIds : [
162+ managedIdentity .outputs .resourceId
163+ ]
164+ }
165+ secrets : {
166+ secureList : [
167+ {
168+ name : 'azure-cosmos-db-nosql-endpoint'
169+ value : cosmosDbAccount .outputs .endpoint
170+ }
171+ {
172+ name : 'user-assigned-managed-identity-client-id'
173+ value : managedIdentity .outputs .clientId
174+ }
175+ ]
176+ }
177+ containers : [
178+ {
179+ image : 'mcr.microsoft.com/azuredocs/containerapps-helloworld:latest'
180+ name : 'web-front-end'
181+ resources : {
182+ cpu : '0.25'
183+ memory : '.5Gi'
184+ }
185+ env : [
186+ {
187+ name : 'CONFIGURATION__AZURECOSMOSDB__ENDPOINT'
188+ secretRef : 'azure-cosmos-db-nosql-endpoint'
189+ }
190+ {
191+ name : 'CONFIGURATION__AZURECOSMOSDB__DATABASENAME'
192+ value : databaseName
193+ }
194+ {
195+ name : 'CONFIGURATION__AZURECOSMOSDB__CONTAINERNAME'
196+ value : containerName
197+ }
198+ {
199+ name : 'AZURE_CLIENT_ID'
200+ secretRef : 'user-assigned-managed-identity-client-id'
201+ }
202+ ]
203+ }
204+ ]
205+ }
206+ }
207+
90208// Azure Cosmos DB for Table outputs
91209output CONFIGURATION__AZURECOSMOSDB__ENDPOINT string = cosmosDbAccount .outputs .endpoint
92210output CONFIGURATION__AZURECOSMOSDB__DATABASENAME string = databaseName
93211output CONFIGURATION__AZURECOSMOSDB__CONTAINERNAME string = containerName
212+
213+ // Azure Container Registry outputs
214+ output AZURE_CONTAINER_REGISTRY_ENDPOINT string = containerRegistry .outputs .loginServer
0 commit comments