@@ -19,11 +19,8 @@ param postgresDatabaseName string
19
19
param postgresDatabasePassword string
20
20
{{- end}}
21
21
{{- if .DbMySql}}
22
- param mysqlDatabaseHost string
23
- param mysqlDatabaseUser string
24
- param mysqlDatabaseName string
25
- @secure()
26
- param mysqlDatabasePassword string
22
+ param mysqlDatabaseId string
23
+ param mysqlIdentityName string
27
24
{{- end}}
28
25
{{- if .DbRedis}}
29
26
param redisName string
@@ -153,12 +150,6 @@ resource app 'Microsoft.App/containerApps@2023-05-02-preview' = {
153
150
value: postgresDatabasePassword
154
151
}
155
152
{{- end}}
156
- {{- if .DbMySql}}
157
- {
158
- name: 'mysql-db-pass'
159
- value: mysqlDatabasePassword
160
- }
161
- {{- end}}
162
153
],
163
154
map(secrets, secret => {
164
155
name: secret.secretRef
@@ -203,28 +194,6 @@ resource app 'Microsoft.App/containerApps@2023-05-02-preview' = {
203
194
value: '5432'
204
195
}
205
196
{{- end}}
206
- {{- if .DbMySql}}
207
- {
208
- name: 'MYSQL_HOST'
209
- value: mysqlDatabaseHost
210
- }
211
- {
212
- name: 'MYSQL_USERNAME'
213
- value: mysqlDatabaseUser
214
- }
215
- {
216
- name: 'MYSQL_DATABASE'
217
- value: mysqlDatabaseName
218
- }
219
- {
220
- name: 'MYSQL_PASSWORD'
221
- secretRef: 'mysql-db-pass'
222
- }
223
- {
224
- name: 'MYSQL_PORT'
225
- value: '3306'
226
- }
227
- {{- end}}
228
197
{{- if .Frontend}}
229
198
{{- range $i, $e := .Frontend.Backends}}
230
199
{
@@ -266,6 +235,44 @@ resource app 'Microsoft.App/containerApps@2023-05-02-preview' = {
266
235
}
267
236
}
268
237
}
238
+ {{- if .DbMySql}}
239
+
240
+ resource linkerCreatorIdentity 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = {
241
+ name: 'linkerCreatorIdentity'
242
+ location: location
243
+ }
244
+
245
+ resource linkerCreatorRole 'Microsoft.Authorization/roleAssignments@2022-04-01' = {
246
+ scope: resourceGroup()
247
+ name: guid(subscription().id, resourceGroup().id, linkerCreatorIdentity.id, 'linkerCreatorRole')
248
+ properties: {
249
+ roleDefinitionId: subscriptionResourceId(
250
+ 'Microsoft.Authorization/roleDefinitions', 'b24988ac-6180-42a0-ab88-20f7382dd24c')
251
+ principalType: 'ServicePrincipal'
252
+ principalId: linkerCreatorIdentity.properties.principalId
253
+ }
254
+ }
255
+
256
+ resource appLinkToMySql 'Microsoft.Resources/deploymentScripts@2023-08-01' = {
257
+ dependsOn: [ linkerCreatorRole ]
258
+ name: 'appLinkToMySql'
259
+ location: location
260
+ kind: 'AzureCLI'
261
+ identity: {
262
+ type: 'UserAssigned'
263
+ userAssignedIdentities: {
264
+ '${linkerCreatorIdentity.id}': {}
265
+ }
266
+ }
267
+ properties: {
268
+ azCliVersion: '2.63.0'
269
+ timeout: 'PT10M'
270
+ scriptContent: 'apk update; apk add g++; apk add unixodbc-dev; az extension add --name containerapp; az extension add --name serviceconnector-passwordless --upgrade; az containerapp connection create mysql-flexible --connection appLinkToMySql --source-id ${app.id} --target-id ${mysqlDatabaseId} --client-type springBoot --user-identity client-id=${identity.properties.clientId} subs-id=${subscription().subscriptionId} user-object-id=${linkerCreatorIdentity.properties.principalId} mysql-identity-id=${mysqlIdentityName} -c main --yes; az tag create --resource-id ${app.id} --tags azd-service-name={{.Name}} '
271
+ cleanupPreference: 'OnSuccess'
272
+ retentionInterval: 'P1D'
273
+ }
274
+ }
275
+ {{- end}}
269
276
270
277
output defaultDomain string = containerAppsEnvironment.properties.defaultDomain
271
278
output name string = app.name
0 commit comments