Skip to content

Commit

Permalink
azurerm_storage_account: limit tag names to 128 characters (#1524)
Browse files Browse the repository at this point in the history
* azurerm_storage_account: limit tag names to 128 characters

* fixing the imports
  • Loading branch information
katbyte authored and tombuildsstuff committed Jul 10, 2018
1 parent d676869 commit 214e3a8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
32 changes: 31 additions & 1 deletion azurerm/resource_arm_storage_account.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package azurerm

import (
"errors"
"fmt"
"log"
"regexp"
Expand All @@ -20,6 +21,7 @@ func resourceArmStorageAccount() *schema.Resource {
Read: resourceArmStorageAccountRead,
Update: resourceArmStorageAccountUpdate,
Delete: resourceArmStorageAccountDelete,

Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Expand Down Expand Up @@ -287,11 +289,39 @@ func resourceArmStorageAccount() *schema.Resource {
},
},

"tags": tagsSchema(),
"tags": {
Type: schema.TypeMap,
Optional: true,
Computed: true,
ValidateFunc: validateAzureRMStorageAccountTags,
},
},
}
}

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

if len(tagsMap) > 15 {
es = append(es, errors.New("a maximum of 15 tags can be applied to each ARM resource"))
}

for k, v := range tagsMap {
if len(k) > 128 {
es = append(es, fmt.Errorf("the maximum length for a tag key is 128 characters: %q is %d characters", k, len(k)))
}

value, err := tagValueToString(v)
if err != nil {
es = append(es, err)
} else if len(value) > 256 {
es = append(es, fmt.Errorf("the maximum length for a tag value is 256 characters: the value for %q is %d characters", k, len(value)))
}
}

return ws, es
}

func resourceArmStorageAccountCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient).storageServiceClient

Expand Down
2 changes: 1 addition & 1 deletion azurerm/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func tagValueToString(v interface{}) (string, error) {
}
}

func validateAzureRMTags(v interface{}, f string) (ws []string, es []error) {
func validateAzureRMTags(v interface{}, _ string) (ws []string, es []error) {
tagsMap := v.(map[string]interface{})

if len(tagsMap) > 15 {
Expand Down

0 comments on commit 214e3a8

Please sign in to comment.