From eeb60e3aa47031557bc161263a245c70ad86b176 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20G=C3=BCnther?= Date: Mon, 23 Aug 2021 11:07:47 +0200 Subject: [PATCH 1/2] Allow usernames containing an "@" i.e emails. --- mysql/resource_grant.go | 8 ++++---- mysql/resource_user.go | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/mysql/resource_grant.go b/mysql/resource_grant.go index 26e12d029..4cf9e2312 100644 --- a/mysql/resource_grant.go +++ b/mysql/resource_grant.go @@ -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:] db, err := meta.(*MySQLConfiguration).GetDbConn() if err != nil { diff --git a/mysql/resource_user.go b/mysql/resource_user.go index df1dac416..959aa4e79 100644 --- a/mysql/resource_user.go +++ b/mysql/resource_user.go @@ -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:] db, err := meta.(*MySQLConfiguration).GetDbConn() if err != nil { From b24c220cfc194acb4a21d2de06e39475a9cc91a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20G=C3=BCnther?= Date: Mon, 23 Aug 2021 11:27:42 +0200 Subject: [PATCH 2/2] fix index offset --- mysql/resource_grant.go | 2 +- mysql/resource_user.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mysql/resource_grant.go b/mysql/resource_grant.go index 4cf9e2312..24cf0c74f 100644 --- a/mysql/resource_grant.go +++ b/mysql/resource_grant.go @@ -432,7 +432,7 @@ func ImportGrant(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceDa } user := d.Id()[0:lastSeparatorIndex] - host := d.Id()[lastSeparatorIndex:] + host := d.Id()[lastSeparatorIndex+1:] db, err := meta.(*MySQLConfiguration).GetDbConn() if err != nil { diff --git a/mysql/resource_user.go b/mysql/resource_user.go index 959aa4e79..fb3e494ae 100644 --- a/mysql/resource_user.go +++ b/mysql/resource_user.go @@ -259,7 +259,7 @@ func ImportUser(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceDat } user := d.Id()[0:lastSeparatorIndex] - host := d.Id()[lastSeparatorIndex:] + host := d.Id()[lastSeparatorIndex+1:] db, err := meta.(*MySQLConfiguration).GetDbConn() if err != nil {