Skip to content

Commit ce5c9d7

Browse files
committed
add tencentcloud_dcdb_instance_config
1 parent aefd131 commit ce5c9d7

11 files changed

+279
-26
lines changed

.changelog/1872.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ tencentcloud_dcdb_flush_binlog_operation
99
```release-note:new-resource
1010
tencentcloud_dcdb_switch_db_instance_ha_operation
1111
```
12+
13+
```release-note:new-resource
14+
tencentcloud_dcdb_instance_config
15+
```

tencentcloud/provider.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,7 @@ TDSQL for MySQL(DCDB)
11151115
tencentcloud_dcdb_db_parameters
11161116
tencentcloud_dcdb_db_sync_mode_config
11171117
tencentcloud_dcdb_encrypt_attributes_config
1118+
tencentcloud_dcdb_instance_config
11181119
tencentcloud_dcdb_cancel_dcn_job_operation
11191120
tencentcloud_dcdb_activate_hour_instance_operation
11201121
tencentcloud_dcdb_isolate_hour_instance_operation
@@ -2431,6 +2432,7 @@ func Provider() *schema.Provider {
24312432
"tencentcloud_dcdb_db_parameters": resourceTencentCloudDcdbDbParameters(),
24322433
"tencentcloud_dcdb_encrypt_attributes_config": resourceTencentCloudDcdbEncryptAttributesConfig(),
24332434
"tencentcloud_dcdb_db_sync_mode_config": resourceTencentCloudDcdbDbSyncModeConfig(),
2435+
"tencentcloud_dcdb_instance_config": resourceTencentCloudDcdbInstanceConfig(),
24342436
"tencentcloud_dcdb_activate_hour_instance_operation": resourceTencentCloudDcdbActivateHourInstanceOperation(),
24352437
"tencentcloud_dcdb_isolate_hour_instance_operation": resourceTencentCloudDcdbIsolateHourInstanceOperation(),
24362438
"tencentcloud_dcdb_cancel_dcn_job_operation": resourceTencentCloudDcdbCancelDcnJobOperation(),

tencentcloud/resource_tc_dcdb_account_privileges.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ func resourceTencentCloudDcdbAccountPrivileges() *schema.Resource {
9090
Elem: &schema.Schema{
9191
Type: schema.TypeString,
9292
},
93-
Description: ""Global permissions. Among them, the optional value of the permission in GlobalPrivileges is:""SELECT, INSERT, UPDATE, DELETE, CREATE, PROCESS, DROP, REFERENCES, INDEX, ALTER, SHOW DATABASES,""CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EVENT, TRIGGER.""Note that if this parameter is not passed, it means that the existing permissions are reserved. If it needs to be cleared, pass an empty array in this field.".",
93+
Description: "Global permissions. Among them, the optional value of the permission in GlobalPrivileges is: SELECT, INSERT, UPDATE, DELETE, CREATE, PROCESS, DROP, REFERENCES, INDEX, ALTER, SHOW DATABASES, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EVENT, TRIGGER. Note that if this parameter is not passed, it means that the existing permissions are reserved. If it needs to be cleared, pass an empty array in this field.",
9494
},
9595

9696
"database_privileges": {
9797
Optional: true,
9898
Type: schema.TypeList,
9999
MaxItems: 1,
100-
Description: ""Database permissions. Optional values for the Privileges permission are:""SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE TEMPORARY TABLES,""LOCK TABLES, EXECUTE, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EVENT, TRIGGER.""Note that if this parameter is not passed, the existing privileges are reserved. If you need to clear them, please pass an empty array in the complex type Privileges field.".",
100+
Description: "Database permissions. Optional values for the Privileges permission are: SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EVENT, TRIGGER. Note that if this parameter is not passed, the existing privileges are reserved. If you need to clear them, please pass an empty array in the complex type Privileges field.",
101101
Elem: &schema.Resource{
102102
Schema: map[string]*schema.Schema{
103103
"privileges": {
@@ -121,7 +121,7 @@ func resourceTencentCloudDcdbAccountPrivileges() *schema.Resource {
121121
Optional: true,
122122
Type: schema.TypeList,
123123
MaxItems: 1,
124-
Description: ""Permissions for tables in the database. Optional values for the Privileges permission are:""SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE VIEW, SHOW VIEW, TRIGGER.""Note that if this parameter is not passed, the existing privileges are reserved. If you need to clear them, please pass an empty array in the complex type Privileges field.".",
124+
Description: "Permissions for tables in the database. Optional values for the Privileges permission are: SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE VIEW, SHOW VIEW, TRIGGER. Note that if this parameter is not passed, the existing privileges are reserved. If you need to clear them, please pass an empty array in the complex type Privileges field.",
125125
Elem: &schema.Resource{
126126
Schema: map[string]*schema.Schema{
127127
"database": {
@@ -150,7 +150,7 @@ func resourceTencentCloudDcdbAccountPrivileges() *schema.Resource {
150150
Optional: true,
151151
Type: schema.TypeList,
152152
MaxItems: 1,
153-
Description: ""Permissions for columns in database tables. Optional values for the Privileges permission are:""SELECT, INSERT, UPDATE, REFERENCES.""Note that if this parameter is not passed, the existing privileges are reserved. If you need to clear them, please pass an empty array in the complex type Privileges field.".",
153+
Description: "Permissions for columns in database tables. Optional values for the Privileges permission are: SELECT, INSERT, UPDATE, REFERENCES. Note that if this parameter is not passed, the existing privileges are reserved. If you need to clear them, please pass an empty array in the complex type Privileges field.",
154154
Elem: &schema.Resource{
155155
Schema: map[string]*schema.Schema{
156156
"database": {
@@ -184,7 +184,7 @@ func resourceTencentCloudDcdbAccountPrivileges() *schema.Resource {
184184
Optional: true,
185185
Type: schema.TypeList,
186186
MaxItems: 1,
187-
Description: ""Permissions for database views. Optional values for the Privileges permission are:""SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE VIEW, SHOW VIEW, TRIGGER.""Note that if this parameter is not passed, the existing privileges are reserved. If you need to clear them, please pass an empty array in the complex type Privileges field.".",
187+
Description: "Permissions for database views. Optional values for the Privileges permission are: SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE VIEW, SHOW VIEW, TRIGGER. Note that if this parameter is not passed, the existing privileges are reserved. If you need to clear them, please pass an empty array in the complex type Privileges field.",
188188
Elem: &schema.Resource{
189189
Schema: map[string]*schema.Schema{
190190
"database": {

tencentcloud/resource_tc_dcdb_db_instance.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func resourceTencentCloudDcdbDbInstance() *schema.Resource {
7777
Elem: &schema.Schema{
7878
Type: schema.TypeString,
7979
},
80-
Description: ""The availability zone distribution of shard nodes can be filled with up to two availability zones. When the shard specification is one master and two slaves, two of the nodes are in the first availability zone.""Note that the current availability zone that can be sold needs to be pulled through the DescribeDCDBSaleInfo interface.".",
80+
Description: "The availability zone distribution of shard nodes can be filled with up to two availability zones. When the shard specification is one master and two slaves, two of the nodes are in the first availability zone.Note that the current availability zone that can be sold needs to be pulled through the DescribeDCDBSaleInfo interface.",
8181
},
8282

8383
"period": {
@@ -89,19 +89,19 @@ func resourceTencentCloudDcdbDbInstance() *schema.Resource {
8989
"shard_memory": {
9090
Required: true,
9191
Type: schema.TypeInt,
92-
Description: ""Shard memory size, unit: GB, can pass DescribeShardSpec""Query the instance specification to obtain.".",
92+
Description: "Shard memory size, unit: GB, can pass DescribeShardSpec Query the instance specification to obtain.",
9393
},
9494

9595
"shard_storage": {
9696
Required: true,
9797
Type: schema.TypeInt,
98-
Description: ""Shard storage size, unit: GB, can pass DescribeShardSpec""Query the instance specification to obtain.".",
98+
Description: " Shard storage size, unit: GB, can pass DescribeShardSpec Query the instance specification to obtain.",
9999
},
100100

101101
"shard_node_count": {
102102
Required: true,
103103
Type: schema.TypeInt,
104-
Description: ""Number of single shard nodes, can pass DescribeShardSpec""Query the instance specification to obtain.".",
104+
Description: " Number of single shard nodes, can pass DescribeShardSpec Query the instance specification to obtain.",
105105
},
106106

107107
"shard_count": {
@@ -137,7 +137,7 @@ func resourceTencentCloudDcdbDbInstance() *schema.Resource {
137137
"db_version_id": {
138138
Optional: true,
139139
Type: schema.TypeString,
140-
Description: ""Database engine version, currently available: 8.0.18, 10.1.9, 5.7.17.""8.0.18 - MySQL 8.0.18;""10.1.9 - Mariadb 10.1.9;""5.7.17 - Percona 5.7.17""If not filled, the default is 5.7.17, which means Percona 5.7.17.".",
140+
Description: " Database engine version, currently available: 8.0.18, 10.1.9, 5.7.17. 8.0.18 - MySQL 8.0.18; 10.1.9 - Mariadb 10.1.9; 5.7.17 - Percona 5.7.17 If not filled, the default is 5.7.17, which means Percona 5.7.17.",
141141
},
142142

143143
"auto_voucher": {
@@ -222,7 +222,7 @@ func resourceTencentCloudDcdbDbInstance() *schema.Resource {
222222
"init_params": {
223223
Optional: true,
224224
Type: schema.TypeList,
225-
Description: ""parameter list. The optional values of this interface are:""character_set_server (character set, must be passed),""lower_case_table_names (table name is case sensitive, must be passed, 0 - sensitive; 1 - insensitive),""innodb_page_size (innodb data page, default 16K),""sync_mode ( Synchronous mode: 0 - asynchronous; 1 - strong synchronous; 2 - strong synchronous degenerate. The default is strong synchronous degenerate)".",
225+
Description: " parameter list. The optional values of this interface are: character_set_server (character set, must be passed), lower_case_table_names (table name is case sensitive, must be passed, 0 - sensitive; 1 - insensitive), innodb_page_size (innodb data page, default 16K), sync_mode ( Synchronous mode: 0 - asynchronous; 1 - strong synchronous; 2 - strong synchronous degenerate. The default is strong synchronous degenerate) .",
226226
Elem: &schema.Resource{
227227
Schema: map[string]*schema.Schema{
228228
"param": {
@@ -254,7 +254,7 @@ func resourceTencentCloudDcdbDbInstance() *schema.Resource {
254254
"auto_renew_flag": {
255255
Optional: true,
256256
Type: schema.TypeInt,
257-
Description: ""Automatic renewal flag, 0 means the default state (the user has not set it, that is, the initial state is manual renewal, and the user has activated the prepaid non-stop privilege and will also perform automatic renewal).""1 means automatic renewal, 2 means no automatic renewal (user setting).""if the business has no concept of renewal or automatic renewal is not required, it needs to be set to 0.".",
257+
Description: " Automatic renewal flag, 0 means the default state (the user has not set it, that is, the initial state is manual renewal, and the user has activated the prepaid non-stop privilege and will also perform automatic renewal). 1 means automatic renewal, 2 means no automatic renewal (user setting). if the business has no concept of renewal or automatic renewal is not required, it needs to be set to 0.",
258258
},
259259

260260
"security_group_ids": {
@@ -528,10 +528,6 @@ func resourceTencentCloudDcdbDbInstanceRead(d *schema.ResourceData, meta interfa
528528

529529
dbInstance := ret.Instances[0]
530530

531-
if dbInstance.Zone != nil {
532-
_ = d.Set("zones", []*string{dbInstance.Zone})
533-
}
534-
535531
// if dbInstance.Period != nil {
536532
// _ = d.Set("period", dbInstance.Period)
537533
// }
@@ -683,6 +679,14 @@ func resourceTencentCloudDcdbDbInstanceRead(d *schema.ResourceData, meta interfa
683679
_ = d.Set("vip", detail.Vip)
684680
_ = d.Set("vipv6", detail.Vip6)
685681
_ = d.Set("vport", detail.Vport)
682+
683+
if detail.MasterZone != nil {
684+
zones := []*string{detail.MasterZone}
685+
if detail.SlaveZones != nil {
686+
zones = append(zones, detail.SlaveZones...)
687+
}
688+
_ = d.Set("zones", zones)
689+
}
686690
}
687691
} else {
688692
return err

tencentcloud/resource_tc_dcdb_hourdb_instance.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func resourceTencentCloudDcdbHourdbInstance() *schema.Resource {
9595
"subnet_id": {
9696
Type: schema.TypeString,
9797
Optional: true,
98-
Description: "subnet id, it's required when vpcId is set.",
98+
Description: "subnet id, its required when vpcId is set.",
9999
},
100100

101101
"db_version_id": {
@@ -427,9 +427,6 @@ func resourceTencentCloudDcdbHourdbInstanceRead(d *schema.ResourceData, meta int
427427
}
428428

429429
hourdbInstance := hourdbInstances.Instances[0]
430-
if hourdbInstance.Zone != nil {
431-
_ = d.Set("zones", []*string{hourdbInstance.Zone})
432-
}
433430

434431
if hourdbInstance.ShardDetail[0] != nil { // Memory and Storage is params for one shard
435432
shard := hourdbInstance.ShardDetail[0]
@@ -533,6 +530,14 @@ func resourceTencentCloudDcdbHourdbInstanceRead(d *schema.ResourceData, meta int
533530
_ = d.Set("vip", detail.Vip)
534531
_ = d.Set("vipv6", detail.Vip6)
535532
_ = d.Set("vport", detail.Vport)
533+
534+
if detail.MasterZone != nil {
535+
zones := []*string{detail.MasterZone}
536+
if detail.SlaveZones != nil {
537+
zones = append(zones, detail.SlaveZones...)
538+
}
539+
_ = d.Set("zones", zones)
540+
}
536541
}
537542
} else {
538543
return err
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/*
2+
Provides a resource to create a dcdb instance_config
3+
4+
Example Usage
5+
6+
```hcl
7+
resource "tencentcloud_dcdb_instance_config" "instance_config" {
8+
instance_id = ""
9+
rs_access_strategy =
10+
}
11+
```
12+
13+
Import
14+
15+
dcdb instance_config can be imported using the id, e.g.
16+
17+
```
18+
terraform import tencentcloud_dcdb_instance_config.instance_config instance_config_id
19+
```
20+
*/
21+
package tencentcloud
22+
23+
import (
24+
"context"
25+
"log"
26+
27+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
28+
)
29+
30+
func resourceTencentCloudDcdbInstanceConfig() *schema.Resource {
31+
return &schema.Resource{
32+
Create: resourceTencentCloudDcdbInstanceConfigCreate,
33+
Read: resourceTencentCloudDcdbInstanceConfigRead,
34+
Update: resourceTencentCloudDcdbInstanceConfigUpdate,
35+
Delete: resourceTencentCloudDcdbInstanceConfigDelete,
36+
Importer: &schema.ResourceImporter{
37+
State: schema.ImportStatePassthrough,
38+
},
39+
Schema: map[string]*schema.Schema{
40+
"instance_id": {
41+
Required: true,
42+
Type: schema.TypeString,
43+
Description: "Instance ID.",
44+
},
45+
46+
"rs_access_strategy": {
47+
Required: true,
48+
Type: schema.TypeInt,
49+
Description: "RS nearest access mode, 0-no policy, 1-nearest access.",
50+
},
51+
},
52+
}
53+
}
54+
55+
func resourceTencentCloudDcdbInstanceConfigCreate(d *schema.ResourceData, meta interface{}) error {
56+
defer logElapsed("resource.tencentcloud_dcdb_instance_config.create")()
57+
defer inconsistentCheck(d, meta)()
58+
59+
var instanceId string
60+
if v, ok := d.GetOk("instance_id"); ok {
61+
instanceId = v.(string)
62+
}
63+
d.SetId(instanceId)
64+
65+
return resourceTencentCloudDcdbInstanceConfigUpdate(d, meta)
66+
}
67+
68+
func resourceTencentCloudDcdbInstanceConfigRead(d *schema.ResourceData, meta interface{}) error {
69+
defer logElapsed("resource.tencentcloud_dcdb_instance_config.read")()
70+
defer inconsistentCheck(d, meta)()
71+
72+
logId := getLogId(contextNil)
73+
74+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
75+
76+
service := DcdbService{client: meta.(*TencentCloudClient).apiV3Conn}
77+
78+
instanceId := d.Id()
79+
80+
detail, err := service.DescribeDcdbDbInstanceDetailById(ctx, instanceId)
81+
if err != nil {
82+
return err
83+
}
84+
85+
if detail == nil {
86+
d.SetId("")
87+
log.Printf("[WARN]%s resource `DcdbInstanceConfig` [%s] not found, please check if it has been deleted.\n", logId, d.Id())
88+
return nil
89+
}
90+
91+
_ = d.Set("instance_id", instanceId)
92+
93+
if detail.RsAccessStrategy != nil {
94+
_ = d.Set("rs_access_strategy", detail.RsAccessStrategy)
95+
}
96+
97+
return nil
98+
}
99+
100+
func resourceTencentCloudDcdbInstanceConfigUpdate(d *schema.ResourceData, meta interface{}) error {
101+
defer logElapsed("resource.tencentcloud_dcdb_instance_config.update")()
102+
defer inconsistentCheck(d, meta)()
103+
104+
logId := getLogId(contextNil)
105+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
106+
107+
var (
108+
service = DcdbService{client: meta.(*TencentCloudClient).apiV3Conn}
109+
rsStrategy int
110+
)
111+
112+
instanceId := d.Id()
113+
if d.HasChange("rs_access_strategy") {
114+
if v, ok := d.GetOk("rs_access_strategy"); ok {
115+
rsStrategy = v.(int)
116+
}
117+
}
118+
119+
err := service.SetRealServerAccessStrategy(ctx, instanceId, rsStrategy)
120+
121+
if err != nil {
122+
log.Printf("[CRITAL]%s update dcdb instanceConfig failed, reason:%+v", logId, err)
123+
return err
124+
}
125+
126+
return resourceTencentCloudDcdbInstanceConfigRead(d, meta)
127+
}
128+
129+
func resourceTencentCloudDcdbInstanceConfigDelete(d *schema.ResourceData, meta interface{}) error {
130+
defer logElapsed("resource.tencentcloud_dcdb_instance_config.delete")()
131+
defer inconsistentCheck(d, meta)()
132+
133+
return nil
134+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudDcdbInstanceConfigResource_basic(t *testing.T) {
10+
t.Parallel()
11+
resource.Test(t, resource.TestCase{
12+
PreCheck: func() {
13+
testAccPreCheck(t)
14+
},
15+
Providers: testAccProviders,
16+
Steps: []resource.TestStep{
17+
{
18+
Config: testAccDcdbInstanceConfig,
19+
Check: resource.ComposeTestCheckFunc(
20+
resource.TestCheckResourceAttrSet("tencentcloud_dcdb_instance_config.instance_config", "id"),
21+
resource.TestCheckResourceAttr("tencentcloud_dcdb_instance_config.instance_config", "rs_access_strategy", "0"),
22+
),
23+
},
24+
{
25+
Config: testAccDcdbInstanceConfig_update,
26+
Check: resource.ComposeTestCheckFunc(
27+
resource.TestCheckResourceAttrSet("tencentcloud_dcdb_instance_config.instance_config", "id"),
28+
resource.TestCheckResourceAttr("tencentcloud_dcdb_instance_config.instance_config", "rs_access_strategy", "1"),
29+
),
30+
},
31+
{
32+
ResourceName: "tencentcloud_dcdb_instance_config.instance_config",
33+
ImportState: true,
34+
ImportStateVerify: true,
35+
},
36+
},
37+
})
38+
}
39+
40+
const testAccDcdbInstanceConfig = CommonPresetDcdb + `
41+
42+
resource "tencentcloud_dcdb_instance_config" "instance_config" {
43+
instance_id = "tdsqlshard-970m7tfv"
44+
rs_access_strategy = 0
45+
}
46+
47+
`
48+
49+
const testAccDcdbInstanceConfig_update = CommonPresetDcdb + `
50+
51+
resource "tencentcloud_dcdb_instance_config" "instance_config" {
52+
instance_id = "tdsqlshard-970m7tfv"
53+
rs_access_strategy = 1
54+
}
55+
56+
`

0 commit comments

Comments
 (0)