Skip to content

Commit d336410

Browse files
authored
feat: mysql - support fast upgrade and param template id (#1067)
* feat: mysql - support fast upgrade and param template id * fix: cynosdb importstate
1 parent cbf39e7 commit d336410

File tree

12 files changed

+6511
-639
lines changed

12 files changed

+6511
-639
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ require (
2424
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/as v1.0.363
2525
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cam v1.0.409
2626
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cbs v1.0.199
27-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdb v1.0.199
27+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdb v1.0.409
2828
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdn v1.0.199
2929
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfs v1.0.199
3030
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ckafka v1.0.403

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cbs v1.0.199 h1:MkIdFgE
462462
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cbs v1.0.199/go.mod h1:PTp058qpOV//RukBVdYQT962rZg71lIt6eHLK1zdvEc=
463463
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdb v1.0.199 h1:7ReZOKl95X+9SkPPtrAoUt4ZPJSIjiSxq4g/M54JmtU=
464464
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdb v1.0.199/go.mod h1:BMLd7J4LnIxw3fSl9vo3UCudJbH1wZutP8Uo3sQGQTk=
465+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdb v1.0.409 h1:fKFSxvMzS8T+z2z2qm67dgTClnkryeVTykclVkHh3qE=
466+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdb v1.0.409/go.mod h1:q89YBv3T1bzENpcovtwnjxfVn9vx9pCYAssp0HPuivU=
465467
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdn v1.0.199 h1:ji9wSYFgRYbNvlm5KD1Lxb7Uh5ldcQi3AfjktJCrygY=
466468
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdn v1.0.199/go.mod h1:gJDjRbA4JhsRGKkNzqwx053/vqgNMhf42ID2a7lcE0g=
467469
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cfs v1.0.199 h1:VyOKZOlgTXW0szboWhI1N35khPsaHE4CyH9pf42o7P8=

tencentcloud/resource_tc_cynosdb_cluster_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ func TestAccTencentCloudCynosdbClusterResource(t *testing.T) {
9999
resource.TestCheckResourceAttr("tencentcloud_cynosdb_cluster.foo", "param_items.0.current_value", "utf8"),
100100
),
101101
},
102+
{
103+
ResourceName: "tencentcloud_cynosdb_cluster.foo",
104+
ImportState: true,
105+
ImportStateVerify: true,
106+
ImportStateVerifyIgnore: []string{"password", "force_delete", "storage_limit", "param_items"},
107+
},
102108
{
103109
Config: testAccCynosdbCluster_update,
104110
Check: resource.ComposeTestCheckFunc(
@@ -116,12 +122,6 @@ func TestAccTencentCloudCynosdbClusterResource(t *testing.T) {
116122
resource.TestCheckResourceAttr("tencentcloud_cynosdb_cluster.foo", "param_items.0.current_value", "utf8mb4"),
117123
),
118124
},
119-
{
120-
ResourceName: "tencentcloud_cynosdb_cluster.foo",
121-
ImportState: true,
122-
ImportStateVerify: true,
123-
ImportStateVerifyIgnore: []string{"password", "force_delete", "storage_limit", "param_items"},
124-
},
125125
},
126126
})
127127
}

tencentcloud/resource_tc_mysql_instance.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,16 @@ func TencentMsyqlBasicInfo() map[string]*schema.Schema {
175175
},
176176
Description: "Security groups to use.",
177177
},
178-
178+
"param_template_id": {
179+
Type: schema.TypeInt,
180+
Optional: true,
181+
Description: "Specify parameter template id.",
182+
},
183+
"fast_upgrade": {
184+
Type: schema.TypeInt,
185+
Optional: true,
186+
Description: "Specify whether to enable fast upgrade when upgrade instance spec, available value: `1` - enabled, `0` - disabled.",
187+
},
179188
"tags": {
180189
Type: schema.TypeMap,
181190
Optional: true,
@@ -430,6 +439,15 @@ func mysqlAllInstanceRoleSet(ctx context.Context, requestInter interface{}, d *s
430439
requestByUse.SecurityGroup = requestSecurityGroup
431440
}
432441
}
442+
443+
if v, ok := d.GetOk("param_template_id"); ok {
444+
paramTemplateId := helper.IntInt64(v.(int))
445+
if okByMonth {
446+
requestByMonth.ParamTemplateId = paramTemplateId
447+
} else {
448+
requestByUse.ParamTemplateId = paramTemplateId
449+
}
450+
}
433451
return nil
434452

435453
}
@@ -1003,8 +1021,12 @@ func mysqlAllInstanceRoleUpdate(ctx context.Context, d *schema.ResourceData, met
10031021
memSize := int64(d.Get("mem_size").(int))
10041022
cpu := int64(d.Get("cpu").(int))
10051023
volumeSize := int64(d.Get("volume_size").(int))
1024+
fastUpgrade := int64(0)
1025+
if v, ok := d.GetOk("fast_upgrade"); ok {
1026+
fastUpgrade = int64(v.(int))
1027+
}
10061028

1007-
asyncRequestId, err := mysqlService.UpgradeDBInstance(ctx, d.Id(), memSize, cpu, volumeSize)
1029+
asyncRequestId, err := mysqlService.UpgradeDBInstance(ctx, d.Id(), memSize, cpu, volumeSize, fastUpgrade)
10081030

10091031
if err != nil {
10101032
return err
@@ -1094,6 +1116,9 @@ func mysqlAllInstanceRoleUpdate(ctx context.Context, d *schema.ResourceData, met
10941116
d.SetPartial("tags")
10951117
}
10961118

1119+
if d.HasChange("param_template_id") {
1120+
return fmt.Errorf("argument `param_template_id` cannot be modified for now")
1121+
}
10971122
return nil
10981123
}
10991124

tencentcloud/resource_tc_mysql_instance_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,10 @@ resource "tencentcloud_mysql_instance" "mysql_master" {
294294

295295
func testAccMysqlMasterInstance_fullslave() string {
296296
return `
297+
variable "temporary_param_tmpl_id" {
298+
default = 16954
299+
}
300+
297301
resource "tencentcloud_mysql_instance" "mysql_master" {
298302
charge_type = "POSTPAID"
299303
mem_size = 1000
@@ -307,6 +311,7 @@ resource "tencentcloud_mysql_instance" "mysql_master" {
307311
first_slave_zone = "ap-guangzhou-3"
308312
second_slave_zone = "ap-guangzhou-3"
309313
slave_sync_mode = 2
314+
param_template_id = var.temporary_param_tmpl_id
310315
force_delete = true
311316
}`
312317
}

tencentcloud/service_tencentcloud_mysql.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,7 @@ func (me *MysqlService) ModifyDBInstanceVipVport(ctx context.Context, mysqlId, v
11081108
}
11091109

11101110
func (me *MysqlService) UpgradeDBInstance(ctx context.Context, mysqlId string,
1111-
memSize, cpu, volumeSize int64) (asyncRequestId string, errRet error) {
1111+
memSize, cpu, volumeSize, fastUpgrade int64) (asyncRequestId string, errRet error) {
11121112

11131113
logId := getLogId(ctx)
11141114

@@ -1120,6 +1120,7 @@ func (me *MysqlService) UpgradeDBInstance(ctx context.Context, mysqlId string,
11201120
request.Cpu = &cpu
11211121
request.Volume = &volumeSize
11221122
request.WaitSwitch = &waitSwitch
1123+
request.FastUpgrade = &fastUpgrade
11231124

11241125
defer func() {
11251126
if errRet != nil {

0 commit comments

Comments
 (0)