-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
googleapi: Error 400: Invalid request: Failed to delete user root. #3820
Comments
If you can repro and provide debug logs it helps a lot (i.e. |
I'm trying to re-produce while running with the debug enabled. (By the way, I tried upgrading Terraform to 0.12.1 and the Google provider, and the same thing happened). I will attach with debug enabled as soon as it happens again. Thanks, |
Added logs from Terraform. I tried to remove all the resources that are not relevant in the log. Hope this will help. |
Hi @shaulishaked, could you actually give the full logs, if possible? The debug logs you gave are missing some of the HTTP requests and logs I might need to debug. If you could also give the config you are using or which users and databases are linked to which instances, that would be helpful. |
Hello @emilymye, Could I send you the full logs and the config in private? Thanks again, |
Hi, Any update on this? I sent the logs I could share, and I can send full logs privately. We are unable to destroy a setup in one run and require to run Terraform twice, which isn't reliable. We still get sporadic errors of:
Please let me know if any additional info can help. Thanks, |
We have the same problem as well.
|
Hi @shaulishaked - so sorry for the late reply! If you are still encountering this issue, you can send your logs to me at my google.com address (emilyye). |
I have encountered this issue too. I think this is the result of dependencies at the DB level, getting to be at conflict with others at the infra level that we define ourselves depending on how we layout our configuration files at Terraform. At the DB level: At the same time, DBs will conflict at deletion time if there are resources using them (eg.: existing connections). With that, there is a deletion flow that allows for these dependencies to succeed: Now, that's all great, unless one is in need of using the IPs for newly created machines to define the authorized nets / fw rules of the SQL instance. In that case, the machines need to be created first, hence deleted last, breaking the flow above. One way to circumvent that is to ignore users and DBs at destroy time by taking manually these out of the state ( Without getting into more fundamental discussions of who has the responsibility to provision infra and DB schemas, one pattern that I find appealing is to have Terraform take care of the infra, which includes the creation of an implicit root / admin / base user and use SW provisioning technologies (Spinnaker, Ansible, A solution to this would be to add the ability to set the default password for the instance on the |
We're having lots of problems with the sql instance relating to the above feedback, basically when I say destroy sql instance, i expect it to be fully torn down (I don't care if there are connections open or if a user owns a database they shouldn't etc.. ) . Destroy means destroy... and from what I see, it currently does not because of the intertwined dependencies. Basically delete sql instance should be equivalent to: gcloud sql instances delete INSTANCE_NAME --quiet Our config for our modules have the database instance -- users (depend on instance) -- databases (depend on users) FYI. I've seen random failures deleting the sql instance, some have come from a dev creating a new database with the user, and when terraform tries to teardown it fails as the user owns another database. If the database instance is being destroyed, i dont see why it would matter what the user owns :) |
Sorry this fell on the backlog, I think I still need some clarification before I actually start trying to fix this. I feel like there are multiple issues being presented by @JlUgia and since I'm not firsthand using Cloud SQL, please bear with me.
Is this related to your issue @shaulishaked? This sounds like something I'm not sure how to manage this in Terraform, both because it's not an inherent dependency link in Terraform (or is it?) and becuase I'm not the most familiar with the proper deletion order for networking Cloud SQL instances. I guess I'm really confused by what this means. Do you have example config or do you mind giving a explaination, @JlUgia? |
Hi,
I agree with @jclarksnps with the saying that "Basically delete sql instance should be equivalent to: gcloud sql instances delete INSTANCE_NAME --quiet". For now, I need to do pre-destroy commands manually instead of relying on the Terraform module, which I really want to remove. Thanks again, |
I think it's two separate issues we are discussing.
|
@JlUgia Yeah our plan is to remove database creation from TF all-together, I agree that it does not belong there at all. I did try adding dependencies, although not reverse from the instance to the users. Most of my issues have been someone using the user to create another db or having connections open, which im not sure the dependencies would fix (unless I'm missing something)? |
That's right per my understanding too. If there are other objects or connections open or created outside of the scope of Terraform, that'd conflict with the deletion of the resource. |
Any update on this? I'm running into this issue, too. It seems the best option is to manually do Seems like a hack. I tried to create a IMO a good solution to this would be to allow me (the user) to execute custom SQL on destroy for the user. Can't imagine terraform would be able to handle all use cases, but if we could drop into SQL to manually do what we need to during this sequence it would be extremely helpful. I think if I could execute SQL that looks like this:
It could work, but would need some sort of SQL hook. |
@kenmazaika that's what we did, we remove the state and we actually use gcloud to tear the instance down. |
@jclarksnps Thanks for the update! How do you hook into SQL and drop into the database? I think that Did you just make a separate script to combine the Thanks for the reply! Really appreciate it! |
@kenmazaika we actually use gcloud commands to tear the instance down, prior to that call we use terraform to remove the state for the db and its databases and users. We basically gave up on terraform doing the teardown. So in our bash that calls terraform (we use concourse pipelines), we first use gcloud to delete the instance and then we remove all the state, then we go about regular TF activities. |
FWIW, I'm taking the same approach as @kenmazaika, force removing the user from the state prior to destroying the Cloud SQL instance. |
I was able to fix a similar issue where I was receiving Error: Error, failed to deleteuser foo in instance foo-db: based on comment #3820 (comment) part 1 by explicitly enforcing dependency. |
It seems like this issue is now related to many different things. The original issue seems to be related to adding explicit dependencies and managing the root user in Terraform (given that Terraform should delete the root user upon instance creation unless on a replica instance). I'm going to close this issue and ask that @JlUgia and other folks open a new issue to discuss ways in which we can manage , which is difficult - as you may have figured out, there isn't a way Terraform can force destroy objects that Terraform doesn't know about and I'm hesistant to make terraform handle SQL commands or similar. |
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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks! |
Community Note
Terraform Version
Terraform v0.11.13
Affected Resource(s)
Terraform Configuration Files
Panic Output
Expected Behavior
Terraform should destroy the user and database successfully on the first run.
Actual Behavior
Database and user aren't deleted on the first run.
Re-run (with the same code) deletes successfully (sometimes require more than one re-run).
Steps to Reproduce
terraform destroy
The text was updated successfully, but these errors were encountered: