From 7c2c81583dadad28848f0c843a92e9a2337c2f38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20J=C3=BAno=C5=A1?= Date: Thu, 25 Feb 2021 21:56:45 +0100 Subject: [PATCH] Update password reading to work only in old MySQL New is doing its own hashing and doesn't support PASSWORD() function. Maybe we should introduce it later. --- mysql/resource_user_password.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/mysql/resource_user_password.go b/mysql/resource_user_password.go index 5aff52f6..7ab00358 100644 --- a/mysql/resource_user_password.go +++ b/mysql/resource_user_password.go @@ -5,6 +5,7 @@ import ( "log" "github.com/gofrs/uuid" + "github.com/hashicorp/go-version" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -66,7 +67,26 @@ func SetUserPassword(d *schema.ResourceData, meta interface{}) error { return nil } +func canReadPassword(meta interface{}) (bool, error) { + db := meta.(*MySQLConfiguration).Db + serverVersion, err := serverVersion(db) + if err != nil { + return false, fmt.Errorf("Could not determine server version: %s", err) + } + + ver, _ := version.NewVersion("8.0.0") + return serverVersion.LessThan(ver), nil +} + func ReadUserPassword(d *schema.ResourceData, meta interface{}) error { + canRead, err := canReadPassword(meta) + if err != nil { + return err + } + if !canRead { + return nil + } + db := meta.(*MySQLConfiguration).Db results, err := db.Query(`SELECT IF(PASSWORD(?) = authentication_string,'OK','FAIL') result, plugin FROM mysql.user WHERE user = ? AND host = ?`,