Search code examples
terraformterraform-provider-gcp

Terraform trying to read the SQL user after database is deleted


Our terraform state went to a broken state after we accidentally executed a out of date branch.

Two of the database got deleted, and as GCP doesn't let you use the same name for database after deletion, terraform couldn't recreate the databases, and bailed out.

The problem is, terraform thinks the databases are their, and trying to read its users:

Error when reading or editing SQL User "xxx" in instance "xxx": googleapi: Error 400: Invalid request: Invalid request since instance is not running., invalid

The instance is simply not there!

I tried to taint the database, and the user, but I still get this exact same error.

Does anyone know how to fix this? I cannot afford to destroy and recreate the environment.


Solution

  • terraform state rm can be used to remove the no longer existing databases from the state file which should fix this. Details at https://www.terraform.io/docs/commands/state/rm.html