From fec4e8a1a4ed781c057ede2e8e1b7f91ae3b6fe1 Mon Sep 17 00:00:00 2001 From: Nick Metz Date: Wed, 13 Nov 2019 15:57:07 +0100 Subject: [PATCH 1/4] add - to database collation validation, adjust test, remove hyphen underscore rewrite --- azurerm/helpers/validate/database.go | 2 +- azurerm/helpers/validate/database_test.go | 2 +- azurerm/resource_arm_postgresql_database.go | 6 +----- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/azurerm/helpers/validate/database.go b/azurerm/helpers/validate/database.go index bda83f52b22a..5de5dd5da5ed 100644 --- a/azurerm/helpers/validate/database.go +++ b/azurerm/helpers/validate/database.go @@ -12,7 +12,7 @@ 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)) diff --git a/azurerm/helpers/validate/database_test.go b/azurerm/helpers/validate/database_test.go index 773ee5a203d0..b110fee6bd8d 100644 --- a/azurerm/helpers/validate/database_test.go +++ b/azurerm/helpers/validate/database_test.go @@ -9,7 +9,7 @@ func TestDatabaseCollation(t *testing.T) { }{ { Value: "en-US", - Errors: 1, + Errors: 0, }, { Value: "en_US", diff --git a/azurerm/resource_arm_postgresql_database.go b/azurerm/resource_arm_postgresql_database.go index c915f8a5afc6..ffb804481fd0 100644 --- a/azurerm/resource_arm_postgresql_database.go +++ b/azurerm/resource_arm_postgresql_database.go @@ -152,11 +152,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 From ca8cbf2043253574c6ecf23f55f76dcbfab8ad9c Mon Sep 17 00:00:00 2001 From: Nick Metz Date: Wed, 13 Nov 2019 16:51:03 +0100 Subject: [PATCH 2/4] remove unused import strings --- azurerm/resource_arm_postgresql_database.go | 1 - 1 file changed, 1 deletion(-) diff --git a/azurerm/resource_arm_postgresql_database.go b/azurerm/resource_arm_postgresql_database.go index ffb804481fd0..12e60d6a0693 100644 --- a/azurerm/resource_arm_postgresql_database.go +++ b/azurerm/resource_arm_postgresql_database.go @@ -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" From 07c112191f925dd5b20094630c004c296451b06d Mon Sep 17 00:00:00 2001 From: Nick Metz Date: Mon, 18 Nov 2019 09:08:33 +0100 Subject: [PATCH 3/4] update error message in database collation validation, add additional test with false characters --- azurerm/helpers/validate/database.go | 2 +- azurerm/helpers/validate/database_test.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/azurerm/helpers/validate/database.go b/azurerm/helpers/validate/database.go index 5de5dd5da5ed..3b6094eef5df 100644 --- a/azurerm/helpers/validate/database.go +++ b/azurerm/helpers/validate/database.go @@ -15,7 +15,7 @@ func DatabaseCollation(i interface{}, k string) (warnings []string, errors []err 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, underscores, spaces or hyphens characters are supported, got %s", k, v)) return } diff --git a/azurerm/helpers/validate/database_test.go b/azurerm/helpers/validate/database_test.go index b110fee6bd8d..01e748cc5f94 100644 --- a/azurerm/helpers/validate/database_test.go +++ b/azurerm/helpers/validate/database_test.go @@ -7,6 +7,10 @@ func TestDatabaseCollation(t *testing.T) { Value string Errors int }{ + { + Value: "en@US", + Errors: 1, + }, { Value: "en-US", Errors: 0, From 8ec3e5af665f71ff19f18d50794701a8d38bb809 Mon Sep 17 00:00:00 2001 From: Nick Metz Date: Mon, 18 Nov 2019 09:18:35 +0100 Subject: [PATCH 4/4] fix typo in error message --- azurerm/helpers/validate/database.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/helpers/validate/database.go b/azurerm/helpers/validate/database.go index 3b6094eef5df..d79aa3abb502 100644 --- a/azurerm/helpers/validate/database.go +++ b/azurerm/helpers/validate/database.go @@ -15,7 +15,7 @@ func DatabaseCollation(i interface{}, k string) (warnings []string, errors []err matched, _ := regexp.MatchString(`^[-A-Za-z0-9_. ]+$`, v) if !matched { - errors = append(errors, fmt.Errorf("%s contains invalid characters, only alphanumeric, underscores, spaces or hyphens characters 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 }