mirror of
https://github.com/opentffoundation/opentf.git
synced 2026-05-23 22:00:54 -04:00
MySQL Provider does not recreate user if user got deleted manually in MySQL (#12791)
Issue No. #12767
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user