diff --git a/.changelog/2516.txt b/.changelog/2516.txt new file mode 100644 index 0000000000..473360a8ed --- /dev/null +++ b/.changelog/2516.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/tencentcloud_mysql_instance: Support configuration modification when active/standby switchover occurs. +``` diff --git a/tencentcloud/services/cdb/resource_tc_mysql_instance.go b/tencentcloud/services/cdb/resource_tc_mysql_instance.go index 9da7393edf..f7349e7420 100644 --- a/tencentcloud/services/cdb/resource_tc_mysql_instance.go +++ b/tencentcloud/services/cdb/resource_tc_mysql_instance.go @@ -1083,12 +1083,25 @@ func mysqlAllInstanceRoleUpdate(ctx context.Context, d *schema.ResourceData, met deviceType = v.(string) } - if v, ok := d.GetOk("first_slave_zone"); ok { - firstSlaveZone = v.(string) - } + if d.HasChange("first_slave_zone") || d.HasChange("second_slave_zone") { + if v, ok := d.GetOk("first_slave_zone"); ok { + firstSlaveZone = v.(string) + } - if v, ok := d.GetOk("second_slave_zone"); ok { - secondSlaveZone = v.(string) + if v, ok := d.GetOk("second_slave_zone"); ok { + secondSlaveZone = v.(string) + } + } else { + mysqlInfo, e := tencentMsyqlBasicInfoRead(ctx, d, meta, true) + if e != nil { + return e + } + if mysqlInfo != nil && mysqlInfo.SlaveInfo != nil && mysqlInfo.SlaveInfo.First != nil && mysqlInfo.SlaveInfo.First.Zone != nil { + firstSlaveZone = *mysqlInfo.SlaveInfo.First.Zone + } + if mysqlInfo != nil && mysqlInfo.SlaveInfo != nil && mysqlInfo.SlaveInfo.Second != nil && mysqlInfo.SlaveInfo.Second.Zone != nil { + firstSlaveZone = *mysqlInfo.SlaveInfo.Second.Zone + } } if v, ok := d.GetOkExists("wait_switch"); ok { diff --git a/tencentcloud/services/cdb/resource_tc_mysql_instance_test.go b/tencentcloud/services/cdb/resource_tc_mysql_instance_test.go index 7aebc1cc3a..dae3005d50 100644 --- a/tencentcloud/services/cdb/resource_tc_mysql_instance_test.go +++ b/tencentcloud/services/cdb/resource_tc_mysql_instance_test.go @@ -642,7 +642,7 @@ resource "tencentcloud_mysql_instance" "mysql8" { mem_size = 1000 volume_size = 25 intranet_port = 3306 - security_groups = ["sg-3k7vtgf7"] + security_groups = ["sg-05f7wnhn"] tags = { createdBy = "terraform"