petoju / terraform-provider-mysql

Terraform MySQL provider – unofficial fork
https://registry.terraform.io/providers/petoju/mysql
Mozilla Public License 2.0
63 stars 40 forks source link

Crash when creating grant #143

Closed vfouqueron closed 2 months ago

vfouqueron commented 2 months ago

Provider version

3.0.57

MySQL version and settings

MySQL 8.0

Terraform Configuration Files

resource "mysql_database" "app" {
  default_character_set = "utf8mb4"
  default_collation     = "utf8mb4_unicode_ci"
  name                  = "grafana-on-call"
}

resource "mysql_user" "grafana_on_call" {
  for_each                   = [<IP 1>,<IP 2>,<IP 3>,<IP 4>,<IP 5>]
  user                          = "grafana-on-call"
  host                          = each.key
  plaintext_password = random_password.mysql.result
  tls_option                 = "SSL"
}

resource "mysql_grant" "grafana_on_call" {
  for_each   = mysql_user.grafana_on_call
  user       = each.value.user
  host       = each.value.host
  database   = mysql_database.app.name
  privileges = [
    "ALTER",
    "ALTER ROUTINE",
    "CREATE",
    "CREATE VIEW",
    "CREATE ROUTINE",
    "DELETE",
    "DROP",
    "INDEX",
    "INSERT",
    "REFERENCES",
    "SELECT",
    "UPDATE"
  ]
}

Debug Output

https://gist.github.com/vfouqueron/08ec9acc48fe28422e78c2432405a744

Expected Behavior

There should be no error and apply does not try to create grant again

Actual Behavior

There is an error, the grants are actually created but not persisted in state

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform apply

Important Factoids

I was trying to check if https://github.com/petoju/terraform-provider-mysql/issues/137 was solved, but I cannot check I have tried to remove the value in state (via terraform state rm) and grants in database. Same result I've tried to import grant, it tries to create them anyway

References

petoju commented 2 months ago

@vfouqueron thanks for the logs. This should be fixed in 3.0.58.

The issue was that multiple connections have to be handled differently. I know I slowed down everyone using this provider by this change, but there could be more issues without my change.

vfouqueron commented 2 months ago

Thanks @petoju for your time, it seems to work perfectly this time :)