From cdf1faf7778e394969619bedce8f8429ae5be082 Mon Sep 17 00:00:00 2001 From: Arunma <41282634+gitmkn@users.noreply.github.com> Date: Mon, 5 Feb 2024 16:31:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Support=20configuration=20modification?= =?UTF-8?q?=20when=20active/standby=20switchove=E2=80=A6=20(#2516)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: Support configuration modification when active/standby switchover occurs * feat: add 2516 changelog --- .changelog/2516.txt | 3 +++ .../cdb/resource_tc_mysql_instance.go | 23 +++++++++++++++---- .../cdb/resource_tc_mysql_instance_test.go | 2 +- 3 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 .changelog/2516.txt 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"