Skip to content

Commit 29408c9

Browse files
otherchenAndrew Chenzph
authored
Fixes TF drift for resource group name and query_limit (#6)
This fixes the following drift: 1. Resource group name would always be in quotes when pulled from the DB. This PR removes the quotes. 2. Query Limit would always be missing `()` parentheses when pulled from the DB. This PR standardizes around the query_limit inside the parentheses. A breaking change is that we expect NO parenthesis to be passed in for the query_limit from now on. Instead, we will wrap the query_limit inside parentheses in the actual query rather than rely on the query_limit string being wrapped in parentheses by the caller. I also got basic tidb tests working and tested the above changes using `make testtidb7.5.1` --------- Co-authored-by: Andrew Chen <andrewchen@plaid.com> Co-authored-by: Zander Hill <zander@xargs.io>
1 parent cc4f335 commit 29408c9

8 files changed

+183
-163
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
branches: ["master"]
66
tags: ["*"]
77
pull_request:
8-
branches: [ "master" ]
8+
branches: [ "*" ]
99
jobs:
1010
lint:
1111
runs-on: ubuntu-22.04
@@ -38,7 +38,6 @@ jobs:
3838
# Track https://github.com/pingcap/tidb/tags
3939
- testtidb6.1.0
4040
- testtidb6.5.3
41-
# Fails because not yet available? 20240705
4241
# - testtidb6.5.10
4342
- testtidb7.1.5
4443
- testtidb7.5.2

GNUmakefile

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,29 @@ TEST?=$$(go list ./... |grep -v 'vendor')
22
GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor)
33
WEBSITE_REPO=github.com/hashicorp/terraform-website
44
PKG_NAME=mysql
5-
TERRAFORM_VERSION=0.14.7
5+
# Last version before hashicorp relicensing to BSL
6+
TERRAFORM_VERSION=1.5.6
67
TERRAFORM_OS=$(shell uname -s | tr A-Z a-z)
78
TEST_USER=root
89
TEST_PASSWORD=my-secret-pw
910
DATESTAMP=$(shell date "+%Y%m%d")
1011
SHA_SHORT=$(shell git describe --match=FORCE_NEVER_MATCH --always --abbrev=40 --dirty --abbrev)
1112
MOST_RECENT_UPSTREAM_TAG=$(shell git for-each-ref refs/tags --sort=-taggerdate --format="%(refname)" | head -1 | grep -E -o "v\d+\.\d+\.\d+")
1213

13-
OS_ARCH=linux_amd64
1414
# Set correct OS_ARCH on Mac
1515
UNAME := $(shell uname -s)
16+
HW := $(shell uname -m)
17+
ifeq ($(HW),arm64)
18+
ARCH=$(HW)
19+
else
20+
ARCH=amd64
21+
endif
22+
1623
ifeq ($(UNAME),Darwin)
17-
HW := $(shell uname -m)
18-
ifeq ($(HW),arm64)
19-
ARCH=$(HW)
20-
else
21-
ARCH=amd64
22-
endif
2324
OS_ARCH=darwin_$(ARCH)
25+
else
26+
ARCH=amd64
27+
OS_ARCH=linux_$(ARCH)
2428
endif
2529

2630
HOSTNAME=registry.terraform.io
@@ -39,7 +43,7 @@ test: acceptance
3943

4044
bin/terraform:
4145
mkdir -p "$(CURDIR)/bin"
42-
curl -sfL https://releases.hashicorp.com/terraform/$(TERRAFORM_VERSION)/terraform_$(TERRAFORM_VERSION)_$(TERRAFORM_OS)_amd64.zip > $(CURDIR)/bin/terraform.zip
46+
curl -sfL https://releases.hashicorp.com/terraform/$(TERRAFORM_VERSION)/terraform_$(TERRAFORM_VERSION)_$(TERRAFORM_OS)_$(ARCH).zip > $(CURDIR)/bin/terraform.zip
4347
(cd $(CURDIR)/bin/ ; unzip terraform.zip)
4448

4549
testacc: fmtcheck bin/terraform

mysql/provider_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,42 @@ func testAccPreCheckSkipNotTiDB(t *testing.T) {
217217
t.Skip(msg)
218218
}
219219
}
220+
221+
func testAccPreCheckSkipNotTiDBVersionMin(t *testing.T, minVersion string) {
222+
testAccPreCheck(t)
223+
224+
ctx := context.Background()
225+
db, err := connectToMySQL(ctx, testAccProvider.Meta().(*MySQLConfiguration))
226+
if err != nil {
227+
t.Fatalf("Cannot connect to DB (SkipNotTiDBVersionMin): %v", err)
228+
return
229+
}
230+
231+
currentVersion, err := serverVersion(db)
232+
if err != nil {
233+
t.Fatalf("Cannot get DB version string (SkipNotTiDBVersionMin): %v", err)
234+
return
235+
}
236+
237+
versionMin, _ := version.NewVersion(minVersion)
238+
if currentVersion.LessThan(versionMin) {
239+
isTiDB, tidbVersion, _, err := serverTiDB(db)
240+
if err != nil {
241+
t.Fatalf("Cannot get DB version string (SkipNotTiDBVersionMin): %v", err)
242+
return
243+
}
244+
if isTiDB {
245+
tidbSemVar, err := version.NewVersion(tidbVersion)
246+
if err != nil {
247+
t.Fatalf("Cannot get DB version string for TiDB (SkipNotTiDBVersionMin): %s %v", tidbSemVar, err)
248+
return
249+
}
250+
if tidbSemVar.LessThan(versionMin) {
251+
t.Skip("Skip on TiDB (SkipNotTiDBVersionMin)")
252+
}
253+
return
254+
}
255+
256+
t.Skip("Skip on MySQL")
257+
}
258+
}

mysql/resource_ti_resource_group.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ func (rg *ResourceGroup) buildSQLQuery(prefix string) string {
3434
query = append(query, fmt.Sprintf(`PRIORITY = %s`, rg.Priority))
3535

3636
if rg.QueryLimit != DefaultResourceGroup.QueryLimit {
37-
query = append(query, fmt.Sprintf(`QUERY_LIMIT=%s`, rg.QueryLimit))
38-
37+
query = append(query, fmt.Sprintf(`QUERY_LIMIT=(%s)`, rg.QueryLimit))
3938
}
4039

4140
query = append(query, fmt.Sprintf(`BURSTABLE = %t`, rg.Burstable))
@@ -51,9 +50,11 @@ var DefaultResourceGroup = ResourceGroup{
5150
Name: "tfDefault",
5251
Priority: "medium",
5352
Burstable: false,
54-
QueryLimit: "()",
53+
QueryLimit: "",
5554
}
5655

56+
var ResourceGroupTiDBMinVersion = "7.5.0"
57+
5758
func resourceTiResourceGroup() *schema.Resource {
5859
return &schema.Resource{
5960
CreateContext: CreateResourceGroup,
@@ -208,10 +209,10 @@ func getResourceGroupFromDB(db *sql.DB, name string) (*ResourceGroup, error) {
208209
/*
209210
Coerce types on SQL side into good types for golang
210211
Burstable is a varchar(3) so we coerce to BOOLEAN
211-
QUERY_LIMIT is nullable in DB, but we coerce to standard "empty" string type of "()"
212+
QUERY_LIMIT is nullable in DB, but we coerce to standard "empty" string type of ""
212213
Lowercase priority for less configuration variability
213214
*/
214-
query := `SELECT NAME, RU_PER_SEC, LOWER(PRIORITY), BURSTABLE = 'YES' as BURSTABLE, IFNULL(QUERY_LIMIT,"()") FROM information_schema.resource_groups WHERE NAME = ?`
215+
query := `SELECT NAME, RU_PER_SEC, LOWER(PRIORITY), BURSTABLE = 'YES' as BURSTABLE, IFNULL(QUERY_LIMIT,"") FROM information_schema.resource_groups WHERE NAME = ?`
215216

216217
ctx := context.Background()
217218
tflog.SetField(ctx, "query", query)

0 commit comments

Comments
 (0)