diff --git a/azurerm/resource_arm_cosmos_db_account.go b/azurerm/resource_arm_cosmos_db_account.go index fbd6d3815177..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.")) } 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,