Skip to content

Commit 7025258

Browse files
authored
Merge pull request #1872 from tencentcloudstack/feat/supoort-dcdb-other-operation
Feat/supoort dcdb rest of operation
2 parents 47277bb + 43257b5 commit 7025258

25 files changed

+992
-556
lines changed

.changelog/1872.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_dcdb_hourdb_instance: support `rs_access_strategy`, `vip` and `vipv6` field.
3+
```
4+
5+
```release-note:new-resource
6+
tencentcloud_dcdb_flush_binlog_operation
7+
```
8+
9+
```release-note:new-resource
10+
tencentcloud_dcdb_switch_db_instance_ha_operation
11+
```
12+
13+
```release-note:new-resource
14+
tencentcloud_dcdb_instance_config
15+
```

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ require (
3838
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.659
3939
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cloudaudit v1.0.544
4040
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cls v1.0.663
41-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.672
41+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.673
4242
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.624
4343
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.589
4444
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb v1.0.572
4545
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dayu v1.0.335
4646
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dbbrain v1.0.652
4747
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dc v1.0.633
48-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dcdb v1.0.670
48+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dcdb v1.0.673
4949
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dnspod v1.0.539
5050
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/domain v1.0.414
5151
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dts v1.0.628

go.sum

Lines changed: 4 additions & 460 deletions
Large diffs are not rendered by default.

tencentcloud/provider.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,9 +1117,12 @@ TDSQL for MySQL(DCDB)
11171117
tencentcloud_dcdb_db_parameters
11181118
tencentcloud_dcdb_db_sync_mode_config
11191119
tencentcloud_dcdb_encrypt_attributes_config
1120+
tencentcloud_dcdb_instance_config
11201121
tencentcloud_dcdb_cancel_dcn_job_operation
11211122
tencentcloud_dcdb_activate_hour_instance_operation
11221123
tencentcloud_dcdb_isolate_hour_instance_operation
1124+
tencentcloud_dcdb_flush_binlog_operation
1125+
tencentcloud_dcdb_switch_db_instance_ha_operation
11231126
11241127
Short Message Service(SMS)
11251128
Resource
@@ -2442,9 +2445,12 @@ func Provider() *schema.Provider {
24422445
"tencentcloud_dcdb_db_parameters": resourceTencentCloudDcdbDbParameters(),
24432446
"tencentcloud_dcdb_encrypt_attributes_config": resourceTencentCloudDcdbEncryptAttributesConfig(),
24442447
"tencentcloud_dcdb_db_sync_mode_config": resourceTencentCloudDcdbDbSyncModeConfig(),
2448+
"tencentcloud_dcdb_instance_config": resourceTencentCloudDcdbInstanceConfig(),
24452449
"tencentcloud_dcdb_activate_hour_instance_operation": resourceTencentCloudDcdbActivateHourInstanceOperation(),
24462450
"tencentcloud_dcdb_isolate_hour_instance_operation": resourceTencentCloudDcdbIsolateHourInstanceOperation(),
24472451
"tencentcloud_dcdb_cancel_dcn_job_operation": resourceTencentCloudDcdbCancelDcnJobOperation(),
2452+
"tencentcloud_dcdb_flush_binlog_operation": resourceTencentCloudDcdbFlushBinlogOperation(),
2453+
"tencentcloud_dcdb_switch_db_instance_ha_operation": resourceTencentCloudDcdbSwitchDbInstanceHaOperation(),
24482454
"tencentcloud_cat_task_set": resourceTencentCloudCatTaskSet(),
24492455
"tencentcloud_mariadb_dedicatedcluster_db_instance": resourceTencentCloudMariadbDedicatedclusterDbInstance(),
24502456
"tencentcloud_mariadb_instance": resourceTencentCloudMariadbInstance(),

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: 103 additions & 20 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": {
@@ -173,6 +173,26 @@ func resourceTencentCloudDcdbDbInstance() *schema.Resource {
173173
Description: "Whether to open the extranet access.",
174174
},
175175

176+
"vip": {
177+
Optional: true,
178+
Computed: true,
179+
Type: schema.TypeString,
180+
Description: "The field is required to specify VIP.",
181+
},
182+
183+
"vipv6": {
184+
Optional: true,
185+
Computed: true,
186+
Type: schema.TypeString,
187+
Description: "The field is required to specify VIPv6.",
188+
},
189+
190+
"vport": {
191+
Type: schema.TypeInt,
192+
Computed: true,
193+
Description: "Intranet port.",
194+
},
195+
176196
"resource_tags": {
177197
Optional: true,
178198
Type: schema.TypeList,
@@ -196,7 +216,7 @@ func resourceTencentCloudDcdbDbInstance() *schema.Resource {
196216
"init_params": {
197217
Optional: true,
198218
Type: schema.TypeList,
199-
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)".",
219+
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) .",
200220
Elem: &schema.Resource{
201221
Schema: map[string]*schema.Schema{
202222
"param": {
@@ -228,7 +248,7 @@ func resourceTencentCloudDcdbDbInstance() *schema.Resource {
228248
"auto_renew_flag": {
229249
Optional: true,
230250
Type: schema.TypeInt,
231-
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.".",
251+
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.",
232252
},
233253

234254
"security_group_ids": {
@@ -255,6 +275,8 @@ func resourceTencentCloudDcdbDbInstanceCreate(d *schema.ResourceData, meta inter
255275
response = dcdb.NewCreateDCDBInstanceResponse()
256276
instanceId string
257277
dcnInstanceId string
278+
vpcId string
279+
subnetId string
258280
ipv6Flag int
259281
service = DcdbService{client: meta.(*TencentCloudClient).apiV3Conn}
260282
)
@@ -442,6 +464,29 @@ func resourceTencentCloudDcdbDbInstanceCreate(d *schema.ResourceData, meta inter
442464
}
443465
}
444466

467+
var (
468+
vip string
469+
vipv6 string
470+
)
471+
472+
if v, ok := d.GetOk("vip"); ok {
473+
vip = v.(string)
474+
}
475+
if v, ok := d.GetOk("vipv6"); ok {
476+
vipv6 = v.(string)
477+
}
478+
479+
if vip != "" || vipv6 != "" {
480+
if vpcId == "" || subnetId == "" {
481+
return fmt.Errorf("`vpc_id` and `subnet_id` cannot be empty when setting `vip` or `vipv6` fields!")
482+
}
483+
484+
err := service.SetNetworkVip(ctx, instanceId, vpcId, subnetId, vip, vipv6)
485+
if err != nil {
486+
return err
487+
}
488+
}
489+
445490
return resourceTencentCloudDcdbDbInstanceRead(d, meta)
446491
}
447492

@@ -469,10 +514,6 @@ func resourceTencentCloudDcdbDbInstanceRead(d *schema.ResourceData, meta interfa
469514

470515
dbInstance := ret.Instances[0]
471516

472-
if dbInstance.Zone != nil {
473-
_ = d.Set("zones", []*string{dbInstance.Zone})
474-
}
475-
476517
// if dbInstance.Period != nil {
477518
// _ = d.Set("period", dbInstance.Period)
478519
// }
@@ -584,7 +625,7 @@ func resourceTencentCloudDcdbDbInstanceRead(d *schema.ResourceData, meta interfa
584625
_ = d.Set("auto_renew_flag", dbInstance.AutoRenewFlag)
585626
}
586627

587-
if sg, err := service.DescribeDcdbSecurityGroup(ctx, instanceId); sg != nil {
628+
if sg, err := service.DescribeDcdbSecurityGroup(ctx, instanceId); err == nil {
588629
sgIds := []*string{}
589630
for _, sg := range sg.Groups {
590631
sgIds = append(sgIds, sg.SecurityGroupId)
@@ -604,7 +645,7 @@ func resourceTencentCloudDcdbDbInstanceRead(d *schema.ResourceData, meta interfa
604645
}
605646

606647
// set dcn id and region
607-
if dcns, err := service.DescribeDcnDetailById(ctx, instanceId); dcns != nil {
648+
if dcns, err := service.DescribeDcnDetailById(ctx, instanceId); err == nil {
608649
for _, dcn := range dcns {
609650
var master *dcdb.DcnDetailItem
610651
if *dcn.DcnFlag == DCDB_DCN_FLAG_MASTER {
@@ -617,6 +658,25 @@ func resourceTencentCloudDcdbDbInstanceRead(d *schema.ResourceData, meta interfa
617658
return err
618659
}
619660

661+
// set vip, vipv6 and vport
662+
if detail, err := service.DescribeDcdbDbInstanceDetailById(ctx, instanceId); err == nil {
663+
if detail != nil {
664+
_ = d.Set("vip", detail.Vip)
665+
_ = d.Set("vipv6", detail.Vip6)
666+
_ = d.Set("vport", detail.Vport)
667+
668+
if detail.MasterZone != nil {
669+
zones := []*string{detail.MasterZone}
670+
if detail.SlaveZones != nil {
671+
zones = append(zones, detail.SlaveZones...)
672+
}
673+
_ = d.Set("zones", zones)
674+
}
675+
}
676+
} else {
677+
return err
678+
}
679+
620680
return nil
621681
}
622682

@@ -688,7 +748,6 @@ func resourceTencentCloudDcdbDbInstanceUpdate(d *schema.ResourceData, meta inter
688748
return fmt.Errorf("`shard_count` do not support change now.")
689749
}
690750

691-
// if d.HasChange("extranet_access") {
692751
if v, ok := d.GetOkExists("extranet_access"); ok && v != nil {
693752
flag := v.(bool)
694753
var ipv6Flag int
@@ -701,7 +760,6 @@ func resourceTencentCloudDcdbDbInstanceUpdate(d *schema.ResourceData, meta inter
701760
}
702761
time.Sleep(2 * time.Second)
703762
}
704-
// }
705763

706764
if d.HasChange("project_id") {
707765
if projectId, ok := d.GetOk("project_id"); ok {
@@ -726,12 +784,37 @@ func resourceTencentCloudDcdbDbInstanceUpdate(d *schema.ResourceData, meta inter
726784
}
727785
time.Sleep(2 * time.Second)
728786
}
729-
if d.HasChange("vpc_id") {
730-
return fmt.Errorf("`vpc_id` do not support change now.")
731-
}
732-
if d.HasChange("subnet_id") {
733-
return fmt.Errorf("`subnet_id` do not support change now.")
787+
788+
if d.HasChange("vpc_id") || d.HasChange("subnet_id") || d.HasChange("vip") || d.HasChange("vipv6") {
789+
var (
790+
vip string
791+
vipv6 string
792+
vpcId string
793+
subnetId string
794+
)
795+
if v, ok := d.GetOk("vip"); ok {
796+
vip = v.(string)
797+
}
798+
if v, ok := d.GetOk("vipv6"); ok {
799+
vipv6 = v.(string)
800+
}
801+
if v, ok := d.GetOk("vpc_id"); ok {
802+
vpcId = v.(string)
803+
}
804+
if v, ok := d.GetOk("subnet_id"); ok {
805+
subnetId = v.(string)
806+
}
807+
808+
if vpcId == "" || subnetId == "" {
809+
return fmt.Errorf("`vpc_id` and `subnet_id` cannot be empty when updating network configs!")
810+
}
811+
812+
err := service.SetNetworkVip(ctx, instanceId, vpcId, subnetId, vip, vipv6)
813+
if err != nil {
814+
return err
815+
}
734816
}
817+
735818
if d.HasChange("db_version_id") {
736819
return fmt.Errorf("`db_version_id` do not support change now.")
737820
}

0 commit comments

Comments
 (0)