From 536164881c9fe0acf749aca3e95d0567cd0d2ac7 Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Wed, 30 Oct 2024 11:35:24 +0800 Subject: [PATCH 1/3] add --- .../resource_tc_postgresql_instance.go | 67 ++++++++++--------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/tencentcloud/services/postgresql/resource_tc_postgresql_instance.go b/tencentcloud/services/postgresql/resource_tc_postgresql_instance.go index e12df3de5b..82e114801e 100644 --- a/tencentcloud/services/postgresql/resource_tc_postgresql_instance.go +++ b/tencentcloud/services/postgresql/resource_tc_postgresql_instance.go @@ -230,6 +230,7 @@ func ResourceTencentCloudPostgresqlInstance() *schema.Resource { "backup_plan": { Type: schema.TypeList, Optional: true, + Computed: true, Description: "Specify DB backup plan.", MaxItems: 1, Elem: &schema.Resource{ @@ -237,21 +238,25 @@ func ResourceTencentCloudPostgresqlInstance() *schema.Resource { "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}, }, @@ -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 From 147612c5f07a4ab875ba4e8d3da2b240059cbb15 Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Wed, 30 Oct 2024 11:37:09 +0800 Subject: [PATCH 2/3] add --- .changelog/2921.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/2921.txt diff --git a/.changelog/2921.txt b/.changelog/2921.txt new file mode 100644 index 0000000000..6085e9ee79 --- /dev/null +++ b/.changelog/2921.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/tencentcloud_postgresql_instance: update field properties for `backup_plan` +``` From d77532e80b5ddfbbaf14b0afba9b76907b0bf981 Mon Sep 17 00:00:00 2001 From: SevenEarth <391613297@qq.com> Date: Wed, 30 Oct 2024 14:14:37 +0800 Subject: [PATCH 3/3] add --- .../services/postgresql/resource_tc_postgresql_instance.md | 1 + website/docs/r/postgresql_instance.html.markdown | 1 + 2 files changed, 2 insertions(+) diff --git a/tencentcloud/services/postgresql/resource_tc_postgresql_instance.md b/tencentcloud/services/postgresql/resource_tc_postgresql_instance.md index bde47f7d4e..407e1bfcdf 100644 --- a/tencentcloud/services/postgresql/resource_tc_postgresql_instance.md +++ b/tencentcloud/services/postgresql/resource_tc_postgresql_instance.md @@ -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 diff --git a/website/docs/r/postgresql_instance.html.markdown b/website/docs/r/postgresql_instance.html.markdown index 1c9bf85d46..17c32ec8c5 100644 --- a/website/docs/r/postgresql_instance.html.markdown +++ b/website/docs/r/postgresql_instance.html.markdown @@ -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