@@ -5,8 +5,7 @@ PKG_NAME=mysql
55# Last version before hashicorp relicensing to BSL
66TERRAFORM_VERSION =1.5.6
77TERRAFORM_OS =$(shell uname -s | tr A-Z a-z)
8- TEST_USER =root
9- TEST_PASSWORD =my-secret-pw
8+ # Testcontainers-based testing - no need for manual Docker management
109DATESTAMP =$(shell date "+% Y% m% d")
1110SHA_SHORT =$(shell git describe --match=FORCE_NEVER_MATCH --always --abbrev=40 --dirty --abbrev)
1211MOST_RECENT_UPSTREAM_TAG =$(shell git for-each-ref refs/tags --sort=-taggerdate --format="% (refname) " | head -1 | grep -E -o "v\d+\.\d+\.\d+")
@@ -34,88 +33,87 @@ VERSION=9.9.9
3433# # on linux base os
3534TERRAFORM_PLUGINS_DIRECTORY =~/.terraform.d/plugins/${HOSTNAME}/${NAMESPACE}/${NAME}/${VERSION}/${OS_ARCH}
3635
37- default : build
38-
39- build : fmtcheck
36+ .PHONY : help
37+ help : # # Show this help message
38+ @echo ' Usage: make [target]'
39+ @echo ' '
40+ @echo ' Available targets:'
41+ @awk ' BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " %-20s %s\n", $$1, $$2}' $(MAKEFILE_LIST )
42+ @echo ' '
43+ @echo ' Examples:'
44+ @echo ' make build Build the provider'
45+ @echo ' make testversion8.0 Run tests against MySQL 8.0'
46+ @echo ' make testtidb8.5.3 Run tests against TiDB 8.5.3'
47+ @echo ' make acceptance Run all acceptance tests'
48+ @echo ' make testcontainers-matrix Run test matrix across all database versions'
49+
50+ default : help
51+
52+ build : fmtcheck # # Build the provider
4053 go install
4154
42- test : acceptance
55+ test : acceptance # # Run all acceptance tests
4356
44- # Run testcontainers tests with a matrix of MySQL versions
57+ # Run testcontainers tests with a matrix of all database versions
4558# Usage: make testcontainers-matrix TESTARGS="TestAccUser"
46- testcontainers-matrix : fmtcheck
47- @cd $(CURDIR ) && go run scripts/test-runner.go $(if $(TESTARGS ) ,$(TESTARGS ) ,WithTestcontainers)
59+ testcontainers-matrix : fmtcheck bin/terraform # # Run test matrix across all database versions
60+ @cd $(CURDIR ) && PATH= " $( CURDIR ) /bin: ${PATH} " go run scripts/test-runner.go $(if $(TESTARGS ) ,$(TESTARGS ) ,WithTestcontainers)
4861
49- # Run testcontainers tests for a specific MySQL image
62+ # Run testcontainers tests for a specific database image
5063# Usage: make testcontainers-image DOCKER_IMAGE=mysql:8.0
51- testcontainers-image : fmtcheck bin/terraform
52- DOCKER_IMAGE=$(DOCKER_IMAGE ) TF_ACC=1 GOTOOLCHAIN=auto go test -tags=testcontainers $(TEST ) -v $(TESTARGS ) -timeout=15m
64+ # make testcontainers-image TIDB_VERSION=8.5.3
65+ testcontainers-image : fmtcheck bin/terraform # # Run tests for a specific database image (set DOCKER_IMAGE or TIDB_VERSION)
66+ @PATH=" $( CURDIR) /bin:${PATH} " TF_ACC=1 GOTOOLCHAIN=auto go test -tags=testcontainers $(TEST ) -v $(TESTARGS ) -timeout=15m
5367
54- bin/terraform :
68+ bin/terraform : # # Download Terraform binary
5569 mkdir -p " $( CURDIR) /bin"
5670 curl -sfL https://releases.hashicorp.com/terraform/$(TERRAFORM_VERSION ) /terraform_$(TERRAFORM_VERSION ) _$(TERRAFORM_OS ) _$(ARCH ) .zip > $(CURDIR ) /bin/terraform.zip
5771 (cd $( CURDIR) /bin/ ; unzip terraform.zip)
5872
59- testacc : fmtcheck bin/terraform
73+ testacc : fmtcheck bin/terraform # # Run acceptance tests (requires MYSQL_ENDPOINT env vars)
6074 PATH=" $( CURDIR) /bin:${PATH} " TF_ACC=1 go test $(TEST ) -v $(TESTARGS ) -timeout=90s
6175
6276# TiDB versions: latest of each minor series (must match .github/workflows/main.yml TIDB_VERSIONS)
6377# 6.1.x → 6.1.7, 6.5.x → 6.5.12, 7.1.x → 7.1.6, 7.5.x → 7.5.7, 8.1.x → 8.1.2, 8.5.x → 8.5.3
64- acceptance : testversion5.6 testversion5.7 testversion8.0 testpercona5.7 testpercona8.0 testmariadb10.3 testmariadb10.8 testmariadb10.10 testtidb6.1.7 testtidb6.5.12 testtidb7.1.6 testtidb7.5.7 testtidb8.1.2 testtidb8.5.3
65-
66- testversion% :
67- $(MAKE ) MYSQL_VERSION=$* MYSQL_PORT=33$(shell echo "$* " | tr -d '.') testversion
68-
69- testversion :
70- -docker run --rm --name test-mysql$(MYSQL_VERSION ) -e MYSQL_ROOT_PASSWORD=" $( TEST_PASSWORD) " -d -p $(MYSQL_PORT ) :3306 mysql:$(MYSQL_VERSION )
71- @echo ' Waiting for MySQL...'
72- @while ! mysql -h 127.0.0.1 -P $(MYSQL_PORT ) -u " $( TEST_USER) " -p" $( TEST_PASSWORD) " -e ' SELECT 1' > /dev/null 2>&1 ; do printf ' .' ; sleep 1; done ; echo ; echo " Connected!"
73- -mysql -h 127.0.0.1 -P $(MYSQL_PORT ) -u " $( TEST_USER) " -p" $( TEST_PASSWORD) " -e " INSTALL PLUGIN mysql_no_login SONAME 'mysql_no_login.so';"
74- MYSQL_USERNAME=" $( TEST_USER) " MYSQL_PASSWORD=" $( TEST_PASSWORD) " MYSQL_ENDPOINT=127.0.0.1:$(MYSQL_PORT ) $(MAKE ) testacc
75- -docker rm -f test-mysql$(MYSQL_VERSION )
76-
77- testpercona% :
78- $(MAKE ) MYSQL_VERSION=$* MYSQL_PORT=34$(shell echo "$* " | tr -d '.') testpercona
79-
80- testpercona :
81- -docker run --rm --name test-percona$(MYSQL_VERSION ) -e MYSQL_ROOT_PASSWORD=" $( TEST_PASSWORD) " -d -p $(MYSQL_PORT ) :3306 percona:$(MYSQL_VERSION )
82- @echo ' Waiting for Percona...'
83- @while ! mysql -h 127.0.0.1 -P $(MYSQL_PORT ) -u " $( TEST_USER) " -p" $( TEST_PASSWORD) " -e ' SELECT 1' > /dev/null 2>&1 ; do printf ' .' ; sleep 1; done ; echo ; echo " Connected!"
84- -mysql -h 127.0.0.1 -P $(MYSQL_PORT ) -u " $( TEST_USER) " -p" $( TEST_PASSWORD) " -e " INSTALL PLUGIN mysql_no_login SONAME 'mysql_no_login.so';"
85- MYSQL_USERNAME=" $( TEST_USER) " MYSQL_PASSWORD=" $( TEST_PASSWORD) " MYSQL_ENDPOINT=127.0.0.1:$(MYSQL_PORT ) $(MAKE ) testacc
86- -docker rm -f test-percona$(MYSQL_VERSION )
87-
88- testrdsdb% :
78+ acceptance : testversion5.6 testversion5.7 testversion8.0 testpercona5.7 testpercona8.0 testmariadb10.3 testmariadb10.8 testmariadb10.10 testtidb6.1.7 testtidb6.5.12 testtidb7.1.6 testtidb7.5.7 testtidb8.1.2 testtidb8.5.3 # # Run all acceptance tests across all database versions
79+
80+ # MySQL test targets - use testcontainers
81+ testversion% : # # Run tests against MySQL version (e.g., testversion8.0)
82+ @DOCKER_IMAGE=mysql:$* PATH=" $( CURDIR) /bin:${PATH} " TF_ACC=1 GOTOOLCHAIN=auto go test -tags=testcontainers ./mysql/... -v $(if $(TESTARGS ) ,-run "$(TESTARGS ) .* WithTestcontainers",-run WithTestcontainers) -timeout=30m
83+
84+ testversion : # # Run tests against MySQL version (set MYSQL_VERSION)
85+ @DOCKER_IMAGE=mysql:$(MYSQL_VERSION ) PATH=" $( CURDIR) /bin:${PATH} " TF_ACC=1 GOTOOLCHAIN=auto go test -tags=testcontainers ./mysql/... -v $(if $(TESTARGS ) ,-run "$(TESTARGS ) .* WithTestcontainers",-run WithTestcontainers) -timeout=30m
86+
87+ # Percona test targets - use testcontainers
88+ testpercona% : # # Run tests against Percona version (e.g., testpercona8.0)
89+ @DOCKER_IMAGE=percona:$* PATH=" $( CURDIR) /bin:${PATH} " TF_ACC=1 GOTOOLCHAIN=auto go test -tags=testcontainers ./mysql/... -v $(if $(TESTARGS ) ,-run "$(TESTARGS ) .* WithTestcontainers",-run WithTestcontainers) -timeout=30m
90+
91+ testpercona : # # Run tests against Percona version (set MYSQL_VERSION)
92+ @DOCKER_IMAGE=percona:$(MYSQL_VERSION ) PATH=" $( CURDIR) /bin:${PATH} " TF_ACC=1 GOTOOLCHAIN=auto go test -tags=testcontainers ./mysql/... -v $(if $(TESTARGS ) ,-run "$(TESTARGS ) .* WithTestcontainers",-run WithTestcontainers) -timeout=30m
93+
94+ testrdsdb% : # # Run tests against RDS MySQL version (requires MYSQL_ENDPOINT env vars)
8995 $(MAKE ) MYSQL_VERSION=$* MYSQL_USERNAME=${MYSQL_USERNAME} MYSQL_HOST=$(shell echo ${MYSQL_ENDPOINT} | cut -d: -f1) MYSQL_PASSWORD=${MYSQL_PASSWORD} MYSQL_PORT=$(shell echo ${MYSQL_ENDPOINT} | cut -d: -f2) testrdsdb
9096
91- testrdsdb :
97+ testrdsdb : # # Run tests against Amazon RDS (requires MYSQL_ENDPOINT env vars)
9298 @echo ' Waiting for AMAZON RDS...'
9399 @while ! mysql -h " $( MYSQL_HOST) " -P " $( MYSQL_PORT) " -u " $( MYSQL_USERNAME) " -p" $( MYSQL_PASSWORD) " -e ' SELECT 1' > /dev/null 2>&1 ; do printf ' .' ; sleep 1; done ; echo ; echo " Connected!"
94100 $(MAKE ) testacc
95101
96- testtidb% :
97- $(MAKE ) MYSQL_VERSION=$* MYSQL_PORT=$(shell echo "$* " | awk -F. '{port=34000+($$2* 100) +$$ 3; if(port> 65535) port=34000+ ($$ 2* 10)+$$ 3; printf " %d" , port}' ) testtidb
98-
99- # WARNING: this does not work as a bare task run, it only instantiates correctly inside the versioned TiDB task run
100- # otherwise MYSQL_PORT and version are unset.
101- testtidb :
102- @MYSQL_VERSION=$(MYSQL_VERSION ) MYSQL_PORT=$(MYSQL_PORT ) $(CURDIR ) /scripts/tidb-test-cluster.sh --init --port $(MYSQL_PORT ) --version $(MYSQL_VERSION ) || exit 1
103- MYSQL_USERNAME=" $( TEST_USER) " MYSQL_PASSWORD=" " MYSQL_ENDPOINT=127.0.0.1:$(MYSQL_PORT ) $(MAKE ) testacc; \
104- TEST_RESULT=$$? ; \
105- MYSQL_VERSION=$(MYSQL_VERSION ) MYSQL_PORT=$(MYSQL_PORT ) $(CURDIR ) /scripts/tidb-test-cluster.sh --destroy || true ; \
106- exit $$ TEST_RESULT
107-
108- testmariadb% :
109- $(MAKE ) MYSQL_VERSION=$* MYSQL_PORT=6$(shell echo "$* " | tr -d '.') testmariadb
110-
111- testmariadb :
112- -docker run --rm --name test-mariadb$(MYSQL_VERSION ) -e MYSQL_ROOT_PASSWORD=" $( TEST_PASSWORD) " -d -p $(MYSQL_PORT ) :3306 mariadb:$(MYSQL_VERSION )
113- @echo ' Waiting for MySQL...'
114- @while ! mysql -h 127.0.0.1 -P $(MYSQL_PORT ) -u " $( TEST_USER) " -p" $( TEST_PASSWORD) " -e ' SELECT 1' > /dev/null 2>&1 ; do printf ' .' ; sleep 1; done ; echo ; echo " Connected!"
115- MYSQL_USERNAME=" $( TEST_USER) " MYSQL_PASSWORD=" $( TEST_PASSWORD) " MYSQL_ENDPOINT=127.0.0.1:$(MYSQL_PORT ) $(MAKE ) testacc
116- -docker rm -f test-mariadb$(MYSQL_VERSION )
117-
118- vet :
102+ # TiDB test targets - use testcontainers
103+ testtidb% : # # Run tests against TiDB version (e.g., testtidb8.5.3)
104+ @TIDB_VERSION=$* PATH=" $( CURDIR) /bin:${PATH} " TF_ACC=1 GOTOOLCHAIN=auto go test -tags=testcontainers ./mysql/... -v $(if $(TESTARGS ) ,-run "$(TESTARGS ) .* WithTestcontainers",-run WithTestcontainers) -timeout=30m
105+
106+ testtidb : # # Run tests against TiDB version (set MYSQL_VERSION)
107+ @TIDB_VERSION=$(MYSQL_VERSION ) PATH=" $( CURDIR) /bin:${PATH} " TF_ACC=1 GOTOOLCHAIN=auto go test -tags=testcontainers ./mysql/... -v $(if $(TESTARGS ) ,-run "$(TESTARGS ) .* WithTestcontainers",-run WithTestcontainers) -timeout=30m
108+
109+ # MariaDB test targets - use testcontainers
110+ testmariadb% : # # Run tests against MariaDB version (e.g., testmariadb10.10)
111+ @DOCKER_IMAGE=mariadb:$* PATH=" $( CURDIR) /bin:${PATH} " TF_ACC=1 GOTOOLCHAIN=auto go test -tags=testcontainers ./mysql/... -v $(if $(TESTARGS ) ,-run "$(TESTARGS ) .* WithTestcontainers",-run WithTestcontainers) -timeout=30m
112+
113+ testmariadb : # # Run tests against MariaDB version (set MYSQL_VERSION)
114+ @DOCKER_IMAGE=mariadb:$(MYSQL_VERSION ) PATH=" $( CURDIR) /bin:${PATH} " TF_ACC=1 GOTOOLCHAIN=auto go test -tags=testcontainers ./mysql/... -v $(if $(TESTARGS ) ,-run "$(TESTARGS ) .* WithTestcontainers",-run WithTestcontainers) -timeout=30m
115+
116+ vet : # # Run go vet
119117 @echo " go vet ."
120118 @go vet $$(go list ./... | grep -v vendor/ ) ; if [ $$ ? -eq 1 ]; then \
121119 echo " " ; \
@@ -124,31 +122,31 @@ vet:
124122 exit 1; \
125123 fi
126124
127- fmt :
125+ fmt : # # Format Go code
128126 gofmt -w $(GOFMT_FILES )
129127
130- deps :
128+ deps : # # Update dependencies and vendor
131129 go mod tidy
132130 go mod vendor
133131
134- fmtcheck :
132+ fmtcheck : # # Check Go code formatting
135133 @sh -c " '$( CURDIR) /scripts/gofmtcheck.sh'"
136134
137- errcheck :
135+ errcheck : # # Run errcheck
138136 @sh -c " '$( CURDIR) /scripts/errcheck.sh'"
139137
140- vendor-status :
138+ vendor-status : # # Show vendor status
141139 @govendor status
142140
143- test-compile :
141+ test-compile : # # Compile tests without running them
144142 @if [ " $( TEST) " = " ./..." ]; then \
145143 echo " ERROR: Set TEST to a specific package. For example," ; \
146144 echo " make test-compile TEST=./$( PKG_NAME) " ; \
147145 exit 1; \
148146 fi
149147 go test -c $(TEST ) $(TESTARGS )
150148
151- website :
149+ website : # # Generate website documentation
152150ifeq (,$(wildcard $(GOPATH ) /src/$(WEBSITE_REPO ) ) )
153151 echo "$(WEBSITE_REPO) not found in your GOPATH (necessary for layouts and assets), get-ting..."
154152 git clone https://$(WEBSITE_REPO) $(GOPATH)/src/$(WEBSITE_REPO)
@@ -157,27 +155,27 @@ endif
157155
158156 @$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME)
159157
160- install :
158+ install : # # Install provider to Terraform plugins directory
161159 mkdir -p ${TERRAFORM_PLUGINS_DIRECTORY}
162160 go build -o ${TERRAFORM_PLUGINS_DIRECTORY} /terraform-provider-${NAME}
163161 cd examples && rm -rf .terraform
164162 cd examples && make init
165163
166- re-install :
164+ re-install : # # Reinstall provider (removes lock file first)
167165 rm -f examples/.terraform.lock.hcl
168166 rm -f ${TERRAFORM_PLUGINS_DIRECTORY} /terraform-provider-${NAME}
169167 go build -o ${TERRAFORM_PLUGINS_DIRECTORY} /terraform-provider-${NAME}
170168 cd examples && rm -rf .terraform
171169 cd examples && terraform init
172170
173- format-tag :
171+ format-tag : # # Format tag string
174172 @echo $(MOST_RECENT_UPSTREAM_TAG ) -$(DATESTAMP ) -$(SHA_SHORT )
175173
176- tag :
174+ tag : # # Create git tag from VERSION file
177175 @echo git tag -a $(shell cat VERSION) -m $(shell cat VERSION)
178176 @git tag -a v$(shell cat VERSION) -m v$(shell cat VERSION)
179177
180- release :
178+ release : # # Create a release (tag, build, and optionally push to GitHub)
181179 @VERSION=$$(cat VERSION ) ; \
182180 TAG=" v$$ VERSION" ; \
183181 echo " Checking if tag $$ TAG already exists..." ; \
@@ -283,4 +281,4 @@ release:
283281 echo " " ; \
284282 echo " Release complete! Tag $$ TAG has been pushed to GitHub."
285283
286- .PHONY : build test testacc vet fmt fmtcheck errcheck vendor-status test-compile website website-test tag format-tag release
284+ .PHONY : help build test testacc vet fmt fmtcheck errcheck vendor-status test-compile website website-test tag format-tag release
0 commit comments