When I run the terraform destroy job in the environment pipeline, it fails with Error, failed to deleteuser atc in instance <instance-name>. I think this is caused by the fact that terraform tries to delete the user before the database, which it is not allowed to do and results in this error. hashicorp/terraform-provider-google#3820 (comment)
If I run the terraform destroy job a few more times, it seems like randomly it will try to delete the database first (which I think is able to delete it successfully) but then the user is still left in the terraform state and it then errors with Error, failed to deleteuser atc in instance <instance-name>: googleapi: Error 400: Invalid request: Invalid request since instance is not running., invalid.
The way I manually fixed this as a workaround to the issue is to run terraform state list and find the terraform google sql user (it should look like module.baseline_database.google_sql_user.user) and then run 1terraform state rm module.baseline_database.google_sql_user.user`.
But I think maybe the long term fix is to try what is suggested in the issue I linked, where we can try adding a depends_on to the google_sql_database so that it depends on the google_sql_user.
When I run the terraform destroy job in the environment pipeline, it fails with
Error, failed to deleteuser atc in instance <instance-name>. I think this is caused by the fact that terraform tries to delete the user before the database, which it is not allowed to do and results in this error. hashicorp/terraform-provider-google#3820 (comment)If I run the terraform destroy job a few more times, it seems like randomly it will try to delete the database first (which I think is able to delete it successfully) but then the user is still left in the terraform state and it then errors with
Error, failed to deleteuser atc in instance <instance-name>: googleapi: Error 400: Invalid request: Invalid request since instance is not running., invalid.The way I manually fixed this as a workaround to the issue is to run
terraform state listand find the terraform google sql user (it should look likemodule.baseline_database.google_sql_user.user) and then run 1terraform state rm module.baseline_database.google_sql_user.user`.But I think maybe the long term fix is to try what is suggested in the issue I linked, where we can try adding a
depends_onto thegoogle_sql_databaseso that it depends on thegoogle_sql_user.