@@ -282,6 +282,30 @@ func ResourceInstance() *schema.Resource {
282282 },
283283 },
284284 },
285+ "logs_policy" : {
286+ Type : schema .TypeList ,
287+ Optional : true ,
288+ Computed : true ,
289+ Description : "Logs policy configuration" ,
290+ MaxItems : 1 ,
291+ Elem : & schema.Resource {
292+ Schema : map [string ]* schema.Schema {
293+ // Computed
294+ "max_age_retention" : {
295+ Type : schema .TypeInt ,
296+ Optional : true ,
297+ Computed : true ,
298+ Description : "The max age (in days) of remote logs to keep on the Database Instance" ,
299+ },
300+ "total_disk_retention" : {
301+ Type : schema .TypeInt ,
302+ Optional : true ,
303+ Computed : true ,
304+ Description : "The max disk size of remote logs to keep on the Database Instance." ,
305+ },
306+ },
307+ },
308+ },
285309 // Common
286310 "region" : regional .Schema (),
287311 "organization_id" : account .OrganizationIDSchema (),
@@ -349,29 +373,36 @@ func ResourceRdbInstanceCreate(ctx context.Context, d *schema.ResourceData, m in
349373
350374 d .SetId (regional .NewIDString (region , res .ID ))
351375
376+ mustUpdate := false
377+ updateReq := & rdb.UpdateInstanceRequest {
378+ Region : region ,
379+ InstanceID : res .ID ,
380+ }
352381 // Configure Schedule Backup
353382 // BackupScheduleFrequency and BackupScheduleRetention can only configure after instance creation
354383 if ! d .Get ("disable_backup" ).(bool ) {
355- updateReq := & rdb.UpdateInstanceRequest {
356- Region : region ,
357- InstanceID : res .ID ,
358- }
359-
360384 updateReq .BackupSameRegion = types .ExpandBoolPtr (d .Get ("backup_same_region" ))
361-
362385 updateReq .IsBackupScheduleDisabled = scw .BoolPtr (d .Get ("disable_backup" ).(bool ))
363386 if backupScheduleFrequency , okFrequency := d .GetOk ("backup_schedule_frequency" ); okFrequency {
364387 updateReq .BackupScheduleFrequency = scw .Uint32Ptr (uint32 (backupScheduleFrequency .(int )))
365388 }
366389 if backupScheduleRetention , okRetention := d .GetOk ("backup_schedule_retention" ); okRetention {
367390 updateReq .BackupScheduleRetention = scw .Uint32Ptr (uint32 (backupScheduleRetention .(int )))
368391 }
392+ mustUpdate = true
393+ }
369394
395+ policyRaw , exist := d .GetOk ("logs_policy" )
396+ if exist {
397+ updateReq .LogsPolicy = expandInstanceLogsPolicy (policyRaw )
398+ mustUpdate = true
399+ }
400+
401+ if mustUpdate {
370402 _ , err = waitForRDBInstance (ctx , rdbAPI , region , res .ID , d .Timeout (schema .TimeoutCreate ))
371403 if err != nil {
372404 return diag .FromErr (err )
373405 }
374-
375406 _ , err = rdbAPI .UpdateInstance (updateReq , scw .WithContext (ctx ))
376407 if err != nil {
377408 return diag .FromErr (err )
@@ -412,7 +443,6 @@ func ResourceRdbInstanceRead(ctx context.Context, d *schema.ResourceData, m inte
412443 }
413444 return diag .FromErr (err )
414445 }
415-
416446 _ = d .Set ("name" , res .Name )
417447 _ = d .Set ("node_type" , res .NodeType )
418448 _ = d .Set ("engine" , res .Engine )
@@ -476,6 +506,9 @@ func ResourceRdbInstanceRead(ctx context.Context, d *schema.ResourceData, m inte
476506 _ = d .Set ("settings" , flattenInstanceSettings (res .Settings ))
477507 _ = d .Set ("init_settings" , flattenInstanceSettings (res .InitSettings ))
478508
509+ // set logs policy
510+ _ = d .Set ("logs_policy" , flattenInstanceLogsPolicy (res .LogsPolicy ))
511+
479512 // set endpoints
480513 enableIpam , err := getIPAMConfigRead (res , m )
481514 if err != nil {
@@ -651,6 +684,13 @@ func ResourceRdbInstanceUpdate(ctx context.Context, d *schema.ResourceData, m in
651684 req .Tags = types .ExpandUpdatedStringsPtr (d .Get ("tags" ))
652685 }
653686
687+ if d .HasChange ("logs_policy" ) {
688+ policyRaw , exist := d .GetOk ("logs_policy" )
689+ if exist {
690+ req .LogsPolicy = expandInstanceLogsPolicy (policyRaw )
691+ }
692+ }
693+
654694 _ , err = waitForRDBInstance (ctx , rdbAPI , region , ID , d .Timeout (schema .TimeoutUpdate ))
655695 if err != nil {
656696 return diag .FromErr (err )
0 commit comments