@@ -365,6 +365,8 @@ func resourceProjectDelete(ctx context.Context, d *schema.ResourceData, m interf
365365	return  diags 
366366}
367367
368+ const  batchSize  =  50 
369+ 
368370func  updateDatabasesInProject (ctx  context.Context , d  * schema.ResourceData , client  api.Client , projectName  string ) diag.Diagnostics  {
369371	filter  :=  fmt .Sprintf (`project == "%s"` , projectName )
370372	databases , err  :=  client .ListDatabase (ctx , "-" , filter )
@@ -409,9 +411,14 @@ func updateDatabasesInProject(ctx context.Context, d *schema.ResourceData, clien
409411		}
410412	}
411413
412- 	if  len (batchTransferDatabases ) >  0  {
414+ 	for  i  :=  0 ; i  <  len (batchTransferDatabases ); i  +=  batchSize  {
415+ 		end  :=  i  +  batchSize 
416+ 		if  end  >  len (batchTransferDatabases ) {
417+ 			end  =  len (batchTransferDatabases )
418+ 		}
419+ 		batch  :=  batchTransferDatabases [i :end ]
413420		if  _ , err  :=  client .BatchUpdateDatabases (ctx , & v1pb.BatchUpdateDatabasesRequest {
414- 			Requests : batchTransferDatabases ,
421+ 			Requests : batch ,
415422			Parent :   "instances/-" ,
416423		}); err  !=  nil  {
417424			return  diag .Errorf ("failed to assign databases to project %s with error: %v" , projectName , err .Error ())
@@ -439,9 +446,14 @@ func updateDatabasesInProject(ctx context.Context, d *schema.ResourceData, clien
439446			})
440447		}
441448	}
442- 	if  len (unassignDatabases ) >  0  {
449+ 	for  i  :=  0 ; i  <  len (unassignDatabases ); i  +=  batchSize  {
450+ 		end  :=  i  +  batchSize 
451+ 		if  end  >  len (unassignDatabases ) {
452+ 			end  =  len (unassignDatabases )
453+ 		}
454+ 		batch  :=  unassignDatabases [i :end ]
443455		if  _ , err  :=  client .BatchUpdateDatabases (ctx , & v1pb.BatchUpdateDatabasesRequest {
444- 			Requests : unassignDatabases ,
456+ 			Requests : batch ,
445457			Parent :   "instances/-" ,
446458		}); err  !=  nil  {
447459			return  diag .Errorf ("failed to move databases to default project with error: %v" , err .Error ())
0 commit comments