Skip to content

Commit 1e2bcfc

Browse files
tongyimingmikatong
andauthored
Fix/mysql zone (#913)
* fix: ro mysql support one param * fix: add mysql zone doc Co-authored-by: mikatong <[email protected]>
1 parent bac92f9 commit 1e2bcfc

File tree

4 files changed

+34
-8
lines changed

4 files changed

+34
-8
lines changed

tencentcloud/basic_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ const (
130130

131131
// ref with `local.mysql_id`
132132
const CommonPresetMysql = `
133+
134+
variable "availability_zone" {
135+
default = "` + defaultAZone + `"
136+
}
137+
133138
data "tencentcloud_mysql_instance" "mysql" {
134139
instance_name = "` + defaultMySQLName + `"
135140
}

tencentcloud/resource_tc_mysql_readonly_instance.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ func resourceTencentCloudMysqlReadonlyInstance() *schema.Resource {
4646
Required: true,
4747
Description: "Indicates the master instance ID of recovery instances.",
4848
},
49+
"zone": {
50+
Type: schema.TypeString,
51+
Optional: true,
52+
ForceNew: true,
53+
Description: "Zone information, this parameter defaults to, the system automatically selects an Availability Zone.",
54+
},
4955
}
5056

5157
basic := TencentMsyqlBasicInfo()
@@ -92,6 +98,10 @@ func mysqlCreateReadonlyInstancePayByMonth(ctx context.Context, d *schema.Resour
9298
request.Cpu = helper.IntInt64(v.(int))
9399
}
94100

101+
if v, ok := d.GetOk("zone"); ok {
102+
zone := v.(string)
103+
request.Zone = &zone
104+
}
95105
autoRenewFlag := int64(d.Get("auto_renew_flag").(int))
96106
request.AutoRenewFlag = &autoRenewFlag
97107

@@ -152,6 +162,11 @@ func mysqlCreateReadonlyInstancePayByUse(ctx context.Context, d *schema.Resource
152162
return err
153163
}
154164

165+
if v, ok := d.GetOk("zone"); ok {
166+
zone := v.(string)
167+
request.Zone = &zone
168+
}
169+
155170
response, err := meta.(*TencentCloudClient).apiV3Conn.UseMysqlClient().CreateDBInstanceHour(request)
156171
if err != nil {
157172
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n",
@@ -293,6 +308,8 @@ func resourceTencentCloudMysqlReadonlyInstanceRead(d *schema.ResourceData, meta
293308
return nil
294309
}
295310
_ = d.Set("master_instance_id", *mysqlInfo.MasterInfo.InstanceId)
311+
_ = d.Set("zone", *mysqlInfo.Zone)
312+
296313
return nil
297314
})
298315
if err != nil {

tencentcloud/resource_tc_mysql_readonly_instance_test.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ func TestAccTencentCloudMysqlReadonlyInstance(t *testing.T) {
6363
resource.TestCheckResourceAttr("tencentcloud_mysql_readonly_instance.mysql_readonly", "instance_name", "mysql-readonly-update"),
6464
),
6565
},
66-
// update intranet_port
67-
{
68-
Config: testAccMysqlReadonlyInstance_update(CommonPresetMysql, "mysql-readonly-update", "3361"),
69-
Check: resource.ComposeAggregateTestCheckFunc(
70-
testAccCheckMysqlInstanceExists("tencentcloud_mysql_readonly_instance.mysql_readonly"),
71-
resource.TestCheckResourceAttr("tencentcloud_mysql_readonly_instance.mysql_readonly", "intranet_port", "3361"),
72-
),
73-
},
66+
// // update intranet_port
67+
// {
68+
// Config: testAccMysqlReadonlyInstance_update(CommonPresetMysql, "mysql-readonly-update", "3361"),
69+
// Check: resource.ComposeAggregateTestCheckFunc(
70+
// testAccCheckMysqlInstanceExists("tencentcloud_mysql_readonly_instance.mysql_readonly"),
71+
// resource.TestCheckResourceAttr("tencentcloud_mysql_readonly_instance.mysql_readonly", "intranet_port", "3361"),
72+
// ),
73+
// },
7474
},
7575
})
7676
}
@@ -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+
zone = var.availability_zone
136137
tags = {
137138
test = "test-tf"
138139
}
@@ -150,6 +151,7 @@ resource "tencentcloud_mysql_readonly_instance" "mysql_readonly" {
150151
volume_size = 200
151152
instance_name = "mysql-readonly-test"
152153
intranet_port = 3360
154+
zone = var.availability_zone
153155
tags = {
154156
test = "test-tf"
155157
role = "%s"
@@ -168,6 +170,7 @@ resource "tencentcloud_mysql_readonly_instance" "mysql_readonly" {
168170
volume_size = 200
169171
instance_name = "%s"
170172
intranet_port = %s
173+
zone = var.availability_zone
171174
tags = {
172175
test = "test-tf"
173176
}

website/docs/r/mysql_readonly_instance.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ The following arguments are supported:
5353
* `subnet_id` - (Optional) Private network ID. If `vpc_id` is set, this value is required.
5454
* `tags` - (Optional) Instance tags.
5555
* `vpc_id` - (Optional) ID of VPC, which can be modified once every 24 hours and can't be removed.
56+
* `zone` - (Optional, ForceNew) Zone information, this parameter defaults to, the system automatically selects an Availability Zone.
5657

5758
## Attributes Reference
5859

0 commit comments

Comments
 (0)