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

azurerm_storage_account: limit tag names to 128 characters #1524

Merged
merged 2 commits into from
Jul 10, 2018
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
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