Skip to content
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

Mysql Sql User cannot be updated or deleted if host is blank #3784

Closed
chrisst opened this issue Jun 4, 2019 · 8 comments
Closed

Mysql Sql User cannot be updated or deleted if host is blank #3784

chrisst opened this issue Jun 4, 2019 · 8 comments

Comments

@chrisst
Copy link
Contributor

chrisst commented Jun 4, 2019

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment
  • If an issue is assigned to the "modular-magician" user, it is either in the process of being autogenerated, or is planned to be autogenerated soon. If an issue is assigned to a user, that user is claiming responsibility for the issue. If an issue is assigned to "hashibot", a community member has claimed the issue already.

Terraform Version

all

Affected Resource(s)

  • google_sql_user

Terraform Configuration Files

func TestAccSqlUser_mysqlNoHost(t *testing.T) {
	t.Parallel()

	instance := acctest.RandomWithPrefix("i")
	resource.Test(t, resource.TestCase{
		PreCheck:     func() { testAccPreCheck(t) },
		Providers:    testAccProviders,
		CheckDestroy: testAccSqlUserDestroy,
		Steps: []resource.TestStep{
			{
				Config: testGoogleSqlUser_mysqlNoHost(instance, "password"),
				Check: resource.ComposeTestCheckFunc(
					testAccCheckGoogleSqlUserExists("google_sql_user.user2"),
				),
			},
			{
				Config: testGoogleSqlUser_mysqlNoHost(instance, "password2"),
				Check: resource.ComposeTestCheckFunc(
					testAccCheckGoogleSqlUserExists("google_sql_user.user2"),
				),
			},
			{
				ResourceName:            "google_sql_user.user2",
				ImportStateId:           fmt.Sprintf("%s/%s/localhost/admin", getTestProjectFromEnv(), instance),
				ImportState:             true,
				ImportStateVerify:       true,
				ImportStateVerifyIgnore: []string{"password"},
			},
		},
	})
}

func testGoogleSqlUser_mysqlNoHost(instance, password string) string {
	return fmt.Sprintf(`
	resource "google_sql_database_instance" "instance" {
		name = "%s"
		region = "us-central"
		settings {
			tier = "D0"
		}
	}

	resource "google_sql_user" "user2" {
		name = "admin"
		instance = "${google_sql_database_instance.instance.name}"
		password = "%s"
	}
	`, instance, password)
}

Problem

The host attribute of SqlUser for MySql is Optional and the empty string is the default if not passed to the rest API. However once a User is created with an empty host it can no longer be updated or deleted. The request will fail with "Error 400: Invalid request: Host required for MySQL instances."

This is because the upstream API requires host in the url as a param, but doesn't recognize ?host= as a valid option.

References

b/134505616

@justindujardin
Copy link

@chrisst Your problem statement says that update and delete will fail, but your referenced code change only sets the default host for Users.Update. Is this an oversight in the PR? I see this 400 error while deleting a SQL user:

...
Error: Error applying plan:
1 error(s) occurred:
* google_sql_user.project-db-user (destroy): 1 error(s) occurred:
* google_sql_user.project-db-user: Error, failed to deleteuser cool-user in instance terraform-1337:
  googleapi: Error 400: Missing parameter: host., required

@chrisst chrisst changed the title Sql User cannot be updated or deleted if host isn't present Mysql Sql User cannot be updated or deleted if host is blank Jun 27, 2019
@chrisst
Copy link
Contributor Author

chrisst commented Jun 27, 2019

The referenced PR wasn't meant to fix this issue. This issue is a problem with the API since there it allows creating a user that can not be modified. We can't fix this issue until the API addresses this.

In contrast the referenced PR was fixing the Update call to pass the host as a param to make normal updates succeed with a valid host present.

If you have a config where you have a valid host and you can't delete the sql use can you share your config?

@justindujardin
Copy link

I see, thanks for the info.

If you have a config where you have a valid host and you can't delete the sql use can you share your config?

I'll look deeper into my issue and follow up here with a reproduction case if I can't resolve it.

@morgante
Copy link

Would it be possible to work around this in the provider by providing an option to force delete?

Specifically, when trying to delete an entire database it doesn't actually matter if the individual users are deleted but Terraform will error out on that step.

We're encountering this issue here: forseti-security/terraform-google-forseti#148

@chrisst
Copy link
Contributor Author

chrisst commented Oct 24, 2019

It's my understanding from the API team that the user shouldn't be able to be created with no host. Once the user has been created in this state it appears to be impossible to modify/delete via the rest API. Ignoring the delete errors would result in an orphaned resource. I'll ping the API team and see if there's a plan for resolution because anything we do in the provider will be some degree of broken.

@chrisst
Copy link
Contributor Author

chrisst commented Nov 13, 2019

Assigning this to 4.0 so that if there still isn't any update from the API team we can make a breaking change to avoid this for future users. It will likely require manual resolution of problematic resources if we address this in the provider.

modular-magician added a commit to modular-magician/terraform-provider-google that referenced this issue Jul 27, 2020
modular-magician added a commit that referenced this issue Jul 27, 2020
@c2thorn
Copy link
Collaborator

c2thorn commented Sep 7, 2021

This was resolved and verified in b/134758506

@c2thorn c2thorn closed this as completed Sep 7, 2021
@rileykarson rileykarson removed this from the 4.0.0 milestone Sep 27, 2021
@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants