Skip to content

Commit c921409

Browse files
committed
support postgresql: operation instance
1 parent 05ce469 commit c921409

15 files changed

+1285
-408
lines changed

tencentcloud/basic_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,18 @@ data "tencentcloud_postgresql_instances" "foo" {
467467
name = "` + defaultPGOperationName + `"
468468
}
469469
470+
data "tencentcloud_postgresql_readonly_groups" "ro_groups" {
471+
filters {
472+
name = "db-master-instance-id"
473+
values = [data.tencentcloud_postgresql_instances.foo.instance_list.0.id]
474+
}
475+
order_by = "CreateTime"
476+
order_by_type = "asc"
477+
}
478+
470479
locals {
471480
pgsql_id = data.tencentcloud_postgresql_instances.foo.instance_list.0.id
481+
pgrogroup_id = data.tencentcloud_postgresql_readonly_groups.ro_groups.read_only_group_list.0.read_only_group_id
472482
}
473483
`
474484
const defaultPGSQLName = "keep-postgresql"

tencentcloud/provider.go

Lines changed: 395 additions & 389 deletions
Large diffs are not rendered by default.
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
Provides a resource to create a postgresql modify_account_remark_operation
3+
4+
Example Usage
5+
6+
```hcl
7+
resource "tencentcloud_postgresql_modify_account_remark_operation" "modify_account_remark_operation" {
8+
db_instance_id = ""
9+
user_name = ""
10+
remark = ""
11+
}
12+
```
13+
*/
14+
package tencentcloud
15+
16+
import (
17+
"log"
18+
19+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
20+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
21+
postgresql "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/postgres/v20170312"
22+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
23+
)
24+
25+
func resourceTencentCloudPostgresqlModifyAccountRemarkOperation() *schema.Resource {
26+
return &schema.Resource{
27+
Create: resourceTencentCloudPostgresqlModifyAccountRemarkOperationCreate,
28+
Read: resourceTencentCloudPostgresqlModifyAccountRemarkOperationRead,
29+
Delete: resourceTencentCloudPostgresqlModifyAccountRemarkOperationDelete,
30+
Schema: map[string]*schema.Schema{
31+
"db_instance_id": {
32+
Required: true,
33+
ForceNew: true,
34+
Type: schema.TypeString,
35+
Description: "Instance ID in the format of postgres-4wdeb0zv.",
36+
},
37+
38+
"user_name": {
39+
Required: true,
40+
ForceNew: true,
41+
Type: schema.TypeString,
42+
Description: "Instance username.",
43+
},
44+
45+
"remark": {
46+
Required: true,
47+
ForceNew: true,
48+
Type: schema.TypeString,
49+
Description: "New remarks corresponding to user `UserName`.",
50+
},
51+
},
52+
}
53+
}
54+
55+
func resourceTencentCloudPostgresqlModifyAccountRemarkOperationCreate(d *schema.ResourceData, meta interface{}) error {
56+
defer logElapsed("resource.tencentcloud_postgresql_modify_account_remark_operation.create")()
57+
defer inconsistentCheck(d, meta)()
58+
59+
logId := getLogId(contextNil)
60+
61+
var (
62+
request = postgresql.NewModifyAccountRemarkRequest()
63+
dBInstanceId string
64+
)
65+
if v, ok := d.GetOk("db_instance_id"); ok {
66+
request.DBInstanceId = helper.String(v.(string))
67+
dBInstanceId = v.(string)
68+
}
69+
70+
if v, ok := d.GetOk("user_name"); ok {
71+
request.UserName = helper.String(v.(string))
72+
}
73+
74+
if v, ok := d.GetOk("remark"); ok {
75+
request.Remark = helper.String(v.(string))
76+
}
77+
78+
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
79+
result, e := meta.(*TencentCloudClient).apiV3Conn.UsePostgresqlClient().ModifyAccountRemark(request)
80+
if e != nil {
81+
return retryError(e)
82+
} else {
83+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
84+
}
85+
return nil
86+
})
87+
if err != nil {
88+
log.Printf("[CRITAL]%s operate postgresql ModifyAccountRemarkOperation failed, reason:%+v", logId, err)
89+
return err
90+
}
91+
92+
d.SetId(dBInstanceId)
93+
94+
return resourceTencentCloudPostgresqlModifyAccountRemarkOperationRead(d, meta)
95+
}
96+
97+
func resourceTencentCloudPostgresqlModifyAccountRemarkOperationRead(d *schema.ResourceData, meta interface{}) error {
98+
defer logElapsed("resource.tencentcloud_postgresql_modify_account_remark_operation.read")()
99+
defer inconsistentCheck(d, meta)()
100+
101+
return nil
102+
}
103+
104+
func resourceTencentCloudPostgresqlModifyAccountRemarkOperationDelete(d *schema.ResourceData, meta interface{}) error {
105+
defer logElapsed("resource.tencentcloud_postgresql_modify_account_remark_operation.delete")()
106+
defer inconsistentCheck(d, meta)()
107+
108+
return nil
109+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
const TestObjectPgModifyAccountRemark = "tencentcloud_postgresql_modify_account_remark_operation.modify_account_remark_operation"
10+
11+
func TestAccTencentCloudPostgresqlModifyAccountRemarkOperationResource_basic(t *testing.T) {
12+
t.Parallel()
13+
resource.Test(t, resource.TestCase{
14+
PreCheck: func() {
15+
testAccPreCheck(t)
16+
},
17+
Providers: testAccProviders,
18+
Steps: []resource.TestStep{
19+
{
20+
Config: testAccPostgresqlModifyAccountRemarkOperation,
21+
Check: resource.ComposeTestCheckFunc(
22+
resource.TestCheckResourceAttrSet(TestObjectPgModifyAccountRemark, "id"),
23+
resource.TestCheckResourceAttrSet(TestObjectPgModifyAccountRemark, "db_instance_id"),
24+
resource.TestCheckResourceAttr(TestObjectPgModifyAccountRemark, "user_name", "root"),
25+
resource.TestCheckResourceAttr(TestObjectPgModifyAccountRemark, "remark", "hello_world"),
26+
),
27+
},
28+
},
29+
})
30+
}
31+
32+
const testAccPostgresqlModifyAccountRemarkOperation = OperationPresetPGSQL + `
33+
34+
resource "tencentcloud_postgresql_modify_account_remark_operation" "modify_account_remark_operation" {
35+
db_instance_id = local.pgsql_id
36+
user_name = "root"
37+
remark = "hello_world"
38+
}
39+
40+
`
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/*
2+
Provides a resource to create a postgresql modify_db_instance_charge_type_operation
3+
4+
Example Usage
5+
6+
```hcl
7+
resource "tencentcloud_postgresql_modify_db_instance_charge_type_operation" "modify_db_instance_charge_type_operation" {
8+
db_instance_id = "postgres-6r233v55"
9+
instance_charge_type = "PREPAID"
10+
period = 1
11+
auto_renew_flag = 0
12+
auto_voucher = 0
13+
}
14+
```
15+
*/
16+
package tencentcloud
17+
18+
import (
19+
"log"
20+
21+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
22+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
23+
postgresql "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/postgres/v20170312"
24+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
25+
)
26+
27+
func resourceTencentCloudPostgresqlModifyDbInstanceChargeTypeOperation() *schema.Resource {
28+
return &schema.Resource{
29+
Create: resourceTencentCloudPostgresqlModifyDbInstanceChargeTypeOperationCreate,
30+
Read: resourceTencentCloudPostgresqlModifyDbInstanceChargeTypeOperationRead,
31+
Delete: resourceTencentCloudPostgresqlModifyDbInstanceChargeTypeOperationDelete,
32+
Schema: map[string]*schema.Schema{
33+
"db_instance_id": {
34+
Required: true,
35+
ForceNew: true,
36+
Type: schema.TypeString,
37+
Description: "dbInstance ID.",
38+
},
39+
40+
"instance_charge_type": {
41+
Required: true,
42+
ForceNew: true,
43+
Type: schema.TypeString,
44+
Description: "Instance billing mode. Valid values:PREPAID (monthly subscription), POSTPAID_BY_HOUR (pay-as-you-go).",
45+
},
46+
47+
"period": {
48+
Required: true,
49+
ForceNew: true,
50+
Type: schema.TypeInt,
51+
Description: "Valid period in months of purchased instances. Valid values:1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 24, 36. This parameter is set to 1 when the pay-as-you-go billing mode is used.",
52+
},
53+
54+
"auto_renew_flag": {
55+
Optional: true,
56+
ForceNew: true,
57+
Type: schema.TypeInt,
58+
Description: "Renewal flag. Valid values:0 (manual renewal), 1 (auto-renewal). Default value:0.",
59+
},
60+
61+
"auto_voucher": {
62+
Optional: true,
63+
ForceNew: true,
64+
Type: schema.TypeInt,
65+
Description: "Whether to automatically use vouchers.Valid values:1(yes),0(no).Default value:0.",
66+
},
67+
},
68+
}
69+
}
70+
71+
func resourceTencentCloudPostgresqlModifyDbInstanceChargeTypeOperationCreate(d *schema.ResourceData, meta interface{}) error {
72+
defer logElapsed("resource.tencentcloud_postgresql_modify_db_instance_charge_type_operation.create")()
73+
defer inconsistentCheck(d, meta)()
74+
75+
logId := getLogId(contextNil)
76+
77+
var (
78+
request = postgresql.NewModifyDBInstanceChargeTypeRequest()
79+
dBInstanceId string
80+
)
81+
if v, ok := d.GetOk("db_instance_id"); ok {
82+
request.DBInstanceId = helper.String(v.(string))
83+
dBInstanceId = v.(string)
84+
}
85+
86+
if v, ok := d.GetOk("instance_charge_type"); ok {
87+
request.InstanceChargeType = helper.String(v.(string))
88+
}
89+
90+
if v, _ := d.GetOk("period"); v != nil {
91+
request.Period = helper.IntInt64(v.(int))
92+
}
93+
94+
if v, _ := d.GetOk("auto_renew_flag"); v != nil {
95+
request.AutoRenewFlag = helper.IntInt64(v.(int))
96+
}
97+
98+
if v, _ := d.GetOk("auto_voucher"); v != nil {
99+
request.AutoVoucher = helper.IntInt64(v.(int))
100+
}
101+
102+
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
103+
result, e := meta.(*TencentCloudClient).apiV3Conn.UsePostgresqlClient().ModifyDBInstanceChargeType(request)
104+
if e != nil {
105+
return retryError(e)
106+
} else {
107+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
108+
}
109+
return nil
110+
})
111+
if err != nil {
112+
log.Printf("[CRITAL]%s operate postgresql ModifyDbInstanceChargeTypeOperation failed, reason:%+v", logId, err)
113+
return err
114+
}
115+
116+
d.SetId(dBInstanceId)
117+
118+
return resourceTencentCloudPostgresqlModifyDbInstanceChargeTypeOperationRead(d, meta)
119+
}
120+
121+
func resourceTencentCloudPostgresqlModifyDbInstanceChargeTypeOperationRead(d *schema.ResourceData, meta interface{}) error {
122+
defer logElapsed("resource.tencentcloud_postgresql_modify_db_instance_charge_type_operation.read")()
123+
defer inconsistentCheck(d, meta)()
124+
125+
return nil
126+
}
127+
128+
func resourceTencentCloudPostgresqlModifyDbInstanceChargeTypeOperationDelete(d *schema.ResourceData, meta interface{}) error {
129+
defer logElapsed("resource.tencentcloud_postgresql_modify_db_instance_charge_type_operation.delete")()
130+
defer inconsistentCheck(d, meta)()
131+
132+
return nil
133+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
const TestObjectPgModifyChargeType = "tencentcloud_postgresql_modify_db_instance_charge_type_operation.modify_db_instance_charge_type_operation"
10+
11+
func TestAccTencentCloudPostgresqlModifyDbInstanceChargeTypeOperationResource_basic(t *testing.T) {
12+
t.Parallel()
13+
resource.Test(t, resource.TestCase{
14+
PreCheck: func() { testAccPreCheckCommon(t, ACCOUNT_TYPE_PREPAY) },
15+
Providers: testAccProviders,
16+
Steps: []resource.TestStep{
17+
{
18+
Config: testAccPostgresqlModifyDbInstanceChargeTypeOperation,
19+
Check: resource.ComposeTestCheckFunc(
20+
resource.TestCheckResourceAttrSet(TestObjectPgModifyChargeType, "id"),
21+
resource.TestCheckResourceAttrSet(TestObjectPgModifyChargeType, "db_instance_id"),
22+
resource.TestCheckResourceAttr(TestObjectPgModifyChargeType, "instance_charge_type", "PREPAID"),
23+
resource.TestCheckResourceAttr(TestObjectPgModifyChargeType, "period", "2"),
24+
resource.TestCheckResourceAttr(TestObjectPgModifyChargeType, "auto_renew_flag", "0"),
25+
resource.TestCheckResourceAttr(TestObjectPgModifyChargeType, "auto_voucher", "0"),
26+
),
27+
},
28+
},
29+
})
30+
}
31+
32+
const testAccPostgresqlModifyDbInstanceChargeTypeOperation = defaultVpcSubnets + `
33+
data "tencentcloud_availability_zones_by_product" "zone" {
34+
product = "postgres"
35+
}
36+
37+
data "tencentcloud_security_groups" "internal" {
38+
name = "default"
39+
}
40+
41+
locals {
42+
sg_id = data.tencentcloud_security_groups.internal.security_groups.0.security_group_id
43+
}
44+
45+
resource "tencentcloud_postgresql_instance" "prepaid" {
46+
name = "tf_postsql_pre"
47+
availability_zone = var.default_az
48+
charge_type = "POSTPAID_BY_HOUR"
49+
vpc_id = local.vpc_id
50+
subnet_id = local.subnet_id
51+
engine_version = "13.3"
52+
root_password = "t1qaA2k1wgvfa3?ZZZ"
53+
security_groups = [local.sg_id]
54+
charset = "LATIN1"
55+
project_id = 0
56+
memory = 2
57+
storage = 20
58+
}
59+
60+
61+
resource "tencentcloud_postgresql_modify_db_instance_charge_type_operation" "modify_db_instance_charge_type_operation" {
62+
db_instance_id = tencentcloud_postgresql_instance.prepaid.id
63+
instance_charge_type = "PREPAID"
64+
period = 2
65+
auto_renew_flag = 0
66+
auto_voucher = 0
67+
}
68+
69+
`

0 commit comments

Comments
 (0)