-
Notifications
You must be signed in to change notification settings - Fork 69
Description
Ever since updating our CloudSQL mysql instances to 8, we struggle to remove grants from our users.
╷
│ Error: error revoking REVOKE ALTER, CREATE, DELETE, DROP, INDEX, INSERT, PROCESS, REFERENCES, SELECT, SHOW VIEW, SHOW_ROUTINE, UPDATE ON . FROM 'firstname.lastname'@'%': Error 3879 (HY000): Access denied for AuthId root@% to database 'mysql'.
│
│
╵
All our sql users are CLOUD_IAM_USER objects in GCP, embedded into the GCP IAM workflow. Before v8, it was simple to remove users, now, the above error occurs, and users need to be manually removed. The same happens when we try to change the grants of a user.
resource "google_sql_user" "api-dev-users" {
for_each = toset(concat(var.cloudsql_read_users, var.cloudsql_write_users))
name = each.value
instance = google_sql_database_instance.api-dev.name
type = "CLOUD_IAM_USER"
}
resource "mysql_grant" "developer-read-users" {
for_each = toset(var.cloudsql_read_users)
user = split("@", each.value)[0]
host = "%"
database = "*"
privileges = ["SELECT", "SHOW VIEW", "PROCESS", "SHOW_ROUTINE"]
provider = mysql.api-dev
depends_on = [
google_sql_user.api-dev-users
]
}
The only fix seems to be to manually destroy the cloud_iam_user element and then apply the mysql_grant resource again. I tried messing with the depends_on in the mysql_grant resource, but to no effect. The only workaround i could find is to run a time resource inbetween that forces the google_sql_user element to be messed with first and then let the grant depend on the time element, but that only helps for destruction of users, not for altering of grants.