Skip to content

Commit

Permalink
Merge pull request #4866 from NickMetz/b/azure-postgresql-collation
Browse files Browse the repository at this point in the history
`azurerm_postgres_database` allow `-`s in database collation
  • Loading branch information
tombuildsstuff authored Nov 18, 2019
2 parents ce9c65f + 8ec3e5a commit f46cc42
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions azurerm/helpers/validate/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ func DatabaseCollation(i interface{}, k string) (warnings []string, errors []err
return
}

matched, _ := regexp.MatchString(`^[A-Za-z0-9_. ]+$`, v)
matched, _ := regexp.MatchString(`^[-A-Za-z0-9_. ]+$`, v)

if !matched {
errors = append(errors, fmt.Errorf("%s contains invalid characters, only underscores are supported, got %s", k, v))
errors = append(errors, fmt.Errorf("%s contains invalid characters, only alphanumeric, underscore, space or hyphen characters are supported, got %s", k, v))
return
}

Expand Down
6 changes: 5 additions & 1 deletion azurerm/helpers/validate/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ func TestDatabaseCollation(t *testing.T) {
Errors int
}{
{
Value: "en-US",
Value: "en@US",
Errors: 1,
},
{
Value: "en-US",
Errors: 0,
},
{
Value: "en_US",
Errors: 0,
Expand Down
7 changes: 1 addition & 6 deletions azurerm/resource_arm_postgresql_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package azurerm
import (
"fmt"
"log"
"strings"
"time"

"github.com/Azure/azure-sdk-for-go/services/postgresql/mgmt/2017-12-01/postgresql"
Expand Down Expand Up @@ -152,11 +151,7 @@ func resourceArmPostgreSQLDatabaseRead(d *schema.ResourceData, meta interface{})

if props := resp.DatabaseProperties; props != nil {
d.Set("charset", props.Charset)

if collation := props.Collation; collation != nil {
v := strings.Replace(*collation, "-", "_", -1)
d.Set("collation", v)
}
d.Set("collation", props.Collation)
}

return nil
Expand Down

0 comments on commit f46cc42

Please sign in to comment.