From e95c4c14a738fd113ec4dc9cb15839ec9f1ce079 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Mon, 22 Jul 2019 08:57:22 +0200 Subject: [PATCH] r/storage_container: support for containers named `$web` --- azurerm/resource_arm_storage_container.go | 3 +- .../resource_arm_storage_container_test.go | 44 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/azurerm/resource_arm_storage_container.go b/azurerm/resource_arm_storage_container.go index 922c9d3ebaeb..5814ec27b194 100644 --- a/azurerm/resource_arm_storage_container.go +++ b/azurerm/resource_arm_storage_container.go @@ -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)) diff --git a/azurerm/resource_arm_storage_container_test.go b/azurerm/resource_arm_storage_container_test.go index 3d094407ed21..263cfaa08c98 100644 --- a/azurerm/resource_arm_storage_container_test.go +++ b/azurerm/resource_arm_storage_container_test.go @@ -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 { @@ -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" { @@ -420,6 +462,7 @@ func TestValidateArmStorageContainerName(t *testing.T) { "valid-name", "valid02-name", "$root", + "$web", } for _, v := range validNames { _, errors := validateArmStorageContainerName(v, "name") @@ -435,6 +478,7 @@ func TestValidateArmStorageContainerName(t *testing.T) { "invalid!", "ww", "$notroot", + "$notweb", strings.Repeat("w", 65), } for _, v := range invalidNames {