Skip to content

Commit

Permalink
Merge pull request #5934 from terraform-providers/kt/storage-gets-mor…
Browse files Browse the repository at this point in the history
…e-tags

azurerm_storage_account - allow up to 50 tags
  • Loading branch information
katbyte authored Feb 28, 2020
2 parents f7884f1 + 29ac33a commit 9d147dc
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 12 deletions.
23 changes: 11 additions & 12 deletions azurerm/internal/services/storage/resource_arm_storage_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,16 +224,6 @@ func resourceArmStorageAccount() *schema.Resource {
},
},

"tags": {
Type: schema.TypeMap,
Optional: true,
Computed: true,
ValidateFunc: validateAzureRMStorageAccountTags,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},

"blob_properties": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -543,15 +533,24 @@ func resourceArmStorageAccount() *schema.Resource {
Computed: true,
Sensitive: true,
},

"tags": {
Type: schema.TypeMap,
Optional: true,
ValidateFunc: validateAzureRMStorageAccountTags,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
}
}

func validateAzureRMStorageAccountTags(v interface{}, _ string) (warnings []string, errors []error) {
tagsMap := v.(map[string]interface{})

if len(tagsMap) > 15 {
errors = append(errors, fmt.Errorf("a maximum of 15 tags can be applied to storage account ARM resource"))
if len(tagsMap) > 50 {
errors = append(errors, fmt.Errorf("a maximum of 50 tags can be applied to storage account ARM resource"))
}

for k, v := range tagsMap {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,25 @@ func TestAccAzureRMStorageAccount_requiresImport(t *testing.T) {
})
}

func TestAccAzureRMStorageAccount_tagCount(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_storage_account", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMStorageAccountDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMStorageAccount_tagCount(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMStorageAccountExists(data.ResourceName),
),
},
data.ImportStep(),
},
})
}

func TestAccAzureRMStorageAccount_writeLock(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_storage_account", "test")

Expand Down Expand Up @@ -675,6 +694,37 @@ resource "azurerm_storage_account" "test" {
`, data.RandomInteger, data.Locations.Primary, data.RandomString)
}

func testAccAzureRMStorageAccount_tagCount(data acceptance.TestData) string {
tags := ""
for i := 0; i < 50; i++ {
tags += fmt.Sprintf("t%d = \"v%d\"\n", i, i)
}

return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-storage-%d"
location = "%s"
}
resource "azurerm_storage_account" "test" {
name = "unlikely23exst2acct%s"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
account_tier = "Standard"
account_replication_type = "LRS"
tags = {
%s
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomString, tags)
}

func testAccAzureRMStorageAccount_requiresImport(data acceptance.TestData) string {
template := testAccAzureRMStorageAccount_basic(data)
return fmt.Sprintf(`
Expand Down

0 comments on commit 9d147dc

Please sign in to comment.