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

Commit 4af5e73

Browse files
authored
Merge pull request #36 from Xyaren/main
Allow Import of user/grant containing "@" in the username.
2 parents 493f173 + b24c220 commit 4af5e73

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

mysql/resource_grant.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -425,14 +425,14 @@ func DeleteGrant(d *schema.ResourceData, meta interface{}) error {
425425
}
426426

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

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

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

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

mysql/resource_user.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -252,14 +252,14 @@ func DeleteUser(d *schema.ResourceData, meta interface{}) error {
252252
}
253253

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

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

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

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

0 commit comments

Comments
 (0)