Skip to content

Fixes TF drift for resource group name and query_limit #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Aug 9, 2024

Conversation

otherchen
Copy link
Collaborator

@otherchen otherchen commented Aug 9, 2024

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

@@ -34,8 +34,7 @@ func (rg *ResourceGroup) buildSQLQuery(prefix string) string {
query = append(query, fmt.Sprintf(`PRIORITY = %s`, rg.Priority))

if rg.QueryLimit != DefaultResourceGroup.QueryLimit {
query = append(query, fmt.Sprintf(`QUERY_LIMIT=%s`, rg.QueryLimit))

query = append(query, fmt.Sprintf(`QUERY_LIMIT=(%s)`, rg.QueryLimit))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We rely on wrapping the query_limit in parentheses here instead of assuming that it will be wrapped in parentheses by the caller.

@@ -126,7 +126,7 @@ func DeleteResourceGroupUser(ctx context.Context, d *schema.ResourceData, meta i
}

func readUserFromDB(db *sql.DB, name string) (string, string, error) {
selectUsersQuery := `SELECT USER, IFNULL(JSON_EXTRACT(User_attributes, "$.resource_group"), "") as resource_group FROM mysql.user WHERE USER = ?`
selectUsersQuery := `SELECT USER, JSON_UNQUOTE(IFNULL(JSON_EXTRACT(User_attributes, "$.resource_group"), "")) as resource_group FROM mysql.user WHERE USER = ?`
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This gets rid of the quotes that JSON_EXTRACT will generate.

@otherchen otherchen requested a review from zph August 9, 2024 09:00
GNUmakefile Outdated
@@ -43,7 +43,12 @@ bin/terraform:
(cd $(CURDIR)/bin/ ; unzip terraform.zip)

testacc: fmtcheck bin/terraform
PATH="$(CURDIR)/bin:${PATH}" TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout=90s
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be a potentially breaking change to upstream

GNUmakefile Outdated
# Commenting out the below because it tries to use an amd64 version of terraform that is incompatible with M1 Macs. Instead,
# simply rely on the version of terraform that's already on your path. If you don't have terraform installed, follow instructions
# here to install https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli
# PATH="$(CURDIR)/bin:${PATH}" TF_ACC=1 go test $(TEST) -v $(TESTARGS) -run "TestTIDBResourceGroup_basic" -timeout=90s
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this as a separate section in Makefile or can we remove it since I've patched the ARCH problem?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm removing it since it's patched for ARCH above.

LMK if you disagree

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good! Thanks for fixing this 👍

@zph zph merged commit 29408c9 into r3.0.62 Aug 9, 2024
15 checks passed
@zph zph deleted the ac-fix-terraform-diff-for-rg branch August 9, 2024 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants