Skip to content

Commit 214e3a8

Browse files
katbytetombuildsstuff
authored andcommitted
azurerm_storage_account: limit tag names to 128 characters (#1524)
* azurerm_storage_account: limit tag names to 128 characters * fixing the imports
1 parent d676869 commit 214e3a8

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

azurerm/resource_arm_storage_account.go

+31-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package azurerm
22

33
import (
4+
"errors"
45
"fmt"
56
"log"
67
"regexp"
@@ -20,6 +21,7 @@ func resourceArmStorageAccount() *schema.Resource {
2021
Read: resourceArmStorageAccountRead,
2122
Update: resourceArmStorageAccountUpdate,
2223
Delete: resourceArmStorageAccountDelete,
24+
2325
Importer: &schema.ResourceImporter{
2426
State: schema.ImportStatePassthrough,
2527
},
@@ -287,11 +289,39 @@ func resourceArmStorageAccount() *schema.Resource {
287289
},
288290
},
289291

290-
"tags": tagsSchema(),
292+
"tags": {
293+
Type: schema.TypeMap,
294+
Optional: true,
295+
Computed: true,
296+
ValidateFunc: validateAzureRMStorageAccountTags,
297+
},
291298
},
292299
}
293300
}
294301

302+
func validateAzureRMStorageAccountTags(v interface{}, _ string) (ws []string, es []error) {
303+
tagsMap := v.(map[string]interface{})
304+
305+
if len(tagsMap) > 15 {
306+
es = append(es, errors.New("a maximum of 15 tags can be applied to each ARM resource"))
307+
}
308+
309+
for k, v := range tagsMap {
310+
if len(k) > 128 {
311+
es = append(es, fmt.Errorf("the maximum length for a tag key is 128 characters: %q is %d characters", k, len(k)))
312+
}
313+
314+
value, err := tagValueToString(v)
315+
if err != nil {
316+
es = append(es, err)
317+
} else if len(value) > 256 {
318+
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)))
319+
}
320+
}
321+
322+
return ws, es
323+
}
324+
295325
func resourceArmStorageAccountCreate(d *schema.ResourceData, meta interface{}) error {
296326
client := meta.(*ArmClient).storageServiceClient
297327

azurerm/tags.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func tagValueToString(v interface{}) (string, error) {
4545
}
4646
}
4747

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

5151
if len(tagsMap) > 15 {

0 commit comments

Comments
 (0)