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 - name can now contain one nested directory #7382

Merged
merged 4 commits into from Jun 17, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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