Skip to content

Commit

Permalink
azurerm_storage_share_directory - name can now contain one neste…
Browse files Browse the repository at this point in the history
…d directory #7382
  • Loading branch information
jogleasonjr committed Jun 17, 2020
1 parent 33aced7 commit a24b027
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
4 changes: 2 additions & 2 deletions azurerm/helpers/validate/storage.go
Expand Up @@ -11,8 +11,8 @@ func StorageShareDirectoryName(v interface{}, k string) (warnings []string, erro

// 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-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) {
// However they can be nested (e.g. foo/bar) with at most one level.
if !regexp.MustCompile(`^[A-Za-z0-9]{1,}[A-Za-z0-9-]{0,1}[A-Za-z0-9]{1,}(/[A-Za-z0-9]{1,}[A-Za-z0-9-]{0,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))
}

Expand Down
16 changes: 16 additions & 0 deletions azurerm/helpers/validate/storage_test.go
Expand Up @@ -39,6 +39,22 @@ func TestValidateStorageShareDirectoryName(t *testing.T) {
Input: "hello/world",
Expected: true,
},
{
Input: "123-abc/hello-world",
Expected: true,
},
{
Input: "123-abc/hello--world",
Expected: false,
},
{
Input: "123-abc/hello/world",
Expected: false,
},
{
Input: "123-abc/hello/world-",
Expected: false,
},
{
Input: "hello/",
Expected: false,
Expand Down
Expand Up @@ -124,7 +124,7 @@ func TestAccAzureRMStorageShareDirectory_nested(t *testing.T) {
Config: testAccAzureRMStorageShareDirectory_nested(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMStorageShareDirectoryExists("azurerm_storage_share_directory.parent"),
testCheckAzureRMStorageShareDirectoryExists("azurerm_storage_share_directory.child"),
testCheckAzureRMStorageShareDirectoryExists("azurerm_storage_share_directory.child_two"),
),
},
},
Expand Down Expand Up @@ -305,6 +305,12 @@ resource "azurerm_storage_share_directory" "child" {
share_name = azurerm_storage_share.test.name
storage_account_name = azurerm_storage_account.test.name
}
resource "azurerm_storage_share_directory" "child_two" {
name = "${azurerm_storage_share_directory.parent.name}/child-two"
share_name = azurerm_storage_share.test.name
storage_account_name = azurerm_storage_account.test.name
}
`, template)
}

Expand Down

0 comments on commit a24b027

Please sign in to comment.