Skip to content

Commit 1cadd27

Browse files
tongyimingmikatong
andauthored
fix: support ro-mysql cross-zone purchase and query remoteRoZones (#918)
* fix: support ro-mysql cross-zone purchase and query remoteRoZones * fix: tke unit test Co-authored-by: mikatong <mikatong@tencent.com>
1 parent a6315d6 commit 1cadd27

8 files changed

+43
-45
lines changed

tencentcloud/basic_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ const CommonPresetMysql = `
134134
variable "availability_zone" {
135135
default = "` + defaultAZone + `"
136136
}
137+
variable "region" {
138+
default = "` + defaultRegion + `"
139+
}
137140
138141
data "tencentcloud_mysql_instance" "mysql" {
139142
instance_name = "` + defaultMySQLName + `"

tencentcloud/data_source_tc_mysql_zone_config.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ func TencentMysqlZoneConfig() map[string]*schema.Schema {
126126
Computed: true,
127127
Description: "Zone information about second slave instance.",
128128
},
129+
"remote_ro_zones": {
130+
Type: schema.TypeList,
131+
Elem: &schema.Schema{Type: schema.TypeString},
132+
Computed: true,
133+
Description: "Zone information about remote ro instance.",
134+
},
129135
"sells": {Type: schema.TypeList,
130136
Computed: true,
131137
Description: "A list of supported instance types for sell:",
@@ -250,9 +256,9 @@ func dataSourceTencentMysqlZoneConfigRead(d *schema.ResourceData, meta interface
250256
zoneConfig["disaster_recovery_zones"] = disasterRecoveryZones
251257

252258
var (
253-
slaveDeployModes []int
254-
firstSlaveZones, secondSlaveZones, engineVersions []string
255-
sells []interface{}
259+
slaveDeployModes []int
260+
firstSlaveZones, secondSlaveZones, engineVersions, remoteRoZones []string
261+
sells []interface{}
256262
)
257263
if sellItem.ZoneConf != nil {
258264
for _, mode := range sellItem.ZoneConf.DeployMode {
@@ -264,10 +270,14 @@ func dataSourceTencentMysqlZoneConfigRead(d *schema.ResourceData, meta interface
264270
for _, zoneName := range sellItem.ZoneConf.BackupZone {
265271
secondSlaveZones = append(secondSlaveZones, *zoneName)
266272
}
273+
for _, zoneName := range sellItem.RemoteRoZone {
274+
remoteRoZones = append(remoteRoZones, *zoneName)
275+
}
267276
}
268277
zoneConfig["slave_deploy_modes"] = slaveDeployModes
269278
zoneConfig["first_slave_zones"] = firstSlaveZones
270279
zoneConfig["second_slave_zones"] = secondSlaveZones
280+
zoneConfig["remote_ro_zones"] = remoteRoZones
271281

272282
for _, mysqlConfigs := range sellItem.SellType {
273283
for _, strPtr := range mysqlConfigs.EngineVersion {

tencentcloud/data_source_tc_mysql_zone_config_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ func TestAccDataSourceMysqlZoneConfig_basic(t *testing.T) {
2929
resource.TestCheckResourceAttrSet("data.tencentcloud_mysql_zone_config.test", "list.0.slave_deploy_modes.#"),
3030
resource.TestCheckResourceAttrSet("data.tencentcloud_mysql_zone_config.test", "list.0.first_slave_zones.#"),
3131
resource.TestCheckResourceAttrSet("data.tencentcloud_mysql_zone_config.test", "list.0.second_slave_zones.#"),
32+
resource.TestCheckResourceAttrSet("data.tencentcloud_mysql_zone_config.test", "list.0.remote_ro_zones.#"),
3233
resource.TestCheckResourceAttrSet("data.tencentcloud_mysql_zone_config.test", "list.0.sells.#"),
3334
resource.TestCheckResourceAttrSet("data.tencentcloud_mysql_zone_config.test", "list.0.sells.0.mem_size"),
3435
resource.TestCheckResourceAttrSet("data.tencentcloud_mysql_zone_config.test", "list.0.sells.0.min_volume_size"),
@@ -53,6 +54,7 @@ func TestAccDataSourceMysqlZoneConfig_basic(t *testing.T) {
5354
resource.TestCheckResourceAttrSet("data.tencentcloud_mysql_zone_config.testWithRegion", "list.0.slave_deploy_modes.#"),
5455
resource.TestCheckResourceAttrSet("data.tencentcloud_mysql_zone_config.testWithRegion", "list.0.first_slave_zones.#"),
5556
resource.TestCheckResourceAttrSet("data.tencentcloud_mysql_zone_config.testWithRegion", "list.0.second_slave_zones.#"),
57+
resource.TestCheckResourceAttrSet("data.tencentcloud_mysql_zone_config.testWithRegion", "list.0.remote_ro_zones.#"),
5658
resource.TestCheckResourceAttrSet("data.tencentcloud_mysql_zone_config.testWithRegion", "list.0.sells.#"),
5759
resource.TestCheckResourceAttrSet("data.tencentcloud_mysql_zone_config.testWithRegion", "list.0.sells.0.mem_size"),
5860
resource.TestCheckResourceAttrSet("data.tencentcloud_mysql_zone_config.testWithRegion", "list.0.sells.0.min_volume_size"),

tencentcloud/resource_tc_kubernetes_cluster_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ func TestAccTencentCloudTkeResource(t *testing.T) {
3939
resource.TestCheckResourceAttrSet(testTkeClusterResourceKey, "cluster_external_endpoint"),
4040
resource.TestCheckResourceAttr(testTkeClusterResourceKey, "labels.test1", "test1"),
4141
resource.TestCheckResourceAttr(testTkeClusterResourceKey, "labels.test2", "test2"),
42-
resource.TestCheckResourceAttr(testTkeClusterResourceKey, "unschedulable", "0"),
4342
),
4443
},
4544
{
@@ -155,14 +154,15 @@ data "tencentcloud_vpc_subnets" "vpc" {
155154
}
156155
157156
resource "tencentcloud_kubernetes_cluster" "managed_cluster" {
158-
vpc_id = data.tencentcloud_vpc_subnets.vpc.instance_list.0.vpc_id
157+
vpc_id = "vpc-rkojp4kn"
159158
cluster_cidr = var.cluster_cidr
160159
cluster_max_pod_num = 32
161160
cluster_name = "test"
162161
cluster_desc = "test cluster desc"
163162
cluster_max_service_num = 32
164163
cluster_internet = true
165164
cluster_version = "1.18.4"
165+
cluster_os = "tlinux2.2(tkernel3)x86_64"
166166
managed_cluster_internet_security_policies = ["3.3.3.3", "1.1.1.1"]
167167
worker_config {
168168
count = 1
@@ -173,7 +173,7 @@ resource "tencentcloud_kubernetes_cluster" "managed_cluster" {
173173
internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR"
174174
internet_max_bandwidth_out = 100
175175
public_ip_assigned = true
176-
subnet_id = data.tencentcloud_vpc_subnets.vpc.instance_list.0.subnet_id
176+
subnet_id = "subnet-fmcdf57e"
177177
img_id = "img-rkiynh11"
178178
179179
data_disk {
@@ -189,7 +189,7 @@ resource "tencentcloud_kubernetes_cluster" "managed_cluster" {
189189
enhanced_monitor_service = false
190190
user_data = "dGVzdA=="
191191
password = "ZZXXccvv1212"
192-
cam_role_name = "CVM_QcsRole"
192+
cam_role_name = "TKE_TEST"
193193
}
194194
195195
cluster_deploy_type = "MANAGED_CLUSTER"

tencentcloud/resource_tc_mysql_readonly_instance.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ func resourceTencentCloudMysqlReadonlyInstance() *schema.Resource {
5252
ForceNew: true,
5353
Description: "Zone information, this parameter defaults to, the system automatically selects an Availability Zone.",
5454
},
55+
"master_region": {
56+
Type: schema.TypeString,
57+
ForceNew: true,
58+
Optional: true,
59+
Description: "The zone information of the primary instance is required when you purchase a disaster recovery instance.",
60+
},
5561
}
5662

5763
basic := TencentMsyqlBasicInfo()
@@ -102,6 +108,11 @@ func mysqlCreateReadonlyInstancePayByMonth(ctx context.Context, d *schema.Resour
102108
zone := v.(string)
103109
request.Zone = &zone
104110
}
111+
if v, ok := d.GetOk("master_region"); ok {
112+
masterRegion := v.(string)
113+
request.MasterRegion = &masterRegion
114+
}
115+
105116
autoRenewFlag := int64(d.Get("auto_renew_flag").(int))
106117
request.AutoRenewFlag = &autoRenewFlag
107118

@@ -166,6 +177,10 @@ func mysqlCreateReadonlyInstancePayByUse(ctx context.Context, d *schema.Resource
166177
zone := v.(string)
167178
request.Zone = &zone
168179
}
180+
if v, ok := d.GetOk("master_region"); ok {
181+
masterRegion := v.(string)
182+
request.MasterRegion = &masterRegion
183+
}
169184

170185
response, err := meta.(*TencentCloudClient).apiV3Conn.UseMysqlClient().CreateDBInstanceHour(request)
171186
if err != nil {
@@ -309,6 +324,7 @@ func resourceTencentCloudMysqlReadonlyInstanceRead(d *schema.ResourceData, meta
309324
}
310325
_ = d.Set("master_instance_id", *mysqlInfo.MasterInfo.InstanceId)
311326
_ = d.Set("zone", *mysqlInfo.Zone)
327+
_ = d.Set("master_region", *mysqlInfo.MasterInfo.Region)
312328

313329
return nil
314330
})

tencentcloud/resource_tc_mysql_readonly_instance_test.go

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ resource "tencentcloud_mysql_readonly_instance" "mysql_readonly" {
133133
volume_size = 200
134134
instance_name = "mysql-readonly-test"
135135
intranet_port = 3360
136+
master_region = var.region
136137
zone = var.availability_zone
137138
tags = {
138139
test = "test-tf"
@@ -151,6 +152,7 @@ resource "tencentcloud_mysql_readonly_instance" "mysql_readonly" {
151152
volume_size = 200
152153
instance_name = "mysql-readonly-test"
153154
intranet_port = 3360
155+
master_region = var.region
154156
zone = var.availability_zone
155157
tags = {
156158
test = "test-tf"
@@ -170,48 +172,11 @@ resource "tencentcloud_mysql_readonly_instance" "mysql_readonly" {
170172
volume_size = 200
171173
instance_name = "%s"
172174
intranet_port = %s
175+
master_region = var.region
173176
zone = var.availability_zone
174177
tags = {
175178
test = "test-tf"
176179
}
177180
}
178181
`, mysqlTestCase, instance_name, instranet_port)
179182
}
180-
181-
func testAccMysqlReadonlyInstancePrepaid(mysqlTestCase string) string {
182-
return fmt.Sprintf(`
183-
%s
184-
resource "tencentcloud_mysql_readonly_instance" "mysql_readonly_prepaid" {
185-
master_instance_id = local.mysql_id
186-
mem_size = 2000
187-
cpu = 1
188-
volume_size = 200
189-
instance_name = "mysql-readonly-test"
190-
intranet_port = 3360
191-
pay_type = 0
192-
force_delete = true
193-
tags = {
194-
test = "test-tf"
195-
}
196-
}
197-
`, mysqlTestCase)
198-
}
199-
200-
func testAccMysqlReadonlyInstancePrepaid_update(mysqlTestCase string, renewFlag int) string {
201-
return fmt.Sprintf(`
202-
%s
203-
resource "tencentcloud_mysql_readonly_instance" "mysql_readonly_prepaid" {
204-
master_instance_id = local.mysql_id
205-
mem_size = 2000
206-
volume_size = 200
207-
instance_name = "mysql-readonly-test"
208-
intranet_port = 3360
209-
auto_renew_flag = %d
210-
tags = {
211-
test = "test-tf"
212-
}
213-
pay_type = 0
214-
force_delete = true
215-
}
216-
`, mysqlTestCase, renewFlag)
217-
}

website/docs/d/mysql_zone_config.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ In addition to all arguments above, the following attributes are exported:
3939
* `is_support_disaster_recovery` - Indicates whether recovery is supported: `0` - No; `1` - Yes.
4040
* `is_support_vpc` - Indicates whether VPC is supported: `0` - No; `1` - Yes.
4141
* `name` - The name of available zone which is equal to a specific datacenter.
42+
* `remote_ro_zones` - Zone information about remote ro instance.
4243
* `second_slave_zones` - Zone information about second slave instance.
4344
* `sells` - A list of supported instance types for sell:
4445
* `max_volume_size` - Maximum disk size (in GB).

website/docs/r/mysql_readonly_instance.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ The following arguments are supported:
4646
* `cpu` - (Optional) CPU cores.
4747
* `force_delete` - (Optional) Indicate whether to delete instance directly or not. Default is `false`. If set true, the instance will be deleted instead of staying recycle bin. Note: only works for `PREPAID` instance. When the main mysql instance set true, this para of the readonly mysql instance will not take effect.
4848
* `intranet_port` - (Optional) Public access port. Valid value ranges: [1024~65535]. The default value is `3306`.
49+
* `master_region` - (Optional, ForceNew) The zone information of the primary instance is required when you purchase a disaster recovery instance.
4950
* `pay_type` - (Optional, **Deprecated**) It has been deprecated from version 1.36.0. Please use `charge_type` instead. Pay type of instance. Valid values: `0`, `1`. `0`: prepaid, `1`: postpaid.
5051
* `period` - (Optional, **Deprecated**) It has been deprecated from version 1.36.0. Please use `prepaid_period` instead. Period of instance. NOTES: Only supported prepaid instance.
5152
* `prepaid_period` - (Optional) Period of instance. NOTES: Only supported prepaid instance.

0 commit comments

Comments
 (0)