From 30e0f9b2bc96a1dfef24afdcd33848580a26b748 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Thu, 22 Aug 2019 08:23:17 +0200 Subject: [PATCH] validation: allowing for nested directories ``` === RUN TestValidateStorageShareDirectoryName --- PASS: TestValidateStorageShareDirectoryName (0.00s) storage_test.go:49: [DEBUG] Test Input "" storage_test.go:49: [DEBUG] Test Input "abc123" storage_test.go:49: [DEBUG] Test Input "123abc" storage_test.go:49: [DEBUG] Test Input "123-abc" storage_test.go:49: [DEBUG] Test Input "-123-abc" storage_test.go:49: [DEBUG] Test Input "123-abc-" storage_test.go:49: [DEBUG] Test Input "123--abc" storage_test.go:49: [DEBUG] Test Input "hello/world" storage_test.go:49: [DEBUG] Test Input "hello/" PASS ``` --- azurerm/helpers/validate/storage.go | 3 ++- azurerm/helpers/validate/storage_test.go | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/azurerm/helpers/validate/storage.go b/azurerm/helpers/validate/storage.go index 3d834f9d5fa3..3c503375a1fb 100644 --- a/azurerm/helpers/validate/storage.go +++ b/azurerm/helpers/validate/storage.go @@ -11,7 +11,8 @@ func StorageShareDirectoryName(v interface{}, k string) (warnings []string, erro // File share names can contain only lowercase letters, numbers, and hyphens, // and must begin and end with a letter or a number. - if !regexp.MustCompile(`^[a-z0-9][a-z0-9-]+[a-z0-9]$`).MatchString(value) { + // 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)) } diff --git a/azurerm/helpers/validate/storage_test.go b/azurerm/helpers/validate/storage_test.go index 5431a56f89e2..042d8bb1e1d2 100644 --- a/azurerm/helpers/validate/storage_test.go +++ b/azurerm/helpers/validate/storage_test.go @@ -35,6 +35,14 @@ func TestValidateStorageShareDirectoryName(t *testing.T) { Input: "123--abc", Expected: false, }, + { + Input: "hello/world", + Expected: true, + }, + { + Input: "hello/", + Expected: false, + }, } for _, v := range testCases {