Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(postgresql): [120432972] tencentcloud_postgresql_instance update field properties for backup_plan #2921

Merged
merged 3 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/2921.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/tencentcloud_postgresql_instance: update field properties for `backup_plan`
```
67 changes: 35 additions & 32 deletions tencentcloud/services/postgresql/resource_tc_postgresql_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,28 +230,33 @@ func ResourceTencentCloudPostgresqlInstance() *schema.Resource {
"backup_plan": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Description: "Specify DB backup plan.",
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"min_backup_start_time": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Specify earliest backup start time, format `hh:mm:ss`.",
},
"max_backup_start_time": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Specify latest backup start time, format `hh:mm:ss`.",
},
"base_backup_retention_period": {
Type: schema.TypeInt,
Optional: true,
Computed: true,
Description: "Specify days of the retention.",
},
"backup_period": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Description: "List of backup period per week, available values: `monday`, `tuesday`, `wednesday`, `thursday`, `friday`, `saturday`, `sunday`. NOTE: At least specify two days.",
Elem: &schema.Schema{Type: schema.TypeString},
},
Expand Down Expand Up @@ -906,46 +911,44 @@ func resourceTencentCloudPostgresqlInstanceRead(d *schema.ResourceData, meta int
_ = d.Set("tags", tags)

// backup plans (only specified will rewrite)
if _, ok := d.GetOk("backup_plan"); ok {
request := postgresql.NewDescribeBackupPlansRequest()
request.DBInstanceId = helper.String(d.Id())
response, err := postgresqlService.DescribeBackupPlans(ctx, request)
if err != nil {
return err
}

var backupPlan *postgresql.BackupPlan
if len(response) > 0 {
backupPlan = response[0]
}
bkpRequest := postgresql.NewDescribeBackupPlansRequest()
bkpRequest.DBInstanceId = helper.String(d.Id())
bkpResponse, err := postgresqlService.DescribeBackupPlans(ctx, bkpRequest)
if err != nil {
return err
}

if backupPlan != nil {
planMap := map[string]interface{}{}
if backupPlan.MinBackupStartTime != nil {
planMap["min_backup_start_time"] = backupPlan.MinBackupStartTime
}
var backupPlan *postgresql.BackupPlan
if len(bkpResponse) > 0 {
backupPlan = bkpResponse[0]
}

if backupPlan.MaxBackupStartTime != nil {
planMap["max_backup_start_time"] = backupPlan.MaxBackupStartTime
}
if backupPlan != nil {
planMap := map[string]interface{}{}
if backupPlan.MinBackupStartTime != nil {
planMap["min_backup_start_time"] = backupPlan.MinBackupStartTime
}

if backupPlan.BaseBackupRetentionPeriod != nil {
planMap["base_backup_retention_period"] = backupPlan.BaseBackupRetentionPeriod
}
if backupPlan.MaxBackupStartTime != nil {
planMap["max_backup_start_time"] = backupPlan.MaxBackupStartTime
}

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

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

_ = d.Set("backup_plan", []interface{}{planMap})
planMap["backup_period"] = strSlice
}

_ = d.Set("backup_plan", []interface{}{planMap})
}

// pg params
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Use this resource to create postgresql instance.

-> **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.

-> **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

Example Usage
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/postgresql_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ description: |-
Use this resource to create postgresql instance.

-> **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.

-> **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

## Example Usage
Expand Down
Loading