Skip to content

Commit 65f38e8

Browse files
gitmknanonymous
andauthored
feat: support first_slave_zone can be modified (#1873)
* feat: support first_slave_zone can be modified * fix: fmt * fix: add change log * fix: modify test * fix: modify second_slave_zone --------- Co-authored-by: anonymous <anonymous@mail.org>
1 parent 6df0bda commit 65f38e8

File tree

5 files changed

+69
-29
lines changed

5 files changed

+69
-29
lines changed

.changelog/1873.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_mysql_instance: Support modifying field `slave_deploy_mode`, `first_slave_zone`, `second_slave_zone`, `slave_sync_mode`.
3+
```

tencentcloud/resource_tc_mysql_instance.go

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ func TencentMsyqlBasicInfo() map[string]*schema.Schema {
190190
"device_type": {
191191
Type: schema.TypeString,
192192
Optional: true,
193+
Computed: true,
193194
Description: "Specify device type, available values: `UNIVERSAL` (default), `EXCLUSIVE`, `BASIC`.",
194195
},
195196
"tags": {
@@ -281,6 +282,7 @@ func resourceTencentCloudMysqlInstance() *schema.Resource {
281282
"first_slave_zone": {
282283
Type: schema.TypeString,
283284
Optional: true,
285+
Computed: true,
284286
Description: "Zone information about first slave instance.",
285287
},
286288
"second_slave_zone": {
@@ -797,11 +799,7 @@ func tencentMsyqlBasicInfoRead(ctx context.Context, d *schema.ResourceData, meta
797799
_ = d.Set("volume_size", mysqlInfo.Volume)
798800
_ = d.Set("vpc_id", mysqlInfo.UniqVpcId)
799801
_ = d.Set("subnet_id", mysqlInfo.UniqSubnetId)
800-
801-
isUniversal := mysqlInfo.DeviceType != nil && *mysqlInfo.DeviceType == "UNIVERSAL"
802-
if _, ok := d.GetOk("device_type"); ok || !isUniversal {
803-
_ = d.Set("device_type", mysqlInfo.DeviceType)
804-
}
802+
_ = d.Set("device_type", mysqlInfo.DeviceType)
805803

806804
securityGroups, err := mysqlService.DescribeDBSecurityGroups(ctx, d.Id())
807805
if err != nil {
@@ -942,14 +940,10 @@ func resourceTencentCloudMysqlInstanceRead(d *schema.ResourceData, meta interfac
942940
_ = d.Set("slave_sync_mode", int(*backConfig.Response.ProtectMode))
943941
_ = d.Set("slave_deploy_mode", int(*backConfig.Response.DeployMode))
944942
if backConfig.Response.SlaveConfig != nil && *backConfig.Response.SlaveConfig.Zone != "" {
945-
if _, ok := d.GetOk("first_slave_zone"); ok {
946-
_ = d.Set("first_slave_zone", *backConfig.Response.SlaveConfig.Zone)
947-
}
943+
_ = d.Set("first_slave_zone", *backConfig.Response.SlaveConfig.Zone)
948944
}
949945
if backConfig.Response.BackupConfig != nil && *backConfig.Response.BackupConfig.Zone != "" {
950-
if _, ok := d.GetOk("second_slave_zone"); ok {
951-
_ = d.Set("second_slave_zone", *backConfig.Response.BackupConfig.Zone)
952-
}
946+
_ = d.Set("second_slave_zone", *backConfig.Response.BackupConfig.Zone)
953947
}
954948
return nil
955949
})
@@ -999,12 +993,16 @@ func mysqlAllInstanceRoleUpdate(ctx context.Context, d *schema.ResourceData, met
999993
}
1000994
}
1001995

1002-
if d.HasChange("mem_size") || d.HasChange("cpu") || d.HasChange("volume_size") || d.HasChange("device_type") {
996+
if d.HasChange("mem_size") || d.HasChange("cpu") || d.HasChange("volume_size") || d.HasChange("device_type") || d.HasChange("slave_deploy_mode") || d.HasChange("first_slave_zone") || d.HasChange("second_slave_zone") || d.HasChange("slave_sync_mode") {
1003997

1004998
memSize := int64(d.Get("mem_size").(int))
1005999
cpu := int64(d.Get("cpu").(int))
10061000
volumeSize := int64(d.Get("volume_size").(int))
1001+
slaveDeployMode := int64(d.Get("slave_deploy_mode").(int))
1002+
slaveSyncMode := int64(d.Get("slave_sync_mode").(int))
10071003
deviceType := ""
1004+
firstSlaveZone := ""
1005+
secondSlaveZone := ""
10081006

10091007
fastUpgrade := int64(0)
10101008
if v, ok := d.GetOk("fast_upgrade"); ok {
@@ -1014,7 +1012,15 @@ func mysqlAllInstanceRoleUpdate(ctx context.Context, d *schema.ResourceData, met
10141012
deviceType = v.(string)
10151013
}
10161014

1017-
asyncRequestId, err := mysqlService.UpgradeDBInstance(ctx, d.Id(), memSize, cpu, volumeSize, fastUpgrade, deviceType)
1015+
if v, ok := d.GetOk("first_slave_zone"); ok {
1016+
firstSlaveZone = v.(string)
1017+
}
1018+
1019+
if v, ok := d.GetOk("second_slave_zone"); ok {
1020+
secondSlaveZone = v.(string)
1021+
}
1022+
1023+
asyncRequestId, err := mysqlService.UpgradeDBInstance(ctx, d.Id(), memSize, cpu, volumeSize, fastUpgrade, deviceType, slaveDeployMode, slaveSyncMode, firstSlaveZone, secondSlaveZone)
10181024

10191025
if err != nil {
10201026
return err
@@ -1327,16 +1333,6 @@ func resourceTencentCloudMysqlInstanceUpdate(d *schema.ResourceData, meta interf
13271333
logId := getLogId(contextNil)
13281334
ctx := context.WithValue(context.TODO(), logIdKey, logId)
13291335

1330-
immutableArgs := []string{
1331-
"slave_deploy_mode", "first_slave_zone", "second_slave_zone", "slave_sync_mode",
1332-
}
1333-
1334-
for _, v := range immutableArgs {
1335-
if d.HasChange(v) {
1336-
return fmt.Errorf("argument `%s` cannot be changed", v)
1337-
}
1338-
}
1339-
13401336
payType := getPayType(d).(int)
13411337

13421338
d.Partial(true)

tencentcloud/resource_tc_mysql_instance_test.go

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
)
1515

1616
const TestAccTencentCloudMysqlMasterInstance_availability_zone = "ap-guangzhou-3"
17+
const TestAccTencentCloudMysqlMasterInstance_availability_zone_4 = "ap-guangzhou-4"
1718
const TestAccTencentCloudMysqlInstanceName = "testAccMysql"
1819

1920
func init() {
@@ -110,18 +111,20 @@ func TestAccTencentCloudMysqlInstanceResource_prepaid(t *testing.T) {
110111
resource.TestCheckResourceAttr("tencentcloud_mysql_instance.prepaid", "charge_type", "PREPAID"),
111112
resource.TestCheckResourceAttrSet("tencentcloud_mysql_instance.prepaid", "vpc_id"),
112113
resource.TestCheckResourceAttrSet("tencentcloud_mysql_instance.prepaid", "subnet_id"),
114+
resource.TestCheckResourceAttrSet("tencentcloud_mysql_instance.prepaid", "first_slave_zone"),
113115
),
114116
},
115117
{
116118
ResourceName: "tencentcloud_mysql_instance.prepaid",
117119
ImportState: true,
118120
ImportStateVerify: true,
119-
ImportStateVerifyIgnore: []string{"root_password", "prepaid_period", "first_slave_zone", "force_delete", "param_template_id", "fast_upgrade"},
121+
ImportStateVerifyIgnore: []string{"root_password", "prepaid_period", "force_delete", "param_template_id", "fast_upgrade"},
120122
},
121123
},
122124
})
123125
}
124126

127+
// go test -i; go test -test.run TestAccTencentCloudMysqlInstanceResource_DeviceType -v
125128
func TestAccTencentCloudMysqlInstanceResource_DeviceType(t *testing.T) {
126129
resource.Test(t, resource.TestCase{
127130
PreCheck: func() { testAccPreCheck(t) },
@@ -133,13 +136,14 @@ func TestAccTencentCloudMysqlInstanceResource_DeviceType(t *testing.T) {
133136
Check: resource.ComposeAggregateTestCheckFunc(
134137
testAccCheckMysqlMasterInstanceExists("tencentcloud_mysql_instance.mysql_exclusive"),
135138
resource.TestCheckResourceAttr("tencentcloud_mysql_instance.mysql_exclusive", "device_type", "EXCLUSIVE"),
139+
resource.TestCheckResourceAttrSet("tencentcloud_mysql_instance.mysql_exclusive", "first_slave_zone"),
136140
),
137141
},
138142
{
139143
ResourceName: "tencentcloud_mysql_instance.mysql_exclusive",
140144
ImportState: true,
141145
ImportStateVerify: true,
142-
ImportStateVerifyIgnore: []string{"root_password", "prepaid_period", "first_slave_zone", "force_delete", "param_template_id", "fast_upgrade"},
146+
ImportStateVerifyIgnore: []string{"root_password", "prepaid_period", "force_delete", "param_template_id", "fast_upgrade"},
143147
},
144148
{
145149
Config: testAccMySQLDeviceTypeUpdate,
@@ -152,6 +156,7 @@ func TestAccTencentCloudMysqlInstanceResource_DeviceType(t *testing.T) {
152156
})
153157
}
154158

159+
// go test -i; go test -test.run TestAccTencentCloudMysqlInstanceResource_MasterInstance_fullslave -v
155160
func TestAccTencentCloudMysqlInstanceResource_MasterInstance_fullslave(t *testing.T) {
156161
resource.Test(t, resource.TestCase{
157162
PreCheck: func() { testAccPreCheck(t) },
@@ -170,6 +175,18 @@ func TestAccTencentCloudMysqlInstanceResource_MasterInstance_fullslave(t *testin
170175
resource.TestCheckResourceAttr("tencentcloud_mysql_instance.mysql_master", "second_slave_zone", TestAccTencentCloudMysqlMasterInstance_availability_zone),
171176
),
172177
},
178+
{
179+
Config: testAccMysqlMasterInstanceUp_fullslave(),
180+
Check: resource.ComposeAggregateTestCheckFunc(
181+
testAccCheckMysqlMasterInstanceExists("tencentcloud_mysql_instance.mysql_master"),
182+
resource.TestCheckResourceAttr("tencentcloud_mysql_instance.mysql_master", "instance_name", TestAccTencentCloudMysqlInstanceName),
183+
resource.TestCheckResourceAttr("tencentcloud_mysql_instance.mysql_master", "slave_deploy_mode", "1"),
184+
resource.TestCheckResourceAttr("tencentcloud_mysql_instance.mysql_master", "slave_sync_mode", "1"),
185+
resource.TestCheckResourceAttr("tencentcloud_mysql_instance.mysql_master", "availability_zone", TestAccTencentCloudMysqlMasterInstance_availability_zone),
186+
resource.TestCheckResourceAttr("tencentcloud_mysql_instance.mysql_master", "first_slave_zone", TestAccTencentCloudMysqlMasterInstance_availability_zone_4),
187+
resource.TestCheckResourceAttr("tencentcloud_mysql_instance.mysql_master", "second_slave_zone", TestAccTencentCloudMysqlMasterInstance_availability_zone_4),
188+
),
189+
},
173190
},
174191
})
175192
}
@@ -408,7 +425,7 @@ resource "tencentcloud_mysql_instance" "prepaid" {
408425

409426
const testAccMySQLDeviceType = `
410427
variable "temporary_param_tmpl_id" {
411-
default = 16954
428+
default = 19656
412429
}
413430
414431
resource "tencentcloud_mysql_instance" "mysql_exclusive" {
@@ -430,7 +447,7 @@ resource "tencentcloud_mysql_instance" "mysql_exclusive" {
430447

431448
const testAccMySQLDeviceTypeUpdate = `
432449
variable "temporary_param_tmpl_id" {
433-
default = 16954
450+
default = 19656
434451
}
435452
436453
resource "tencentcloud_mysql_instance" "mysql_exclusive" {
@@ -486,6 +503,25 @@ resource "tencentcloud_mysql_instance" "mysql_master" {
486503
}`
487504
}
488505

506+
func testAccMysqlMasterInstanceUp_fullslave() string {
507+
return `
508+
resource "tencentcloud_mysql_instance" "mysql_master" {
509+
charge_type = "POSTPAID"
510+
mem_size = 1000
511+
volume_size = 50
512+
instance_name = "testAccMysql"
513+
engine_version = "5.7"
514+
root_password = "test1234"
515+
intranet_port = 3360
516+
availability_zone = "ap-guangzhou-3"
517+
slave_deploy_mode = 1
518+
first_slave_zone = "ap-guangzhou-4"
519+
second_slave_zone = "ap-guangzhou-4"
520+
slave_sync_mode = 1
521+
force_delete = true
522+
}`
523+
}
524+
489525
func testAccMysqlMasterInstance_internet_service(open bool) string {
490526
tag := "0"
491527
if open {

tencentcloud/resource_tc_mysql_password_complexity.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func resourceTencentCloudMysqlPasswordComplexityCreate(d *schema.ResourceData, m
8787

8888
d.SetId(instanceId)
8989

90-
return resourceTencentCloudMysqlPasswordComplexityRead(d, meta)
90+
return resourceTencentCloudMysqlPasswordComplexityUpdate(d, meta)
9191
}
9292

9393
func resourceTencentCloudMysqlPasswordComplexityRead(d *schema.ResourceData, meta interface{}) error {

tencentcloud/service_tencentcloud_mysql.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,8 @@ func (me *MysqlService) ModifyDBInstanceVipVport(ctx context.Context, mysqlId, v
11411141
}
11421142

11431143
func (me *MysqlService) UpgradeDBInstance(ctx context.Context, mysqlId string,
1144-
memSize, cpu, volumeSize, fastUpgrade int64, deviceType string) (asyncRequestId string, errRet error) {
1144+
memSize, cpu, volumeSize, fastUpgrade int64, deviceType string, slaveDeployMode, slaveSyncMode int64,
1145+
firstSlaveZone, secondSlaveZone string) (asyncRequestId string, errRet error) {
11451146

11461147
logId := getLogId(ctx)
11471148

@@ -1154,6 +1155,10 @@ func (me *MysqlService) UpgradeDBInstance(ctx context.Context, mysqlId string,
11541155
request.Volume = &volumeSize
11551156
request.WaitSwitch = &waitSwitch
11561157
request.FastUpgrade = &fastUpgrade
1158+
request.DeployMode = &slaveDeployMode
1159+
request.SlaveZone = &firstSlaveZone
1160+
request.BackupZone = &secondSlaveZone
1161+
request.ProtectMode = &slaveSyncMode
11571162
if deviceType != "" {
11581163
request.DeviceType = &deviceType
11591164
}

0 commit comments

Comments
 (0)