@@ -215,6 +215,24 @@ func ResourceInstance() *schema.Resource {
215215 },
216216 Description : "List of tags [\" tag1\" , \" tag2\" , ...] attached to a MongoDB instance" ,
217217 },
218+ "snapshot_schedule_frequency_hours" : {
219+ Type : schema .TypeInt ,
220+ Optional : true ,
221+ Computed : true ,
222+ Description : "Snapshot schedule frequency in hours" ,
223+ },
224+ "snapshot_schedule_retention_days" : {
225+ Type : schema .TypeInt ,
226+ Optional : true ,
227+ Computed : true ,
228+ Description : "Snapshot schedule retention in days" ,
229+ },
230+ "is_snapshot_schedule_enabled" : {
231+ Type : schema .TypeBool ,
232+ Optional : true ,
233+ Computed : true ,
234+ Description : "Enable or disable automatic snapshot scheduling" ,
235+ },
218236 "settings" : {
219237 Type : schema .TypeMap ,
220238 Description : "Map of settings to define for the instance." ,
@@ -367,6 +385,40 @@ func ResourceInstanceCreate(ctx context.Context, d *schema.ResourceData, m any)
367385 return diag .FromErr (err )
368386 }
369387
388+ // Configure snapshot scheduling after instance creation
389+ mustUpdate := false
390+ updateReq := & mongodb.UpdateInstanceRequest {
391+ Region : region ,
392+ InstanceID : res .ID ,
393+ }
394+
395+ if snapshotFrequency , ok := d .GetOk ("snapshot_schedule_frequency_hours" ); ok {
396+ updateReq .SnapshotScheduleFrequencyHours = scw .Uint32Ptr (uint32 (snapshotFrequency .(int )))
397+ mustUpdate = true
398+ }
399+
400+ if snapshotRetention , ok := d .GetOk ("snapshot_schedule_retention_days" ); ok {
401+ updateReq .SnapshotScheduleRetentionDays = scw .Uint32Ptr (uint32 (snapshotRetention .(int )))
402+ mustUpdate = true
403+ }
404+
405+ if snapshotEnabled , ok := d .GetOk ("is_snapshot_schedule_enabled" ); ok {
406+ updateReq .IsSnapshotScheduleEnabled = scw .BoolPtr (snapshotEnabled .(bool ))
407+ mustUpdate = true
408+ }
409+
410+ if mustUpdate {
411+ _ , err = mongodbAPI .UpdateInstance (updateReq , scw .WithContext (ctx ))
412+ if err != nil {
413+ return diag .FromErr (err )
414+ }
415+
416+ _ , err = waitForInstance (ctx , mongodbAPI , res .Region , res .ID , d .Timeout (schema .TimeoutCreate ))
417+ if err != nil {
418+ return diag .FromErr (err )
419+ }
420+ }
421+
370422 return ResourceInstanceRead (ctx , d , m )
371423}
372424
@@ -401,6 +453,12 @@ func ResourceInstanceRead(ctx context.Context, d *schema.ResourceData, m any) di
401453 _ = d .Set ("created_at" , instance .CreatedAt .Format (time .RFC3339 ))
402454 _ = d .Set ("region" , instance .Region .String ())
403455
456+ if instance .SnapshotSchedule != nil {
457+ _ = d .Set ("snapshot_schedule_frequency_hours" , int (instance .SnapshotSchedule .FrequencyHours ))
458+ _ = d .Set ("snapshot_schedule_retention_days" , int (instance .SnapshotSchedule .RetentionDays ))
459+ _ = d .Set ("is_snapshot_schedule_enabled" , instance .SnapshotSchedule .Enabled )
460+ }
461+
404462 if instance .Volume != nil {
405463 _ = d .Set ("volume_type" , instance .Volume .Type )
406464 _ = d .Set ("volume_size_in_gb" , int (instance .Volume .SizeBytes / scw .GB ))
@@ -553,6 +611,21 @@ func ResourceInstanceUpdate(ctx context.Context, d *schema.ResourceData, m any)
553611 }
554612 }
555613
614+ if d .HasChange ("snapshot_schedule_frequency_hours" ) {
615+ req .SnapshotScheduleFrequencyHours = types .ExpandUint32Ptr (d .Get ("snapshot_schedule_frequency_hours" ))
616+ shouldUpdateInstance = true
617+ }
618+
619+ if d .HasChange ("snapshot_schedule_retention_days" ) {
620+ req .SnapshotScheduleRetentionDays = types .ExpandUint32Ptr (d .Get ("snapshot_schedule_retention_days" ))
621+ shouldUpdateInstance = true
622+ }
623+
624+ if d .HasChange ("is_snapshot_schedule_enabled" ) {
625+ req .IsSnapshotScheduleEnabled = types .ExpandBoolPtr (d .Get ("is_snapshot_schedule_enabled" ))
626+ shouldUpdateInstance = true
627+ }
628+
556629 if shouldUpdateInstance {
557630 _ , err = mongodbAPI .UpdateInstance (req , scw .WithContext (ctx ))
558631 if err != nil {
0 commit comments