diff --git a/azurerm/helpers/validate/storage.go b/azurerm/helpers/validate/storage.go index 3c503375a1fb..445bac547097 100644 --- a/azurerm/helpers/validate/storage.go +++ b/azurerm/helpers/validate/storage.go @@ -9,11 +9,11 @@ import ( func StorageShareDirectoryName(v interface{}, k string) (warnings []string, errors []error) { value := v.(string) - // File share names can contain only lowercase letters, numbers, and hyphens, + // File share names can contain only uppercase and lowercase letters, numbers, and hyphens, // and must begin and end with a letter or a number. // however they can be nested (e.g. foo/bar) - if !regexp.MustCompile(`^[a-z0-9][a-z0-9-]+[a-z0-9]$`).MatchString(value) && !regexp.MustCompile(`^[a-z0-9]{1,}/[a-z0-9]{1,}$`).MatchString(value) { - errors = append(errors, fmt.Errorf("%s must contain only lowercase alphanumeric characters, numbers and hyphens. It must start and end with a letter and end only with a number or letter", k)) + if !regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9-]+[A-Za-z0-9]$`).MatchString(value) && !regexp.MustCompile(`^[A-Za-z0-9]{1,}/[A-Za-z0-9]{1,}$`).MatchString(value) { + errors = append(errors, fmt.Errorf("%s must contain only uppercase and lowercase alphanumeric characters, numbers and hyphens. It must start and end with a letter and end only with a number or letter", k)) } // The name cannot contain two consecutive hyphens. diff --git a/azurerm/helpers/validate/storage_test.go b/azurerm/helpers/validate/storage_test.go index 042d8bb1e1d2..d0b29c96b1a3 100644 --- a/azurerm/helpers/validate/storage_test.go +++ b/azurerm/helpers/validate/storage_test.go @@ -43,6 +43,18 @@ func TestValidateStorageShareDirectoryName(t *testing.T) { Input: "hello/", Expected: false, }, + { + Input: "Abc123", + Expected: true, + }, + { + Input: "abc123A", + Expected: true, + }, + { + Input: "abC123", + Expected: true, + }, } for _, v := range testCases { diff --git a/azurerm/resource_arm_storage_share_directory_test.go b/azurerm/resource_arm_storage_share_directory_test.go index b690ade083ba..df0a7a129d8f 100644 --- a/azurerm/resource_arm_storage_share_directory_test.go +++ b/azurerm/resource_arm_storage_share_directory_test.go @@ -39,6 +39,32 @@ func TestAccAzureRMStorageShareDirectory_basic(t *testing.T) { }) } +func TestAccAzureRMStorageShareDirectory_uppercase(t *testing.T) { + ri := tf.AccRandTimeInt() + rs := strings.ToLower(acctest.RandString(5)) + location := testLocation() + resourceName := "azurerm_storage_share_directory.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMStorageShareDirectoryDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMStorageShareDirectory_uppercase(ri, rs, location), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMStorageShareDirectoryExists(resourceName), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func TestAccAzureRMStorageShareDirectory_requiresImport(t *testing.T) { if features.ShouldResourcesBeImported() { t.Skip("Skipping since resources aren't required to be imported") @@ -247,6 +273,19 @@ resource "azurerm_storage_share_directory" "test" { `, template) } +func testAccAzureRMStorageShareDirectory_uppercase(rInt int, rString string, location string) string { + template := testAccAzureRMStorageShareDirectory_template(rInt, rString, location) + return fmt.Sprintf(` +%s + +resource "azurerm_storage_share_directory" "test" { + name = "UpperCaseCharacterS" + share_name = "${azurerm_storage_share.test.name}" + storage_account_name = "${azurerm_storage_account.test.name}" +} +`, template) +} + func testAccAzureRMStorageShareDirectory_requiresImport(rInt int, rString string, location string) string { template := testAccAzureRMStorageShareDirectory_basic(rInt, rString, location) return fmt.Sprintf(`