Skip to content

Commit

Permalink
r/storage_container: support for containers named $web (#3896)
Browse files Browse the repository at this point in the history
Fixes #3894
  • Loading branch information
tombuildsstuff authored and katbyte committed Jul 22, 2019
1 parent af62f66 commit 54c314a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
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 @@ -205,6 +205,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 @@ -422,6 +450,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 @@ -448,6 +490,7 @@ func TestValidateArmStorageContainerName(t *testing.T) {
"valid-name",
"valid02-name",
"$root",
"$web",
}
for _, v := range validNames {
_, errors := validateArmStorageContainerName(v, "name")
Expand All @@ -463,6 +506,7 @@ func TestValidateArmStorageContainerName(t *testing.T) {
"invalid!",
"ww",
"$notroot",
"$notweb",
strings.Repeat("w", 65),
}
for _, v := range invalidNames {
Expand Down

0 comments on commit 54c314a

Please sign in to comment.