From 1039cec9c14623938b091cd254692ca92191c3d5 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Tue, 22 Aug 2017 14:31:11 +0100 Subject: [PATCH 1/2] Fixing the CosmosDB name regex to reject upper-case chars --- azurerm/resource_arm_cosmos_db_account.go | 2 +- azurerm/resource_arm_cosmos_db_account_test.go | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/azurerm/resource_arm_cosmos_db_account.go b/azurerm/resource_arm_cosmos_db_account.go index fbd6d3815177..d79fc6972dd4 100644 --- a/azurerm/resource_arm_cosmos_db_account.go +++ b/azurerm/resource_arm_cosmos_db_account.go @@ -398,7 +398,7 @@ func resourceAzureRMCosmosDBAccountFailoverPolicyHash(v interface{}) int { func validateAzureRmCosmosDBAccountName(v interface{}, k string) (ws []string, errors []error) { value := v.(string) - r, _ := regexp.Compile("[a-z0-9-]") + r, _ := regexp.Compile("^([a-z0-9\\-]+)$") if !r.MatchString(value) { errors = append(errors, fmt.Errorf("CosmosDB Account Name can only contain lower-case characters, numbers and the `-` character.")) } diff --git a/azurerm/resource_arm_cosmos_db_account_test.go b/azurerm/resource_arm_cosmos_db_account_test.go index e050028b1df7..80d49a0229a1 100644 --- a/azurerm/resource_arm_cosmos_db_account_test.go +++ b/azurerm/resource_arm_cosmos_db_account_test.go @@ -24,6 +24,14 @@ func TestAccAzureRMCosmosDBAccountName_validation(t *testing.T) { Value: "abc", ErrCount: 0, }, + { + Value: "cosmosDBAccount1", + ErrCount: 1, + }, + { + Value: "hello-world", + ErrCount: 0, + }, { Value: str, ErrCount: 0, From 753bcca729b4fceb9dae9600a363035e5e7a4766 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Tue, 22 Aug 2017 18:10:42 +0100 Subject: [PATCH 2/2] Removing the unnecessary brackets --- azurerm/resource_arm_cosmos_db_account.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/resource_arm_cosmos_db_account.go b/azurerm/resource_arm_cosmos_db_account.go index d79fc6972dd4..3e2a595bc374 100644 --- a/azurerm/resource_arm_cosmos_db_account.go +++ b/azurerm/resource_arm_cosmos_db_account.go @@ -398,7 +398,7 @@ func resourceAzureRMCosmosDBAccountFailoverPolicyHash(v interface{}) int { func validateAzureRmCosmosDBAccountName(v interface{}, k string) (ws []string, errors []error) { value := v.(string) - r, _ := regexp.Compile("^([a-z0-9\\-]+)$") + r, _ := regexp.Compile("^[a-z0-9\\-]+$") if !r.MatchString(value) { errors = append(errors, fmt.Errorf("CosmosDB Account Name can only contain lower-case characters, numbers and the `-` character.")) }