Skip to content
This repository has been archived by the owner on Oct 11, 2022. It is now read-only.

Commit

Permalink
Merge pull request #36 from Xyaren/main
Browse files Browse the repository at this point in the history
Allow Import of user/grant containing "@" in the username.
  • Loading branch information
winebarrel authored Aug 23, 2021
2 parents 493f173 + b24c220 commit 4af5e73
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions mysql/resource_grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,14 +425,14 @@ func DeleteGrant(d *schema.ResourceData, meta interface{}) error {
}

func ImportGrant(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
userHost := strings.SplitN(d.Id(), "@", 2)
lastSeparatorIndex := strings.LastIndex(d.Id(), "@")

if len(userHost) != 2 {
if lastSeparatorIndex <= 0 {
return nil, fmt.Errorf("wrong ID format %s (expected USER@HOST)", d.Id())
}

user := userHost[0]
host := userHost[1]
user := d.Id()[0:lastSeparatorIndex]
host := d.Id()[lastSeparatorIndex+1:]

db, err := meta.(*MySQLConfiguration).GetDbConn()
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions mysql/resource_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,14 @@ func DeleteUser(d *schema.ResourceData, meta interface{}) error {
}

func ImportUser(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
userHost := strings.SplitN(d.Id(), "@", 2)
lastSeparatorIndex := strings.LastIndex(d.Id(), "@")

if len(userHost) != 2 {
if lastSeparatorIndex <= 0 {
return nil, fmt.Errorf("wrong ID format %s (expected USER@HOST)", d.Id())
}

user := userHost[0]
host := userHost[1]
user := d.Id()[0:lastSeparatorIndex]
host := d.Id()[lastSeparatorIndex+1:]

db, err := meta.(*MySQLConfiguration).GetDbConn()
if err != nil {
Expand Down

0 comments on commit 4af5e73

Please sign in to comment.