@@ -259,7 +259,10 @@ func (c *external) Create(ctx context.Context, mg resource.Managed) (managed.Ext
259
259
}
260
260
261
261
ro := resourceOptionsToClauses (cr .Spec .ForProvider .ResourceOptions )
262
- if err := c .executeCreateUserQuery (ctx , username , host , ro , pw ); err != nil {
262
+
263
+ authplugin := cr .Spec .ForProvider .AuthPlugin
264
+
265
+ if err := c .executeCreateUserQuery (ctx , username , host , ro , pw , authplugin ); err != nil {
263
266
return managed.ExternalCreation {}, err
264
267
}
265
268
@@ -272,17 +275,30 @@ func (c *external) Create(ctx context.Context, mg resource.Managed) (managed.Ext
272
275
}, nil
273
276
}
274
277
275
- func (c * external ) executeCreateUserQuery (ctx context.Context , username string , host string , resourceOptionsClauses []string , pw string ) error {
278
+ func (c * external ) executeCreateUserQuery (ctx context.Context , username string , host string , resourceOptionsClauses []string , pw string , authplugin string ) error {
276
279
resourceOptions := ""
277
280
if len (resourceOptionsClauses ) != 0 {
278
281
resourceOptions = fmt .Sprintf (" WITH %s" , strings .Join (resourceOptionsClauses , " " ))
279
282
}
280
283
284
+ var authStm string
285
+
286
+ if len (authplugin ) > 0 {
287
+ switch authplugin {
288
+ case "mysql_native_password" , "caching_sha2_password" :
289
+ authStm = fmt .Sprintf ("WITH %s BY %s" , authplugin , mysql .QuoteValue (pw ))
290
+ case "AWSAuthenticationPlugin" :
291
+ authStm = fmt .Sprintf ("WITH %s AS %s" , authplugin , mysql .QuoteValue ("RDS" ))
292
+ }
293
+ } else {
294
+ authStm = fmt .Sprintf ("BY %s" , mysql .QuoteValue (pw ))
295
+ }
296
+
281
297
query := fmt .Sprintf (
282
- "CREATE USER %s@%s IDENTIFIED BY %s%s" ,
298
+ "CREATE USER %s@%s IDENTIFIED %s%s" ,
283
299
mysql .QuoteValue (username ),
284
300
mysql .QuoteValue (host ),
285
- mysql . QuoteValue ( pw ) ,
301
+ authStm ,
286
302
resourceOptions ,
287
303
)
288
304
0 commit comments