Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions mysql/resource_grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -1065,10 +1065,16 @@ func normalizeColumnOrder(perm string) string {

parts := strings.Split(m[2], ",")
for i := range parts {
// erase spaces and backticks, if any
parts[i] = strings.Trim(parts[i], "` ")
}
sort.Strings(parts)
precursor := strings.Trim(m[1], " ")
for i := range parts {
// put backticks around the column names
parts[i] = fmt.Sprintf("`%s`", parts[i])
}
// build comma separated string from the parts, using strictly one space after comma
partsTogether := strings.Join(parts, ", ")
return fmt.Sprintf("%s(%s)", precursor, partsTogether)
}
Expand Down
11 changes: 10 additions & 1 deletion mysql/resource_grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,15 @@ func TestAccGrantComplex(t *testing.T) {
resource.TestCheckResourceAttr("mysql_grant.test", "table", "tbl"),
),
},
{
Config: testAccGrantConfigWithPrivs(dbName, "\"SELECT (`id`,`key`,`order`,`first`,`last`)\"", false),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("mysql_grant.test", "user", fmt.Sprintf("jdoe-%s", dbName)),
resource.TestCheckResourceAttr("mysql_grant.test", "host", "example.com"),
resource.TestCheckResourceAttr("mysql_grant.test", "database", dbName),
resource.TestCheckResourceAttr("mysql_grant.test", "table", "tbl"),
),
},
{
Config: testAccGrantConfigWithPrivs(dbName, `"DROP", "SELECT (c1)", "INSERT(c3, c4)", "REFERENCES(c5)"`, false),
Check: resource.ComposeTestCheckFunc(
Expand Down Expand Up @@ -484,7 +493,7 @@ func prepareTable(dbname string, tableName string) resource.TestCheckFunc {
if err != nil {
return err
}
if _, err := db.Exec(fmt.Sprintf("CREATE TABLE `%s`.`%s`(c1 INT, c2 INT, c3 INT,c4 INT,c5 INT);", dbname, tableName)); err != nil {
if _, err := db.Exec(fmt.Sprintf("CREATE TABLE `%s`.`%s`(c1 INT, c2 INT, c3 INT, c4 INT, c5 INT, `id` INT, `key` INT, `order` INT, `type` INT, `status` INT, `created` INT, `updated` INT, `user` INT, `name` INT, `group` INT, `value` INT, `index` INT, `source` INT, `date` INT, `state` INT, `last` INT, `first` INT, `email` INT, `phone` INT, `amount` INT, `reference` INT, `reason` INT, `hash` INT, `team` INT, `case` INT, `uid` INT, `path` INT);", dbname, tableName)); err != nil {
return fmt.Errorf("error reading grant: %s", err)
}
return nil
Expand Down
Loading