Skip to content

Commit fd92bb2

Browse files
committed
add changelog and update doc
1 parent d3525f4 commit fd92bb2

8 files changed

+585
-614
lines changed

.changelog/1837.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_postgresql_instance: support to update `charge_type` and `period`
3+
```
4+
5+
```release-note:enhancement
6+
resource/tencentcloud_postgresql_readonly_instance: support the `read_only_group_id` field
7+
```
8+
9+
```release-note:new-resource
10+
tencentcloud_postgresql_modify_account_remark_operation
11+
```
12+
13+
```release-note:new-resource
14+
tencentcloud_postgresql_modify_switch_time_period_operation
15+
```

tencentcloud/provider.go

Lines changed: 399 additions & 402 deletions
Large diffs are not rendered by default.

tencentcloud/resource_tc_postgresql_instance.go

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,7 @@ func resourceTencentCloudPostgresqlInstance() *schema.Resource {
211211
Type: schema.TypeString,
212212
Optional: true,
213213
Default: COMMON_PAYTYPE_POSTPAID,
214-
ForceNew: true,
215-
Description: "Pay type of the postgresql instance. Values `POSTPAID_BY_HOUR` (Default), `PREPAID`.",
214+
Description: "Pay type of the postgresql instance. Values `POSTPAID_BY_HOUR` (Default), `PREPAID`. It support to update the type from `POSTPAID_BY_HOUR` to `PREPAID`.",
216215
},
217216
"period": {
218217
Type: schema.TypeInt,
@@ -795,15 +794,85 @@ func resourceTencentCloudPostgresqlInstanceUpdate(d *schema.ResourceData, meta i
795794
d.Partial(true)
796795

797796
if err := helper.ImmutableArgsChek(d,
798-
"charge_type",
799-
"period",
800-
"auto_renew_flag",
801-
"auto_voucher",
797+
// "charge_type",
798+
// "period",
799+
// "auto_renew_flag",
800+
// "auto_voucher",
802801
"voucher_ids",
803802
); err != nil {
804803
return err
805804
}
806805

806+
if d.HasChange("charge_type") {
807+
var (
808+
chargeTypeOld string
809+
chargeTypeNew string
810+
period = 1
811+
autoRenew = 0
812+
autoVoucher = 0
813+
request = postgresql.NewModifyDBInstanceChargeTypeRequest()
814+
)
815+
816+
old, new := d.GetChange("charge_type")
817+
if old != nil {
818+
chargeTypeOld = old.(string)
819+
}
820+
if new != nil {
821+
chargeTypeNew = new.(string)
822+
}
823+
824+
// The real Update operation rather than the operation from create
825+
if chargeTypeOld != "" && chargeTypeOld != chargeTypeNew {
826+
if v, ok := d.GetOk("period"); ok {
827+
log.Printf("period set")
828+
period = v.(int)
829+
} else {
830+
log.Printf("period not set")
831+
}
832+
833+
if v, ok := d.GetOk("auto_renew_flag"); ok {
834+
log.Printf("auto_renew_flag set")
835+
autoRenew = v.(int)
836+
} else {
837+
log.Printf("auto_renew_flag not set")
838+
}
839+
840+
if v, ok := d.GetOk("auto_voucher"); ok {
841+
log.Printf("auto_voucher set")
842+
autoVoucher = v.(int)
843+
} else {
844+
log.Printf("auto_voucher not set")
845+
}
846+
847+
request.DBInstanceId = &instanceId
848+
request.InstanceChargeType = &chargeTypeNew
849+
request.Period = helper.IntInt64(period)
850+
request.AutoRenewFlag = helper.IntInt64(autoRenew)
851+
request.AutoVoucher = helper.IntInt64(autoVoucher)
852+
853+
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
854+
result, e := meta.(*TencentCloudClient).apiV3Conn.UsePostgresqlClient().ModifyDBInstanceChargeType(request)
855+
if e != nil {
856+
return retryError(e)
857+
} else {
858+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
859+
}
860+
return nil
861+
})
862+
if err != nil {
863+
log.Printf("[CRITAL]%s operate postgresql ModifyDbInstanceChargeType failed, reason:%+v", logId, err)
864+
return err
865+
}
866+
867+
// wait unit charge type changing operation of instance done
868+
service := PostgresqlService{client: meta.(*TencentCloudClient).apiV3Conn}
869+
conf := BuildStateChangeConf([]string{}, []string{"running"}, 2*readRetryTimeout, time.Second, service.PostgresqlDBInstanceStateRefreshFunc(instanceId, []string{}))
870+
if _, e := conf.WaitForState(); e != nil {
871+
return e
872+
}
873+
}
874+
}
875+
807876
var outErr, inErr, checkErr error
808877
// update vpc and subnet
809878
if d.HasChange("vpc_id") || d.HasChange("subnet_id") {

tencentcloud/resource_tc_postgresql_instance_test.go

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,44 @@ func TestAccTencentCloudPostgresqlInstanceResource_prepaid(t *testing.T) {
234234
})
235235
}
236236

237+
func TestAccTencentCloudPostgresqlInstanceResource_postpaid_to_prepaid(t *testing.T) {
238+
resource.Test(t, resource.TestCase{
239+
PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_PREPAY) },
240+
Providers: testAccProviders,
241+
CheckDestroy: testAccCheckPostgresqlInstanceDestroy,
242+
Steps: []resource.TestStep{
243+
{
244+
PreConfig: func() { testAccStepPreConfigSetTempAKSK(t, ACCOUNT_TYPE_PREPAY) },
245+
Config: testAccPostgresqlInstancePostpaid,
246+
Check: resource.ComposeTestCheckFunc(
247+
testAccCheckPostgresqlInstanceExists(testPostgresqlInstanceResourceKey),
248+
resource.TestCheckResourceAttrSet(testPostgresqlInstanceResourceKey, "id"),
249+
resource.TestCheckResourceAttr(testPostgresqlInstanceResourceKey, "name", "tf_postsql_postpaid"),
250+
resource.TestCheckResourceAttr(testPostgresqlInstanceResourceKey, "charge_type", "POSTPAID_BY_HOUR"),
251+
resource.TestCheckResourceAttrSet(testPostgresqlInstanceResourceKey, "period"),
252+
),
253+
},
254+
{
255+
PreConfig: func() { testAccStepPreConfigSetTempAKSK(t, ACCOUNT_TYPE_PREPAY) },
256+
Config: testAccPostgresqlInstancePostpaid_to_Prepaid,
257+
Check: resource.ComposeTestCheckFunc(
258+
testAccCheckPostgresqlInstanceExists(testPostgresqlInstanceResourceKey),
259+
resource.TestCheckResourceAttrSet(testPostgresqlInstanceResourceKey, "id"),
260+
resource.TestCheckResourceAttr(testPostgresqlInstanceResourceKey, "name", "tf_postsql_postpaid_updated_to_prepaid"),
261+
resource.TestCheckResourceAttr(testPostgresqlInstanceResourceKey, "charge_type", "PREPAID"),
262+
resource.TestCheckResourceAttr(testPostgresqlInstanceResourceKey, "period", "2"),
263+
),
264+
},
265+
{
266+
ResourceName: testPostgresqlInstanceResourceKey,
267+
ImportState: true,
268+
ImportStateVerify: true,
269+
ImportStateVerifyIgnore: []string{"root_password", "spec_code", "public_access_switch", "charset", "backup_plan", "period"},
270+
},
271+
},
272+
})
273+
}
274+
237275
func TestAccTencentCloudPostgresqlInstanceResource_MAZ(t *testing.T) {
238276
t.Parallel()
239277
resource.Test(t, resource.TestCase{
@@ -363,6 +401,63 @@ resource "tencentcloud_postgresql_instance" "test" {
363401
}
364402
}
365403
`
404+
const testAccPostgresqlInstancePostpaid = defaultVpcSubnets + `
405+
data "tencentcloud_availability_zones_by_product" "zone" {
406+
product = "postgres"
407+
}
408+
409+
data "tencentcloud_security_groups" "internal" {
410+
name = "default"
411+
}
412+
413+
locals {
414+
sg_id = data.tencentcloud_security_groups.internal.security_groups.0.security_group_id
415+
}
416+
417+
resource "tencentcloud_postgresql_instance" "test" {
418+
name = "tf_postsql_postpaid"
419+
availability_zone = var.default_az
420+
charge_type = "POSTPAID_BY_HOUR"
421+
period = 1
422+
vpc_id = local.vpc_id
423+
subnet_id = local.subnet_id
424+
engine_version = "13.3"
425+
root_password = "t1qaA2k1wgvfa3?ZZZ"
426+
security_groups = [local.sg_id]
427+
charset = "LATIN1"
428+
project_id = 0
429+
memory = 2
430+
storage = 20
431+
}`
432+
433+
const testAccPostgresqlInstancePostpaid_to_Prepaid = defaultVpcSubnets + `
434+
data "tencentcloud_availability_zones_by_product" "zone" {
435+
product = "postgres"
436+
}
437+
438+
data "tencentcloud_security_groups" "internal" {
439+
name = "default"
440+
}
441+
442+
locals {
443+
sg_id = data.tencentcloud_security_groups.internal.security_groups.0.security_group_id
444+
}
445+
446+
resource "tencentcloud_postgresql_instance" "test" {
447+
name = "tf_postsql_postpaid_updated_to_prepaid"
448+
availability_zone = var.default_az
449+
charge_type = "PREPAID"
450+
period = 2
451+
vpc_id = local.vpc_id
452+
subnet_id = local.subnet_id
453+
engine_version = "13.3"
454+
root_password = "t1qaA2k1wgvfa3?ZZZ"
455+
security_groups = [local.sg_id]
456+
charset = "LATIN1"
457+
project_id = 0
458+
memory = 2
459+
storage = 20
460+
}`
366461

367462
const testAccPostgresqlInstancePrepaid = defaultVpcSubnets + `
368463
data "tencentcloud_availability_zones_by_product" "zone" {

tencentcloud/resource_tc_postgresql_modify_db_instance_charge_type_operation.go

Lines changed: 0 additions & 133 deletions
This file was deleted.

0 commit comments

Comments
 (0)