Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_storage_share_directory Allow uppercase characters #4178

Merged
merged 3 commits into from
Aug 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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