MySQL Provider does not recreate user if user got deleted manually in MySQL (#12791)

Issue No. #12767
This commit is contained in:
Hao 2017-03-18 06:15:01 -07:00 committed by Paul Stack
parent 4979ae099e
commit 06a9bfebfc
2 changed files with 27 additions and 2 deletions

View File

@ -88,7 +88,18 @@ func CreateGrant(d *schema.ResourceData, meta interface{}) error {
}
func ReadGrant(d *schema.ResourceData, meta interface{}) error {
// At this time, all attributes are supplied by the user
conn := meta.(*providerConfiguration).Conn
stmtSQL := fmt.Sprintf("SHOW GRANTS FOR '%s'@'%s'",
d.Get("user").(string),
d.Get("host").(string))
log.Println("Executing statement:", stmtSQL)
_, _, err := conn.Query(stmtSQL)
if err != nil {
d.SetId("")
}
return nil
}

View File

@ -95,7 +95,21 @@ func UpdateUser(d *schema.ResourceData, meta interface{}) error {
}
func ReadUser(d *schema.ResourceData, meta interface{}) error {
// At this time, all attributes are supplied by the user
conn := meta.(*providerConfiguration).Conn
stmtSQL := fmt.Sprintf("SELECT USER FROM mysql.user WHERE USER='%s'",
d.Get("user").(string))
log.Println("Executing statement:", stmtSQL)
rows, _, err := conn.Query(stmtSQL)
log.Println("Returned rows:", len(rows))
if err != nil {
return err
}
if len(rows) == 0 {
d.SetId("")
}
return nil
}