Skip to content

Commit 6290725

Browse files
authored
fix(postgresql): [120432972] tencentcloud_postgresql_instance update field properties for backup_plan (#2921)
* add * add * add
1 parent a5d4fd1 commit 6290725

File tree

4 files changed

+40
-32
lines changed

4 files changed

+40
-32
lines changed

.changelog/2921.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_postgresql_instance: update field properties for `backup_plan`
3+
```

tencentcloud/services/postgresql/resource_tc_postgresql_instance.go

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -230,28 +230,33 @@ func ResourceTencentCloudPostgresqlInstance() *schema.Resource {
230230
"backup_plan": {
231231
Type: schema.TypeList,
232232
Optional: true,
233+
Computed: true,
233234
Description: "Specify DB backup plan.",
234235
MaxItems: 1,
235236
Elem: &schema.Resource{
236237
Schema: map[string]*schema.Schema{
237238
"min_backup_start_time": {
238239
Type: schema.TypeString,
239240
Optional: true,
241+
Computed: true,
240242
Description: "Specify earliest backup start time, format `hh:mm:ss`.",
241243
},
242244
"max_backup_start_time": {
243245
Type: schema.TypeString,
244246
Optional: true,
247+
Computed: true,
245248
Description: "Specify latest backup start time, format `hh:mm:ss`.",
246249
},
247250
"base_backup_retention_period": {
248251
Type: schema.TypeInt,
249252
Optional: true,
253+
Computed: true,
250254
Description: "Specify days of the retention.",
251255
},
252256
"backup_period": {
253257
Type: schema.TypeList,
254258
Optional: true,
259+
Computed: true,
255260
Description: "List of backup period per week, available values: `monday`, `tuesday`, `wednesday`, `thursday`, `friday`, `saturday`, `sunday`. NOTE: At least specify two days.",
256261
Elem: &schema.Schema{Type: schema.TypeString},
257262
},
@@ -906,46 +911,44 @@ func resourceTencentCloudPostgresqlInstanceRead(d *schema.ResourceData, meta int
906911
_ = d.Set("tags", tags)
907912

908913
// backup plans (only specified will rewrite)
909-
if _, ok := d.GetOk("backup_plan"); ok {
910-
request := postgresql.NewDescribeBackupPlansRequest()
911-
request.DBInstanceId = helper.String(d.Id())
912-
response, err := postgresqlService.DescribeBackupPlans(ctx, request)
913-
if err != nil {
914-
return err
915-
}
916-
917-
var backupPlan *postgresql.BackupPlan
918-
if len(response) > 0 {
919-
backupPlan = response[0]
920-
}
914+
bkpRequest := postgresql.NewDescribeBackupPlansRequest()
915+
bkpRequest.DBInstanceId = helper.String(d.Id())
916+
bkpResponse, err := postgresqlService.DescribeBackupPlans(ctx, bkpRequest)
917+
if err != nil {
918+
return err
919+
}
921920

922-
if backupPlan != nil {
923-
planMap := map[string]interface{}{}
924-
if backupPlan.MinBackupStartTime != nil {
925-
planMap["min_backup_start_time"] = backupPlan.MinBackupStartTime
926-
}
921+
var backupPlan *postgresql.BackupPlan
922+
if len(bkpResponse) > 0 {
923+
backupPlan = bkpResponse[0]
924+
}
927925

928-
if backupPlan.MaxBackupStartTime != nil {
929-
planMap["max_backup_start_time"] = backupPlan.MaxBackupStartTime
930-
}
926+
if backupPlan != nil {
927+
planMap := map[string]interface{}{}
928+
if backupPlan.MinBackupStartTime != nil {
929+
planMap["min_backup_start_time"] = backupPlan.MinBackupStartTime
930+
}
931931

932-
if backupPlan.BaseBackupRetentionPeriod != nil {
933-
planMap["base_backup_retention_period"] = backupPlan.BaseBackupRetentionPeriod
934-
}
932+
if backupPlan.MaxBackupStartTime != nil {
933+
planMap["max_backup_start_time"] = backupPlan.MaxBackupStartTime
934+
}
935935

936-
if backupPlan.BackupPeriod != nil {
937-
strSlice := []string{}
938-
// set period list from BackupPeriods string, eg:"BackupPeriod": "[\"tuesday\",\"wednesday\"]",
939-
err := json.Unmarshal([]byte(*backupPlan.BackupPeriod), &strSlice)
940-
if err != nil {
941-
return fmt.Errorf("BackupPeriod:[%s] has invalid format,Unmarshal failed! error: %v", *backupPlan.BackupPeriod, err.Error())
942-
}
936+
if backupPlan.BaseBackupRetentionPeriod != nil {
937+
planMap["base_backup_retention_period"] = backupPlan.BaseBackupRetentionPeriod
938+
}
943939

944-
planMap["backup_period"] = strSlice
940+
if backupPlan.BackupPeriod != nil {
941+
strSlice := []string{}
942+
// set period list from BackupPeriods string, eg:"BackupPeriod": "[\"tuesday\",\"wednesday\"]",
943+
err := json.Unmarshal([]byte(*backupPlan.BackupPeriod), &strSlice)
944+
if err != nil {
945+
return fmt.Errorf("BackupPeriod:[%s] has invalid format,Unmarshal failed! error: %v", *backupPlan.BackupPeriod, err.Error())
945946
}
946947

947-
_ = d.Set("backup_plan", []interface{}{planMap})
948+
planMap["backup_period"] = strSlice
948949
}
950+
951+
_ = d.Set("backup_plan", []interface{}{planMap})
949952
}
950953

951954
// pg params

tencentcloud/services/postgresql/resource_tc_postgresql_instance.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Use this resource to create postgresql instance.
22

33
-> **Note:** To update the charge type, please update the `charge_type` and specify the `period` for the charging period. It only supports updating from `POSTPAID_BY_HOUR` to `PREPAID`, and the `period` field only valid in that upgrading case.
4+
45
-> **Note:** If no values are set for the two parameters: `db_major_version` and `engine_version`, then `engine_version` is set to `10.4` by default. Suggest using parameter `db_major_version` to create an instance
56

67
Example Usage

website/docs/r/postgresql_instance.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ description: |-
1212
Use this resource to create postgresql instance.
1313

1414
-> **Note:** To update the charge type, please update the `charge_type` and specify the `period` for the charging period. It only supports updating from `POSTPAID_BY_HOUR` to `PREPAID`, and the `period` field only valid in that upgrading case.
15+
1516
-> **Note:** If no values are set for the two parameters: `db_major_version` and `engine_version`, then `engine_version` is set to `10.4` by default. Suggest using parameter `db_major_version` to create an instance
1617

1718
## Example Usage

0 commit comments

Comments
 (0)