From 82a102c4cbda178db438f4ccff3ea62fdc485cb4 Mon Sep 17 00:00:00 2001 From: kt Date: Mon, 9 Jul 2018 16:35:50 -0700 Subject: [PATCH 1/2] azurerm_storage_account: limit tag names to 128 characters --- azurerm/resource_arm_storage_account.go | 32 ++++++++++++++++++++++++- azurerm/tags.go | 2 +- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/azurerm/resource_arm_storage_account.go b/azurerm/resource_arm_storage_account.go index be90c7050a59..3ee4578887bd 100644 --- a/azurerm/resource_arm_storage_account.go +++ b/azurerm/resource_arm_storage_account.go @@ -6,6 +6,7 @@ import ( "regexp" "strings" + "errors" "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2017-10-01/storage" "github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/validation" @@ -20,6 +21,7 @@ func resourceArmStorageAccount() *schema.Resource { Read: resourceArmStorageAccountRead, Update: resourceArmStorageAccountUpdate, Delete: resourceArmStorageAccountDelete, + Importer: &schema.ResourceImporter{ State: schema.ImportStatePassthrough, }, @@ -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 diff --git a/azurerm/tags.go b/azurerm/tags.go index cbb70069b84d..20d27a741abf 100644 --- a/azurerm/tags.go +++ b/azurerm/tags.go @@ -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 { From 7e9cea748b1b60484ddec4f71cb0a5a02cb87907 Mon Sep 17 00:00:00 2001 From: Tom Harvey Date: Tue, 10 Jul 2018 08:47:32 +0200 Subject: [PATCH 2/2] fixing the imports --- azurerm/resource_arm_storage_account.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azurerm/resource_arm_storage_account.go b/azurerm/resource_arm_storage_account.go index 3ee4578887bd..50167b2d53bb 100644 --- a/azurerm/resource_arm_storage_account.go +++ b/azurerm/resource_arm_storage_account.go @@ -1,12 +1,12 @@ package azurerm import ( + "errors" "fmt" "log" "regexp" "strings" - "errors" "github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2017-10-01/storage" "github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/validation"