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

HTTP 409 while provisioning Google Cloud SQL instance #4557

Closed
gtaylor opened this issue Jan 7, 2016 · 10 comments
Closed

HTTP 409 while provisioning Google Cloud SQL instance #4557

gtaylor opened this issue Jan 7, 2016 · 10 comments

Comments

@gtaylor
Copy link

gtaylor commented Jan 7, 2016

I'm attempting to provision the following CLoud SQL instance (derived from the example in the docs):

resource "google_sql_database_instance" "master" {
  name = "node-control"
  region = "us-central"

  settings {
    tier = "D0"
  }
}

Here's what I'm getting:

google_sql_database_instance.master: Creating...
  database_version:   "" => "MYSQL_5_5"
  name:               "" => "nodecontrol"
  region:             "" => "us-central"
  self_link:          "" => "<computed>"
  settings.#:         "" => "1"
  settings.0.tier:    "" => "D0"
  settings.0.version: "" => "<computed>"
Error applying plan:

1 error(s) occurred:

* google_sql_database_instance.master: Error, failed to create instance nodecontrol: googleapi: Error 409: The instance or operation is not in an appropriate state to handle the request., invalidState

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.

The Google Cloud project is empty, and I have no other resources defined. Currently running Terraform v0.6.8.

$ gcloud sql instances list
NAME  REGION  TIER  ADDRESS  STATUS
Listed 0 items.
@gtaylor
Copy link
Author

gtaylor commented Jan 7, 2016

OK, this ended up being a sneaky one. I guess they use some kind of background task to finalize Cloud SQL instance deletions. Here's what I got when I tried to use the instance name in the web UI:

image

I don't have anything to suggest as far as a workaround, but it's clear that we can't just delete then immediately re-create the instance with the same name.

@phinze
Copy link
Contributor

phinze commented Jan 8, 2016

@lwander any ideas here? If we know how long that "recently" check is we could workaround by dropping a sleep in the delete step - unless it's several minutes or something.

@lwander
Copy link
Contributor

lwander commented Jan 8, 2016

The docs say that a name can be unavailable for up to two months. This is unfortunate, so I guess the second best thing to do is write a nice error message explaining that you need a new instance name?

@phinze
Copy link
Contributor

phinze commented Jan 8, 2016

Haha I suppose we can't exactly time.Sleep(2 * duration.Month). 😛

Yeah a nicer error message for one would be good.

We can also make the name field optional and populate it with resource.UniqueId() to avoid collisions. We do this for a bunch of resources that need unique names and it works pretty nicely.

@lwander
Copy link
Contributor

lwander commented Jan 8, 2016

Ha, that might be too discouraging 😴

Optional field name sounds perfect, I'll submit a PR.

@gtirloni
Copy link

gtirloni commented Apr 1, 2019

I just found this old issue because I'm getting the following error on Terraform 0.11.13:

* google_sql_database_instance.default: Error, failed to create instance master-instance: googleapi: Error 409: The instance or operation is not in an appropriate state to handle the request., invalidState

It seems the nicer message is not getting displayed. Yes, I tried to create an instance the had just been deleted.

@nickmarx12345678
Copy link

nickmarx12345678 commented Apr 4, 2019

I'm encountering same as @gtirloni, on matching Terraform version.

@nickmarx12345678
Copy link

Hilariously, I can't even terraform destroy now.

For those who encounter similar. I was trying to recreate a db user. Running into rejections doing this, I thought I would just delete my database instance instead (developing). This failed as well through terraform so I decided to delete it through console. Now I'm unable to plan, apply, or destroy in this module.

  • google_sql_user.X: google_sql_user.X: Error reading SQL User "X" in instance "terraform-20190403210345996400000001": googleapi: Error 409: The instance or operation is not in an appropriate state to handle the request., invalidState

@rsalmond
Copy link

rsalmond commented Apr 9, 2019

@nickmarx12345678 I just arrived here having hit the same issue. terraform state rm <resource> should sort you out.

@ghost
Copy link

ghost commented Aug 13, 2019

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.

@hashicorp hashicorp locked and limited conversation to collaborators Aug 13, 2019
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

7 participants