Skip to content

Commit 08969d9

Browse files
authored
fix: mysql - 8.0 lowercase ignore and fix testcases (#972)
1 parent 74cb387 commit 08969d9

File tree

4 files changed

+73
-4
lines changed

4 files changed

+73
-4
lines changed

tencentcloud/resource_tc_mysql_account_test.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,80 @@ package tencentcloud
33
import (
44
"context"
55
"fmt"
6+
"log"
67
"strings"
78
"testing"
9+
"time"
10+
11+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
812

913
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
1014
"github.com/hashicorp/terraform-plugin-sdk/terraform"
1115
cdb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdb/v20170320"
1216
sdkError "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
1317
)
1418

19+
func init() {
20+
// go test -v ./tencentcloud -sweep=ap-guangzhou -sweep-run=tencentcloud_mysql_account
21+
resource.AddTestSweepers("tencentcloud_mysql_account", &resource.Sweeper{
22+
Name: "tencentcloud_mysql_account",
23+
F: func(r string) error {
24+
logId := getLogId(contextNil)
25+
ctx := context.WithValue(context.TODO(), logIdKey, logId)
26+
cli, _ := sharedClientForRegion(r)
27+
client := cli.(*TencentCloudClient).apiV3Conn
28+
29+
service := MysqlService{client}
30+
31+
request := cdb.NewDescribeDBInstancesRequest()
32+
request.InstanceNames = []*string{
33+
helper.String(defaultMySQLName),
34+
}
35+
response, err := client.UseMysqlClient().DescribeDBInstances(request)
36+
if err != nil {
37+
log.Printf("[CRITICAL] [%s] fail, request: %s, reason: %s", request.GetAction(), request.ToJsonString(), err.Error())
38+
return err
39+
}
40+
41+
if len(response.Response.Items) == 0 {
42+
return nil
43+
}
44+
45+
instance := response.Response.Items[0]
46+
id := instance.InstanceId
47+
48+
accounts, err := service.DescribeAccounts(ctx, *id)
49+
50+
if err != nil {
51+
return err
52+
}
53+
54+
for i := range accounts {
55+
item := accounts[i]
56+
name := *item.User
57+
host := *item.Host
58+
created, err := time.Parse(time.RFC3339, *item.CreateTime)
59+
if err != nil {
60+
created = time.Time{}
61+
}
62+
if isResourcePersist(name, &created) {
63+
continue
64+
}
65+
if !strings.Contains(name, "test") {
66+
continue
67+
}
68+
log.Printf("Will delete %s %s@%s", *id, name, host)
69+
_, err = service.DeleteAccount(ctx, *id, name, host)
70+
if err != nil {
71+
continue
72+
}
73+
}
74+
75+
return nil
76+
},
77+
})
78+
}
79+
1580
func TestAccTencentCloudMysqlAccountResource(t *testing.T) {
1681
t.Parallel()
1782
resource.Test(t, resource.TestCase{

tencentcloud/resource_tc_mysql_instance.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,12 +624,18 @@ func resourceTencentCloudMysqlInstanceCreate(d *schema.ResourceData, meta interf
624624

625625
// Initialize mysql instance
626626
var (
627+
version = d.Get("engine_version").(string)
627628
password = d.Get("root_password").(string)
628629
charset = d.Get("parameters.character_set_server").(string)
629630
lowercase = d.Get("parameters.lower_case_table_names").(string)
630631
vPort int
631632
)
632633

634+
// 8.0 does not support lower_case_table_names modified, skip this params
635+
if version == "8.0" {
636+
lowercase = ""
637+
}
638+
633639
port, portOk := d.GetOk("intranet_port")
634640

635641
if portOk && port.(int) != 0 {

tencentcloud/resource_tc_mysql_instance_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ func testSweepMySQLInstance(region string) error {
9797
}
9898

9999
func TestAccTencentCloudMysqlMasterInstance_fullslave(t *testing.T) {
100-
t.Parallel()
101100
resource.Test(t, resource.TestCase{
102101
PreCheck: func() { testAccPreCheck(t) },
103102
Providers: testAccProviders,
@@ -120,7 +119,6 @@ func TestAccTencentCloudMysqlMasterInstance_fullslave(t *testing.T) {
120119
}
121120

122121
func TestAccTencentCloudMysqlMasterInstance_basic_and_update(t *testing.T) {
123-
t.Parallel()
124122
resource.Test(t, resource.TestCase{
125123
PreCheck: func() { testAccPreCheck(t) },
126124
Providers: testAccProviders,

tencentcloud/resource_tc_mysql_privilege_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func testAccMysqlPrivilege() string {
186186
%s
187187
resource "tencentcloud_mysql_account" "mysql_account" {
188188
mysql_id = local.mysql_id
189-
name = "test11"
189+
name = "test11priv"
190190
host = "119.168.110.%%"
191191
password = "test1234"
192192
description = "test from terraform"
@@ -220,7 +220,7 @@ func testAccMysqlPrivilegeUpdate() string {
220220
%s
221221
resource "tencentcloud_mysql_account" "mysql_account" {
222222
mysql_id = local.mysql_id
223-
name = "test11"
223+
name = "test11priv"
224224
host = "119.168.110.%%"
225225
password = "test1234"
226226
description = "test from terraform"

0 commit comments

Comments
 (0)