Skip to content

Commit

Permalink
Merge pull request #4178 from nexxai/master
Browse files Browse the repository at this point in the history
`azurerm_storage_share_directory` Allow uppercase characters
  • Loading branch information
tombuildsstuff authored Aug 28, 2019
2 parents bc18c06 + a68a9af commit 2010a2a
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
6 changes: 3 additions & 3 deletions azurerm/helpers/validate/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions azurerm/helpers/validate/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
39 changes: 39 additions & 0 deletions azurerm/resource_arm_storage_share_directory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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(`
Expand Down

0 comments on commit 2010a2a

Please sign in to comment.