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

r/storage_container: support for containers named $web #3896

Merged
merged 1 commit into from
Jul 22, 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
3 changes: 2 additions & 1 deletion azurerm/resource_arm_storage_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ func flattenStorageContainerAccessLevel(input containers.AccessLevel) string {

func validateArmStorageContainerName(v interface{}, k string) (warnings []string, errors []error) {
value := v.(string)
if !regexp.MustCompile(`^\$root$|^[0-9a-z-]+$`).MatchString(value) {

if !regexp.MustCompile(`^\$root$|^\$web$|^[0-9a-z-]+$`).MatchString(value) {
errors = append(errors, fmt.Errorf(
"only lowercase alphanumeric characters and hyphens allowed in %q: %q",
k, value))
Expand Down
44 changes: 44 additions & 0 deletions azurerm/resource_arm_storage_container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,34 @@ func TestAccAzureRMStorageContainer_root(t *testing.T) {
})
}

func TestAccAzureRMStorageContainer_web(t *testing.T) {
resourceName := "azurerm_storage_container.test"

ri := tf.AccRandTimeInt()
rs := strings.ToLower(acctest.RandString(11))
location := testLocation()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMStorageContainerDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMStorageContainer_web(ri, rs, location),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMStorageContainerExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "name", "$web"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testCheckAzureRMStorageContainerExists(resourceName string) resource.TestCheckFunc {
return func(s *terraform.State) error {

Expand Down Expand Up @@ -394,6 +422,20 @@ resource "azurerm_storage_container" "test" {
`, template)
}

func testAccAzureRMStorageContainer_web(rInt int, rString string, location string) string {
template := testAccAzureRMStorageContainer_template(rInt, rString, location)
return fmt.Sprintf(`
%s

resource "azurerm_storage_container" "test" {
name = "$web"
resource_group_name = "${azurerm_resource_group.test.name}"
storage_account_name = "${azurerm_storage_account.test.name}"
container_access_type = "private"
}
`, template)
}

func testAccAzureRMStorageContainer_template(rInt int, rString, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
Expand All @@ -420,6 +462,7 @@ func TestValidateArmStorageContainerName(t *testing.T) {
"valid-name",
"valid02-name",
"$root",
"$web",
}
for _, v := range validNames {
_, errors := validateArmStorageContainerName(v, "name")
Expand All @@ -435,6 +478,7 @@ func TestValidateArmStorageContainerName(t *testing.T) {
"invalid!",
"ww",
"$notroot",
"$notweb",
strings.Repeat("w", 65),
}
for _, v := range invalidNames {
Expand Down