@@ -259,6 +259,22 @@ func ResourceTencentCloudPostgresqlInstance() *schema.Resource {
259
259
Description : "List of backup period per week, available values: `monday`, `tuesday`, `wednesday`, `thursday`, `friday`, `saturday`, `sunday`. NOTE: At least specify two days." ,
260
260
Elem : & schema.Schema {Type : schema .TypeString },
261
261
},
262
+ "monthly_backup_retention_period" : {
263
+ Type : schema .TypeInt ,
264
+ Optional : true ,
265
+ Description : "Specify days of the retention." ,
266
+ },
267
+ "monthly_backup_period" : {
268
+ Type : schema .TypeList ,
269
+ Optional : true ,
270
+ Description : "If it is in monthly dimension, the format is numeric characters, such as [\" 1\" ,\" 2\" ]." ,
271
+ Elem : & schema.Schema {Type : schema .TypeString },
272
+ },
273
+ "monthly_plan_id" : {
274
+ Type : schema .TypeString ,
275
+ Computed : true ,
276
+ Description : "Monthly plan id." ,
277
+ },
262
278
},
263
279
},
264
280
},
@@ -715,6 +731,55 @@ func resourceTencentCloudPostgresqlInstanceCreate(d *schema.ResourceData, meta i
715
731
if err != nil {
716
732
return err
717
733
}
734
+
735
+ if v , ok := plan ["monthly_backup_period" ].([]interface {}); ok && len (v ) > 0 {
736
+ request0 := postgresql .NewCreateBaseBackupRequest ()
737
+ request0 .DBInstanceId = & instanceId
738
+
739
+ var baseBackupId * string
740
+ err := resource .Retry (tccommon .WriteRetryTimeout , func () * resource.RetryError {
741
+ resp , e := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UsePostgresqlClient ().CreateBaseBackup (request0 )
742
+ if e != nil {
743
+ return tccommon .RetryError (err , postgresql .OPERATIONDENIED_INSTANCESTATUSLIMITOPERROR )
744
+ }
745
+ baseBackupId = resp .Response .BaseBackupId
746
+ return nil
747
+ })
748
+
749
+ if err != nil {
750
+ return err
751
+ }
752
+
753
+ request1 := postgresql .NewModifyBackupPlanRequest ()
754
+ request1 .DBInstanceId = & instanceId
755
+ request1 .PlanId = baseBackupId
756
+ request1 .BackupPeriod = helper .InterfacesStringsPoint (v )
757
+
758
+ if v , ok := plan ["min_backup_start_time" ].(string ); ok && v != "" {
759
+ request1 .MinBackupStartTime = & v
760
+ }
761
+
762
+ if v , ok := plan ["max_backup_start_time" ].(string ); ok && v != "" {
763
+ request1 .MaxBackupStartTime = & v
764
+ }
765
+
766
+ if v , ok := plan ["monthly_backup_retention_period" ].(int ); ok && v != 0 {
767
+ request1 .BaseBackupRetentionPeriod = helper .IntUint64 (v )
768
+ }
769
+
770
+ err = resource .Retry (tccommon .WriteRetryTimeout , func () * resource.RetryError {
771
+ err := postgresqlService .ModifyBackupPlan (ctx , request1 )
772
+ if err != nil {
773
+ return tccommon .RetryError (err , postgresql .OPERATIONDENIED_INSTANCESTATUSLIMITOPERROR )
774
+ }
775
+
776
+ return nil
777
+ })
778
+
779
+ if err != nil {
780
+ return err
781
+ }
782
+ }
718
783
}
719
784
720
785
return resourceTencentCloudPostgresqlInstanceRead (d , meta )
@@ -923,9 +988,19 @@ func resourceTencentCloudPostgresqlInstanceRead(d *schema.ResourceData, meta int
923
988
return err
924
989
}
925
990
926
- var backupPlan * postgresql.BackupPlan
991
+ var backupPlan , monthlyBackupPlan * postgresql.BackupPlan
927
992
if len (bkpResponse ) > 0 {
928
993
backupPlan = bkpResponse [0 ]
994
+ for _ , plan := range bkpResponse {
995
+ if plan != nil && plan .BackupPeriodType != nil {
996
+ if * plan .BackupPeriodType == "month" {
997
+ monthlyBackupPlan = plan
998
+ }
999
+ if * plan .BackupPeriodType == "week" {
1000
+ backupPlan = plan
1001
+ }
1002
+ }
1003
+ }
929
1004
}
930
1005
931
1006
if backupPlan != nil {
@@ -953,6 +1028,22 @@ func resourceTencentCloudPostgresqlInstanceRead(d *schema.ResourceData, meta int
953
1028
planMap ["backup_period" ] = strSlice
954
1029
}
955
1030
1031
+ if monthlyBackupPlan != nil && monthlyBackupPlan .PlanId != nil {
1032
+ planMap ["monthly_plan_id" ] = monthlyBackupPlan .PlanId
1033
+ }
1034
+ if monthlyBackupPlan != nil && monthlyBackupPlan .BackupPeriod != nil {
1035
+ strSlice := []string {}
1036
+ err := json .Unmarshal ([]byte (* monthlyBackupPlan .BackupPeriod ), & strSlice )
1037
+ if err != nil {
1038
+ return fmt .Errorf ("BackupPeriod:[%s] has invalid format,Unmarshal failed! error: %v" , * backupPlan .BackupPeriod , err .Error ())
1039
+ }
1040
+
1041
+ planMap ["monthly_backup_period" ] = strSlice
1042
+ }
1043
+ if monthlyBackupPlan != nil && monthlyBackupPlan .BaseBackupRetentionPeriod != nil {
1044
+ planMap ["monthly_backup_retention_period" ] = monthlyBackupPlan .BaseBackupRetentionPeriod
1045
+ }
1046
+
956
1047
_ = d .Set ("backup_plan" , []interface {}{planMap })
957
1048
}
958
1049
@@ -1411,6 +1502,55 @@ func resourceTencentCloudPostgresqlInstanceUpdate(d *schema.ResourceData, meta i
1411
1502
if err != nil {
1412
1503
return err
1413
1504
}
1505
+
1506
+ request1 := postgresql .NewModifyBackupPlanRequest ()
1507
+ request1 .DBInstanceId = & instanceId
1508
+ var isDeleted bool
1509
+ if v , ok := plan ["min_backup_start_time" ].(string ); ok && v != "" {
1510
+ request1 .MinBackupStartTime = & v
1511
+ }
1512
+
1513
+ if v , ok := plan ["max_backup_start_time" ].(string ); ok && v != "" {
1514
+ request1 .MaxBackupStartTime = & v
1515
+ }
1516
+
1517
+ if v , ok := plan ["monthly_backup_retention_period" ].(int ); ok && v != 0 {
1518
+ request1 .BaseBackupRetentionPeriod = helper .IntUint64 (v )
1519
+ }
1520
+
1521
+ if v , ok := plan ["monthly_backup_period" ].([]interface {}); ok && len (v ) > 0 {
1522
+ request1 .BackupPeriod = helper .InterfacesStringsPoint (v )
1523
+ } else {
1524
+ isDeleted = true
1525
+ }
1526
+
1527
+ var monthlyPlanId string
1528
+ if v , ok := plan ["monthly_plan_id" ].(string ); ok {
1529
+ request1 .PlanId = helper .String (v )
1530
+ monthlyPlanId = v
1531
+ }
1532
+ if isDeleted && monthlyPlanId != "" {
1533
+ request0 := postgresql .NewDeleteBackupPlanRequest ()
1534
+ request0 .DBInstanceId = & instanceId
1535
+ request0 .PlanId = & monthlyPlanId
1536
+ err := resource .Retry (tccommon .WriteRetryTimeout , func () * resource.RetryError {
1537
+ _ , e := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ().UsePostgresqlClient ().DeleteBackupPlan (request0 )
1538
+ if e != nil {
1539
+ return tccommon .RetryError (e )
1540
+ }
1541
+ return nil
1542
+ })
1543
+
1544
+ if err != nil {
1545
+ return err
1546
+ }
1547
+ } else {
1548
+ err = postgresqlService .ModifyBackupPlan (ctx , request1 )
1549
+ if err != nil {
1550
+ return err
1551
+ }
1552
+ }
1553
+
1414
1554
}
1415
1555
}
1416
1556
0 commit comments