Skip to content

Destroying terraform environment can fail to delete database userΒ #13

@clarafu

Description

@clarafu

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions