Skip to content

Commit

Permalink
resource_grant: Handle revoke of grants properly
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-walsh committed Mar 4, 2019
1 parent d5b9627 commit 27659f2
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions mysql/resource_grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ func DeleteGrant(d *schema.ResourceData, meta interface{}) error {
}

roles := d.Get("roles").(*schema.Set)
privileges := d.Get("privileges").(*schema.Set)

var sql string
if !isRole && len(roles.List()) == 0 {
Expand All @@ -293,6 +294,9 @@ func DeleteGrant(d *schema.ResourceData, meta interface{}) error {
whatToRevoke := fmt.Sprintf("ALL ON %s.%s", database, table)
if len(roles.List()) > 0 {
whatToRevoke = flattenList(roles.List(), "'%s'")
} else if len(privileges.List()) > 0 {
privilegeList = flattenList(privileges.List(), "'%s'")
whatToRevoke = fmt.Sprintf("%s ON %s.%s", privilegeList, database, table)
}

sql = fmt.Sprintf("REVOKE %s FROM %s", whatToRevoke, userOrRole)
Expand Down

0 comments on commit 27659f2

Please sign in to comment.