From c179a316a7d1c3051b8a2e4f476dc3d7ddffded6 Mon Sep 17 00:00:00 2001 From: kt Date: Wed, 21 Nov 2018 12:30:06 -0800 Subject: [PATCH] standardized validation function sigs --- azurerm/helpers/azure/key_vault_child.go | 22 +++++----- azurerm/helpers/azure/resource_group.go | 10 ++--- azurerm/helpers/azure/validate.go | 4 +- azurerm/helpers/validate/api_management.go | 18 ++++---- azurerm/helpers/validate/base64.go | 8 ++-- azurerm/helpers/validate/compute.go | 22 +++++----- azurerm/helpers/validate/devspace.go | 12 +++--- azurerm/helpers/validate/int.go | 26 ++++++------ azurerm/helpers/validate/iothub.go | 12 +++--- azurerm/helpers/validate/network.go | 4 +- azurerm/helpers/validate/public_ip.go | 4 +- azurerm/helpers/validate/uuid.go | 4 +- .../validate/virtual_network_rule_name.go | 4 +- azurerm/loadbalancer.go | 4 +- azurerm/resource_arm_app_service.go | 6 +-- azurerm/resource_arm_app_service_plan.go | 6 +-- azurerm/resource_arm_container_registry.go | 4 +- azurerm/resource_arm_container_service.go | 12 +++--- azurerm/resource_arm_databricks_workspace.go | 8 ++-- azurerm/resource_arm_eventhub.go | 12 +++--- azurerm/resource_arm_firewall.go | 6 +-- azurerm/resource_arm_iothub.go | 8 ++-- azurerm/resource_arm_key_vault.go | 4 +- azurerm/resource_arm_loadbalancer_rule.go | 4 +- .../resource_arm_log_analytics_workspace.go | 4 +- ...urce_arm_logic_app_trigger_http_request.go | 4 +- azurerm/resource_arm_managed_disk.go | 4 +- azurerm/resource_arm_management_lock.go | 8 ++-- azurerm/resource_arm_metric_alertrule.go | 8 ++-- azurerm/resource_arm_redis_cache.go | 12 +++--- azurerm/resource_arm_redis_firewall_rule.go | 6 +-- azurerm/resource_arm_snapshot.go | 4 +- .../resource_arm_sql_virtual_network_rule.go | 4 +- azurerm/resource_arm_storage_account.go | 25 ++++++----- azurerm/resource_arm_storage_container.go | 8 ++-- azurerm/resource_arm_storage_queue.go | 4 +- azurerm/resource_arm_storage_share.go | 4 +- azurerm/resource_arm_storage_table.go | 4 +- .../resource_arm_virtual_network_gateway.go | 12 +++--- azurerm/tags.go | 13 +++--- azurerm/validators.go | 41 +++++++++++-------- 41 files changed, 196 insertions(+), 193 deletions(-) diff --git a/azurerm/helpers/azure/key_vault_child.go b/azurerm/helpers/azure/key_vault_child.go index eb308f668167..a6c8c3d5a04d 100644 --- a/azurerm/helpers/azure/key_vault_child.go +++ b/azurerm/helpers/azure/key_vault_child.go @@ -42,34 +42,34 @@ func ParseKeyVaultChildID(id string) (*KeyVaultChildID, error) { return &childId, nil } -func ValidateKeyVaultChildName(v interface{}, k string) (ws []string, es []error) { +func ValidateKeyVaultChildName(v interface{}, k string) (warnings []string, errors []error) { value := v.(string) if matched := regexp.MustCompile(`^[0-9a-zA-Z-]+$`).Match([]byte(value)); !matched { - es = append(es, fmt.Errorf("%q may only contain alphanumeric characters and dashes", k)) + errors = append(errors, fmt.Errorf("%q may only contain alphanumeric characters and dashes", k)) } - return ws, es + return warnings, errors } // Unfortunately this can't (easily) go in the Validate package // since there's a circular reference on this package -func ValidateKeyVaultChildId(i interface{}, k string) (s []string, es []error) { - if s, es = validation.NoZeroValues(i, k); len(es) > 0 { - return s, es +func ValidateKeyVaultChildId(i interface{}, k string) (warnings []string, errors []error) { + if warnings, errors = validation.NoZeroValues(i, k); len(errors) > 0 { + return warnings, errors } v, ok := i.(string) if !ok { - es = append(es, fmt.Errorf("Expected %s to be a string!", k)) - return s, es + errors = append(errors, fmt.Errorf("Expected %s to be a string!", k)) + return warnings, errors } _, err := ParseKeyVaultChildID(v) if err != nil { - es = append(es, fmt.Errorf("Error parsing Key Vault Child ID: %s", err)) - return s, es + errors = append(errors, fmt.Errorf("Error parsing Key Vault Child ID: %s", err)) + return warnings, errors } - return s, es + return warnings, errors } diff --git a/azurerm/helpers/azure/resource_group.go b/azurerm/helpers/azure/resource_group.go index 2dc694953708..2a782c129f10 100644 --- a/azurerm/helpers/azure/resource_group.go +++ b/azurerm/helpers/azure/resource_group.go @@ -35,21 +35,21 @@ func SchemaResourceGroupNameForDataSource() *schema.Schema { } } -func validateResourceGroupName(v interface{}, k string) (ws []string, es []error) { +func validateResourceGroupName(v interface{}, k string) (warnings []string, errors []error) { value := v.(string) if len(value) > 80 { - es = append(es, fmt.Errorf("%q may not exceed 80 characters in length", k)) + errors = append(errors, fmt.Errorf("%q may not exceed 80 characters in length", k)) } if strings.HasSuffix(value, ".") { - es = append(es, fmt.Errorf("%q may not end with a period", k)) + errors = append(errors, fmt.Errorf("%q may not end with a period", k)) } // regex pulled from https://docs.microsoft.com/en-us/rest/api/resources/resourcegroups/createorupdate if matched := regexp.MustCompile(`^[-\w\._\(\)]+$`).Match([]byte(value)); !matched { - es = append(es, fmt.Errorf("%q may only contain alphanumeric characters, dash, underscores, parentheses and periods", k)) + errors = append(errors, fmt.Errorf("%q may only contain alphanumeric characters, dash, underscores, parentheses and periods", k)) } - return ws, es + return warnings, errors } diff --git a/azurerm/helpers/azure/validate.go b/azurerm/helpers/azure/validate.go index 945343416ff2..6c29a72791b6 100644 --- a/azurerm/helpers/azure/validate.go +++ b/azurerm/helpers/azure/validate.go @@ -5,7 +5,7 @@ import ( "regexp" ) -func ValidateResourceID(i interface{}, k string) (ws []string, errors []error) { +func ValidateResourceID(i interface{}, k string) (warnings []string, errors []error) { v, ok := i.(string) if !ok { errors = append(errors, fmt.Errorf("expected type of %q to be string", k)) @@ -16,7 +16,7 @@ func ValidateResourceID(i interface{}, k string) (ws []string, errors []error) { errors = append(errors, fmt.Errorf("Can not parse %q as a resource id: %v", k, err)) } - return ws, errors + return warnings, errors } //true for a resource ID or an empty string diff --git a/azurerm/helpers/validate/api_management.go b/azurerm/helpers/validate/api_management.go index d0764a6ac4ae..b0780799a52c 100644 --- a/azurerm/helpers/validate/api_management.go +++ b/azurerm/helpers/validate/api_management.go @@ -5,32 +5,32 @@ import ( "regexp" ) -func ApiManagementServiceName(v interface{}, k string) (ws []string, es []error) { +func ApiManagementServiceName(v interface{}, k string) (warnings []string, errors []error) { value := v.(string) if matched := regexp.MustCompile(`^[0-9a-zA-Z-]{1,50}$`).Match([]byte(value)); !matched { - es = append(es, fmt.Errorf("%q may only contain alphanumeric characters and dashes up to 50 characters in length", k)) + errors = append(errors, fmt.Errorf("%q may only contain alphanumeric characters and dashes up to 50 characters in length", k)) } - return ws, es + return warnings, errors } -func ApiManagementServicePublisherName(v interface{}, k string) (ws []string, es []error) { +func ApiManagementServicePublisherName(v interface{}, k string) (warnings []string, errors []error) { value := v.(string) if matched := regexp.MustCompile(`^.{1,100}$`).Match([]byte(value)); !matched { - es = append(es, fmt.Errorf("%q may only be up to 100 characters in length", k)) + errors = append(errors, fmt.Errorf("%q may only be up to 100 characters in length", k)) } - return ws, es + return warnings, errors } -func ApiManagementServicePublisherEmail(v interface{}, k string) (ws []string, es []error) { +func ApiManagementServicePublisherEmail(v interface{}, k string) (warnings []string, errors []error) { value := v.(string) if matched := regexp.MustCompile(`^[\S*]{1,100}$`).Match([]byte(value)); !matched { - es = append(es, fmt.Errorf("%q may only be up to 100 characters in length", k)) + errors = append(errors, fmt.Errorf("%q may only be up to 100 characters in length", k)) } - return ws, es + return warnings, errors } diff --git a/azurerm/helpers/validate/base64.go b/azurerm/helpers/validate/base64.go index 116a563073f8..8a5774a2e9b3 100644 --- a/azurerm/helpers/validate/base64.go +++ b/azurerm/helpers/validate/base64.go @@ -9,20 +9,20 @@ import ( ) func Base64String() schema.SchemaValidateFunc { - return func(i interface{}, k string) (s []string, es []error) { + return func(i interface{}, k string) (warnings []string, errors []error) { // Empty string is not allowed - if s, es = validation.NoZeroValues(i, k); len(es) > 0 { + if warnings, errors = validation.NoZeroValues(i, k); len(errors) > 0 { return } v, ok := i.(string) if !ok { - es = append(es, fmt.Errorf("expected type of %s to be string", k)) + errors = append(errors, fmt.Errorf("expected type of %s to be string", k)) return } if _, err := base64.StdEncoding.DecodeString(v); err != nil { - es = append(es, fmt.Errorf("expect value (%s) of %s is base64 string", v, k)) + errors = append(errors, fmt.Errorf("expect value (%s) of %s is base64 string", v, k)) } return diff --git a/azurerm/helpers/validate/compute.go b/azurerm/helpers/validate/compute.go index b7125797f9e6..df6cf2982ab8 100644 --- a/azurerm/helpers/validate/compute.go +++ b/azurerm/helpers/validate/compute.go @@ -5,46 +5,46 @@ import ( "regexp" ) -func SharedImageGalleryName(v interface{}, k string) (ws []string, es []error) { +func SharedImageGalleryName(v interface{}, k string) (warnings []string, errors []error) { value := v.(string) // Image gallery name accepts only alphanumeric, dots and underscores in the name (no dashes) r, _ := regexp.Compile(`^[A-Za-z0-9._]+$`) if !r.MatchString(value) { - es = append(es, fmt.Errorf("%s can only contain alphanumeric, full stops and underscores. Got %q.", k, value)) + errors = append(errors, fmt.Errorf("%s can only contain alphanumeric, full stops and underscores. Got %q.", k, value)) } length := len(value) if length >= 80 { - es = append(es, fmt.Errorf("%s can be up to 80 characters, currently %d.", k, length)) + errors = append(errors, fmt.Errorf("%s can be up to 80 characters, currently %d.", k, length)) } - return ws, es + return warnings, errors } -func SharedImageName(v interface{}, k string) (ws []string, es []error) { +func SharedImageName(v interface{}, k string) (warnings []string, errors []error) { // different from the shared image gallery name value := v.(string) r, _ := regexp.Compile(`^[A-Za-z0-9._-]+$`) if !r.MatchString(value) { - es = append(es, fmt.Errorf("%s can only contain alphanumeric, full stops, dashes and underscores. Got %q.", k, value)) + errors = append(errors, fmt.Errorf("%s can only contain alphanumeric, full stops, dashes and underscores. Got %q.", k, value)) } length := len(value) if length >= 80 { - es = append(es, fmt.Errorf("%s can be up to 80 characters, currently %d.", k, length)) + errors = append(errors, fmt.Errorf("%s can be up to 80 characters, currently %d.", k, length)) } - return ws, es + return warnings, errors } -func SharedImageVersionName(v interface{}, k string) (ws []string, es []error) { +func SharedImageVersionName(v interface{}, k string) (warnings []string, errors []error) { value := v.(string) r, _ := regexp.Compile(`^([0-9]{1,10}\.[0-9]{1,10}\.[0-9]{1,10})$`) if !r.MatchString(value) { - es = append(es, fmt.Errorf("Expected %s to be in the format `1.2.3` but got %q.", k, value)) + errors = append(errors, fmt.Errorf("Expected %s to be in the format `1.2.3` but got %q.", k, value)) } - return ws, es + return warnings, errors } diff --git a/azurerm/helpers/validate/devspace.go b/azurerm/helpers/validate/devspace.go index a21e933be1d1..b34c431749c3 100644 --- a/azurerm/helpers/validate/devspace.go +++ b/azurerm/helpers/validate/devspace.go @@ -8,19 +8,19 @@ import ( ) func DevSpaceName() schema.SchemaValidateFunc { - return func(i interface{}, k string) (s []string, es []error) { + return func(i interface{}, k string) (warnings []string, errors []error) { // Length should be between 3 and 31. - if s, es = validation.StringLenBetween(3, 31)(i, k); len(es) > 0 { - return s, es + if warnings, errors = validation.StringLenBetween(3, 31)(i, k); len(errors) > 0 { + return warnings, errors } // Naming rule. regexStr := "^[a-zA-Z0-9](-?[a-zA-Z0-9])*$" errMsg := "DevSpace name can only include alphanumeric characters, hyphens." - if s, es = validation.StringMatch(regexp.MustCompile(regexStr), errMsg)(i, k); len(es) > 0 { - return s, es + if warnings, errors = validation.StringMatch(regexp.MustCompile(regexStr), errMsg)(i, k); len(errors) > 0 { + return warnings, errors } - return s, es + return warnings, errors } } diff --git a/azurerm/helpers/validate/int.go b/azurerm/helpers/validate/int.go index 4880f4f7ec9a..cbd327d06c78 100644 --- a/azurerm/helpers/validate/int.go +++ b/azurerm/helpers/validate/int.go @@ -10,53 +10,53 @@ import ( // IntBetweenAndDivisibleBy returns a SchemaValidateFunc which tests if the provided value // is of type int and is between min and max (inclusive) and is divisible by a given number func IntBetweenAndDivisibleBy(min, max, divisor int) schema.SchemaValidateFunc { // nolint: unparam - return func(i interface{}, k string) (s []string, es []error) { + return func(i interface{}, k string) (warnings []string, errors []error) { v, ok := i.(int) if !ok { - es = append(es, fmt.Errorf("expected type of %s to be int", k)) + errors = append(errors, fmt.Errorf("expected type of %s to be int", k)) return } if v < min || v > max { - es = append(es, fmt.Errorf("expected %s to be in the range (%d - %d), got %d", k, min, max, v)) + errors = append(errors, fmt.Errorf("expected %s to be in the range (%d - %d), got %d", k, min, max, v)) return } if math.Mod(float64(v), float64(divisor)) != 0 { - es = append(es, fmt.Errorf("expected %s to be divisible by %d", k, divisor)) + errors = append(errors, fmt.Errorf("expected %s to be divisible by %d", k, divisor)) return } - return s, es + return warnings, errors } } // IntDivisibleBy returns a SchemaValidateFunc which tests if the provided value // is of type int and is divisible by a given number func IntDivisibleBy(divisor int) schema.SchemaValidateFunc { // nolint: unparam - return func(i interface{}, k string) (s []string, es []error) { + return func(i interface{}, k string) (warnings []string, errors []error) { v, ok := i.(int) if !ok { - es = append(es, fmt.Errorf("expected type of %s to be int", k)) + errors = append(errors, fmt.Errorf("expected type of %s to be int", k)) return } if math.Mod(float64(v), float64(divisor)) != 0 { - es = append(es, fmt.Errorf("expected %s to be divisible by %d", k, divisor)) + errors = append(errors, fmt.Errorf("expected %s to be divisible by %d", k, divisor)) return } - return s, es + return warnings, errors } } // IntInSlice returns a SchemaValidateFunc which tests if the provided value // is of type int and matches the value of an element in the valid slice func IntInSlice(valid []int) schema.SchemaValidateFunc { - return func(i interface{}, k string) (s []string, es []error) { + return func(i interface{}, k string) (warnings []string, errors []error) { v, ok := i.(int) if !ok { - es = append(es, fmt.Errorf("expected type of %s to be int", k)) + errors = append(errors, fmt.Errorf("expected type of %s to be int", k)) return } @@ -66,7 +66,7 @@ func IntInSlice(valid []int) schema.SchemaValidateFunc { } } - es = append(es, fmt.Errorf("expected %q to be one of %v, got %v", k, valid, v)) - return s, es + errors = append(errors, fmt.Errorf("expected %q to be one of %v, got %v", k, valid, v)) + return warnings, errors } } diff --git a/azurerm/helpers/validate/iothub.go b/azurerm/helpers/validate/iothub.go index 4e5fdc926e24..ef467d561cba 100644 --- a/azurerm/helpers/validate/iothub.go +++ b/azurerm/helpers/validate/iothub.go @@ -5,24 +5,24 @@ import ( "regexp" ) -func IoTHubName(v interface{}, k string) (ws []string, es []error) { +func IoTHubName(v interface{}, k string) (warnings []string, errors []error) { value := v.(string) // Portal: The value must contain only alphanumeric characters or the following: - if matched := regexp.MustCompile(`^[0-9a-zA-Z-]{1,}$`).Match([]byte(value)); !matched { - es = append(es, fmt.Errorf("%q may only contain alphanumeric characters and dashes", k)) + errors = append(errors, fmt.Errorf("%q may only contain alphanumeric characters and dashes", k)) } - return ws, es + return warnings, errors } -func IoTHubConsumerGroupName(v interface{}, k string) (ws []string, es []error) { +func IoTHubConsumerGroupName(v interface{}, k string) (warnings []string, errors []error) { value := v.(string) // Portal: The value must contain only alphanumeric characters or the following: - . _ if matched := regexp.MustCompile(`^[0-9a-zA-Z-._]{1,}$`).Match([]byte(value)); !matched { - es = append(es, fmt.Errorf("%q may only contain alphanumeric characters and dashes, periods and underscores", k)) + errors = append(errors, fmt.Errorf("%q may only contain alphanumeric characters and dashes, periods and underscores", k)) } - return ws, es + return warnings, errors } diff --git a/azurerm/helpers/validate/network.go b/azurerm/helpers/validate/network.go index 03ab486dabd3..1b5841a379e0 100644 --- a/azurerm/helpers/validate/network.go +++ b/azurerm/helpers/validate/network.go @@ -9,7 +9,7 @@ func IPv6Address(i interface{}, k string) (warnings []string, errors []error) { return validateIpv6Address(i, k, false) } -func validateIpv6Address(i interface{}, k string, allowEmpty bool) (ws []string, errors []error) { // nolint: unparam +func validateIpv6Address(i interface{}, k string, allowEmpty bool) (warnings []string, errors []error) { // nolint: unparam v, ok := i.(string) if !ok { errors = append(errors, fmt.Errorf("expected type of %q to be string", k)) @@ -25,7 +25,7 @@ func validateIpv6Address(i interface{}, k string, allowEmpty bool) (ws []string, errors = append(errors, fmt.Errorf("%q is not a valid IPv6 address: %q", k, v)) } - return ws, errors + return warnings, errors } diff --git a/azurerm/helpers/validate/public_ip.go b/azurerm/helpers/validate/public_ip.go index c64e19ae9fe9..83bcfa0cb5d9 100644 --- a/azurerm/helpers/validate/public_ip.go +++ b/azurerm/helpers/validate/public_ip.go @@ -5,10 +5,10 @@ import ( "regexp" ) -func PublicIpDomainNameLabel(v interface{}, k string) (ws []string, errors []error) { +func PublicIpDomainNameLabel(v interface{}, k string) (warnings []string, errors []error) { value := v.(string) if !regexp.MustCompile(`^[a-z][a-z0-9-]{1,61}[a-z0-9]$`).MatchString(value) { errors = append(errors, fmt.Errorf("%s must contain only lowercase alphanumeric characters, numbers and hyphens. It must start with a letter and end only with a number or letter", k)) } - return ws, errors + return warnings, errors } diff --git a/azurerm/helpers/validate/uuid.go b/azurerm/helpers/validate/uuid.go index 797f6af4ea8f..4518ba1d5abb 100644 --- a/azurerm/helpers/validate/uuid.go +++ b/azurerm/helpers/validate/uuid.go @@ -6,7 +6,7 @@ import ( "github.com/hashicorp/go-uuid" ) -func UUID(i interface{}, k string) (ws []string, errors []error) { +func UUID(i interface{}, k string) (warnings []string, errors []error) { v, ok := i.(string) if !ok { errors = append(errors, fmt.Errorf("expected type of %q to be string", k)) @@ -17,5 +17,5 @@ func UUID(i interface{}, k string) (ws []string, errors []error) { errors = append(errors, fmt.Errorf("%q isn't a valid UUID (%q): %+v", k, v, err)) } - return ws, errors + return warnings, errors } diff --git a/azurerm/helpers/validate/virtual_network_rule_name.go b/azurerm/helpers/validate/virtual_network_rule_name.go index a5fc07ffa042..3b56715298c3 100644 --- a/azurerm/helpers/validate/virtual_network_rule_name.go +++ b/azurerm/helpers/validate/virtual_network_rule_name.go @@ -5,7 +5,7 @@ import ( "regexp" ) -func VirtualNetworkRuleName(v interface{}, k string) (ws []string, errors []error) { +func VirtualNetworkRuleName(v interface{}, k string) (warnings []string, errors []error) { value := v.(string) // Cannot be empty @@ -39,5 +39,5 @@ func VirtualNetworkRuleName(v interface{}, k string) (ws []string, errors []erro "%q cannot start with a number or hyphen: %q", k, value)) } - return ws, errors + return warnings, errors } diff --git a/azurerm/loadbalancer.go b/azurerm/loadbalancer.go index 04e28f2d7ec9..d4af5fc2d2bf 100644 --- a/azurerm/loadbalancer.go +++ b/azurerm/loadbalancer.go @@ -138,12 +138,12 @@ func loadbalancerStateRefreshFunc(ctx context.Context, client network.LoadBalanc } } -func validateLoadBalancerPrivateIpAddressAllocation(v interface{}, _ string) (ws []string, errors []error) { +func validateLoadBalancerPrivateIpAddressAllocation(v interface{}, _ string) (warnings []string, errors []error) { value := strings.ToLower(v.(string)) if value != "static" && value != "dynamic" { errors = append(errors, fmt.Errorf("LoadBalancer Allocations can only be Static or Dynamic")) } - return ws, errors + return warnings, errors } // sets the loadbalancer_id in the ResourceData from the sub resources full id diff --git a/azurerm/resource_arm_app_service.go b/azurerm/resource_arm_app_service.go index 952549f6bbd8..2046f29ef421 100644 --- a/azurerm/resource_arm_app_service.go +++ b/azurerm/resource_arm_app_service.go @@ -603,14 +603,14 @@ func flattenAzureRmAppServiceMachineIdentity(identity *web.ManagedServiceIdentit return []interface{}{result} } -func validateAppServiceName(v interface{}, k string) (ws []string, es []error) { +func validateAppServiceName(v interface{}, k string) (warnings []string, errors []error) { value := v.(string) if matched := regexp.MustCompile(`^[0-9a-zA-Z-]{1,60}$`).Match([]byte(value)); !matched { - es = append(es, fmt.Errorf("%q may only contain alphanumeric characters and dashes and up to 60 characters in length", k)) + errors = append(errors, fmt.Errorf("%q may only contain alphanumeric characters and dashes and up to 60 characters in length", k)) } - return ws, es + return warnings, errors } func flattenAppServiceSiteCredential(input *web.UserProperties) []interface{} { diff --git a/azurerm/resource_arm_app_service_plan.go b/azurerm/resource_arm_app_service_plan.go index 1f210104d2c7..230bb495008c 100644 --- a/azurerm/resource_arm_app_service_plan.go +++ b/azurerm/resource_arm_app_service_plan.go @@ -318,12 +318,12 @@ func flattenAppServiceProperties(props *web.AppServicePlanProperties) []interfac return result } -func validateAppServicePlanName(v interface{}, k string) (ws []string, es []error) { +func validateAppServicePlanName(v interface{}, k string) (warnings []string, errors []error) { value := v.(string) if matched := regexp.MustCompile(`^[0-9a-zA-Z-_]{1,60}$`).Match([]byte(value)); !matched { - es = append(es, fmt.Errorf("%q may only contain alphanumeric characters, dashes and underscores up to 60 characters in length", k)) + errors = append(errors, fmt.Errorf("%q may only contain alphanumeric characters, dashes and underscores up to 60 characters in length", k)) } - return ws, es + return warnings, errors } diff --git a/azurerm/resource_arm_container_registry.go b/azurerm/resource_arm_container_registry.go index d6c2a6ad294c..b36d95c34f4f 100644 --- a/azurerm/resource_arm_container_registry.go +++ b/azurerm/resource_arm_container_registry.go @@ -316,7 +316,7 @@ func resourceArmContainerRegistryDelete(d *schema.ResourceData, meta interface{} return nil } -func validateAzureRMContainerRegistryName(v interface{}, k string) (ws []string, errors []error) { +func validateAzureRMContainerRegistryName(v interface{}, k string) (warnings []string, errors []error) { value := v.(string) if !regexp.MustCompile(`^[a-zA-Z0-9]+$`).MatchString(value) { errors = append(errors, fmt.Errorf( @@ -331,5 +331,5 @@ func validateAzureRMContainerRegistryName(v interface{}, k string) (ws []string, errors = append(errors, fmt.Errorf("%q cannot be longer than 50 characters: %q %d", k, value, len(value))) } - return ws, errors + return warnings, errors } diff --git a/azurerm/resource_arm_container_service.go b/azurerm/resource_arm_container_service.go index 2cd150d1482c..0367d2f5d46e 100644 --- a/azurerm/resource_arm_container_service.go +++ b/azurerm/resource_arm_container_service.go @@ -598,7 +598,7 @@ func resourceAzureRMContainerServiceDiagnosticProfilesHash(v interface{}) int { return hashcode.String(buf.String()) } -func validateArmContainerServiceOrchestrationPlatform(v interface{}, _ string) (ws []string, errors []error) { +func validateArmContainerServiceOrchestrationPlatform(v interface{}, _ string) (warnings []string, errors []error) { value := v.(string) capacities := map[string]bool{ "DCOS": true, @@ -609,10 +609,10 @@ func validateArmContainerServiceOrchestrationPlatform(v interface{}, _ string) ( if !capacities[value] { errors = append(errors, fmt.Errorf("Container Service: Orchestration Platgorm can only be DCOS / Kubernetes / Swarm")) } - return ws, errors + return warnings, errors } -func validateArmContainerServiceMasterProfileCount(v interface{}, _ string) (ws []string, errors []error) { +func validateArmContainerServiceMasterProfileCount(v interface{}, _ string) (warnings []string, errors []error) { value := v.(int) capacities := map[int]bool{ 1: true, @@ -623,13 +623,13 @@ func validateArmContainerServiceMasterProfileCount(v interface{}, _ string) (ws if !capacities[value] { errors = append(errors, fmt.Errorf("The number of master nodes must be 1, 3 or 5.")) } - return ws, errors + return warnings, errors } -func validateArmContainerServiceAgentPoolProfileCount(v interface{}, _ string) (ws []string, errors []error) { +func validateArmContainerServiceAgentPoolProfileCount(v interface{}, _ string) (warnings []string, errors []error) { value := v.(int) if value > 100 || 0 >= value { errors = append(errors, fmt.Errorf("The Count for an Agent Pool Profile can only be between 1 and 100.")) } - return ws, errors + return warnings, errors } diff --git a/azurerm/resource_arm_databricks_workspace.go b/azurerm/resource_arm_databricks_workspace.go index 5ef728cc2cd9..fd0d82e934c5 100644 --- a/azurerm/resource_arm_databricks_workspace.go +++ b/azurerm/resource_arm_databricks_workspace.go @@ -175,17 +175,17 @@ func resourceArmDatabricksWorkspaceDelete(d *schema.ResourceData, meta interface return nil } -func validateDatabricksWorkspaceName(i interface{}, k string) (ws []string, errors []error) { +func validateDatabricksWorkspaceName(i interface{}, k string) (warnings []string, errors []error) { v, ok := i.(string) if !ok { errors = append(errors, fmt.Errorf("expected %q type to be string", k)) - return ws, errors + return warnings, errors } // Cannot be empty if len(v) == 0 { errors = append(errors, fmt.Errorf("%q cannot be an empty string: %q", k, v)) - return ws, errors + return warnings, errors } // First, second, and last characters must be a letter or number with a total length between 3 to 64 characters @@ -201,5 +201,5 @@ func validateDatabricksWorkspaceName(i interface{}, k string) (ws []string, erro errors = append(errors, fmt.Errorf("%q must not contain any consecutive hyphens", k)) } - return ws, errors + return warnings, errors } diff --git a/azurerm/resource_arm_eventhub.go b/azurerm/resource_arm_eventhub.go index cb89eb9a50e8..b7b510de88f7 100644 --- a/azurerm/resource_arm_eventhub.go +++ b/azurerm/resource_arm_eventhub.go @@ -241,27 +241,27 @@ func resourceArmEventHubDelete(d *schema.ResourceData, meta interface{}) error { return nil } -func validateEventHubPartitionCount(v interface{}, _ string) (ws []string, errors []error) { +func validateEventHubPartitionCount(v interface{}, _ string) (warnings []string, errors []error) { value := v.(int) if !(32 >= value && value >= 2) { errors = append(errors, fmt.Errorf("EventHub Partition Count has to be between 2 and 32")) } - return ws, errors + return warnings, errors } -func validateEventHubMessageRetentionCount(v interface{}, _ string) (ws []string, errors []error) { +func validateEventHubMessageRetentionCount(v interface{}, _ string) (warnings []string, errors []error) { value := v.(int) if !(7 >= value && value >= 1) { errors = append(errors, fmt.Errorf("EventHub Retention Count has to be between 1 and 7")) } - return ws, errors + return warnings, errors } -func validateEventHubArchiveNameFormat(v interface{}, k string) (ws []string, errors []error) { +func validateEventHubArchiveNameFormat(v interface{}, k string) (warnings []string, errors []error) { value := v.(string) requiredComponents := []string{ @@ -282,7 +282,7 @@ func validateEventHubArchiveNameFormat(v interface{}, k string) (ws []string, er } } - return ws, errors + return warnings, errors } func expandEventHubCaptureDescription(d *schema.ResourceData) (*eventhub.CaptureDescription, error) { diff --git a/azurerm/resource_arm_firewall.go b/azurerm/resource_arm_firewall.go index 05b8591283a1..e266989a808d 100644 --- a/azurerm/resource_arm_firewall.go +++ b/azurerm/resource_arm_firewall.go @@ -319,14 +319,14 @@ func flattenArmFirewallIPConfigurations(input *[]network.AzureFirewallIPConfigur return result } -func validateAzureFirewallName(v interface{}, k string) (ws []string, es []error) { +func validateAzureFirewallName(v interface{}, k string) (warnings []string, errors []error) { value := v.(string) // From the Portal: // The name must begin with a letter or number, end with a letter, number or underscore, and may contain only letters, numbers, underscores, periods, or hyphens. if matched := regexp.MustCompile(`^[0-9a-zA-Z]([0-9a-zA-Z.\_-]{0,}[0-9a-zA-Z_])?$`).Match([]byte(value)); !matched { - es = append(es, fmt.Errorf("%q must begin with a letter or number, end with a letter, number or underscore, and may contain only letters, numbers, underscores, periods, or hyphens.", k)) + errors = append(errors, fmt.Errorf("%q must begin with a letter or number, end with a letter, number or underscore, and may contain only letters, numbers, underscores, periods, or hyphens.", k)) } - return ws, es + return warnings, errors } diff --git a/azurerm/resource_arm_iothub.go b/azurerm/resource_arm_iothub.go index 223b457d11b1..c55f3ba5481f 100755 --- a/azurerm/resource_arm_iothub.go +++ b/azurerm/resource_arm_iothub.go @@ -727,7 +727,7 @@ func flattenIoTHubRoute(input *devices.RoutingProperties) []interface{} { return results } -func validateIoTHubEndpointName(v interface{}, _ string) (ws []string, errors []error) { +func validateIoTHubEndpointName(v interface{}, _ string) (warnings []string, errors []error) { value := v.(string) reservedNames := []string{ @@ -743,10 +743,10 @@ func validateIoTHubEndpointName(v interface{}, _ string) (ws []string, errors [] } } - return ws, errors + return warnings, errors } -func validateIoTHubFileNameFormat(v interface{}, k string) (ws []string, errors []error) { +func validateIoTHubFileNameFormat(v interface{}, k string) (warnings []string, errors []error) { value := v.(string) requiredComponents := []string{ @@ -765,5 +765,5 @@ func validateIoTHubFileNameFormat(v interface{}, k string) (ws []string, errors } } - return ws, errors + return warnings, errors } diff --git a/azurerm/resource_arm_key_vault.go b/azurerm/resource_arm_key_vault.go index 620fefbe91e4..9d27a2acb1ee 100644 --- a/azurerm/resource_arm_key_vault.go +++ b/azurerm/resource_arm_key_vault.go @@ -429,13 +429,13 @@ func flattenKeyVaultNetworkAcls(input *keyvault.NetworkRuleSet) []interface{} { return []interface{}{output} } -func validateKeyVaultName(v interface{}, k string) (ws []string, errors []error) { +func validateKeyVaultName(v interface{}, k string) (warnings []string, errors []error) { value := v.(string) if matched := regexp.MustCompile(`^[a-zA-Z0-9-]{3,24}$`).Match([]byte(value)); !matched { errors = append(errors, fmt.Errorf("%q may only contain alphanumeric characters and dashes and must be between 3-24 chars", k)) } - return ws, errors + return warnings, errors } func keyVaultRefreshFunc(vaultUri string) resource.StateRefreshFunc { diff --git a/azurerm/resource_arm_loadbalancer_rule.go b/azurerm/resource_arm_loadbalancer_rule.go index 5f1b67a2e6e5..3e01551573cb 100644 --- a/azurerm/resource_arm_loadbalancer_rule.go +++ b/azurerm/resource_arm_loadbalancer_rule.go @@ -363,7 +363,7 @@ func expandAzureRmLoadBalancerRule(d *schema.ResourceData, lb *network.LoadBalan }, nil } -func validateArmLoadBalancerRuleName(v interface{}, k string) (ws []string, errors []error) { +func validateArmLoadBalancerRuleName(v interface{}, k string) (warnings []string, errors []error) { value := v.(string) if !regexp.MustCompile(`^[a-zA-Z_0-9.-]+$`).MatchString(value) { errors = append(errors, fmt.Errorf( @@ -390,5 +390,5 @@ func validateArmLoadBalancerRuleName(v interface{}, k string) (ws []string, erro "%q must start with a word character or number: %q", k, value)) } - return ws, errors + return warnings, errors } diff --git a/azurerm/resource_arm_log_analytics_workspace.go b/azurerm/resource_arm_log_analytics_workspace.go index 0fdf35752505..106f58292755 100644 --- a/azurerm/resource_arm_log_analytics_workspace.go +++ b/azurerm/resource_arm_log_analytics_workspace.go @@ -203,7 +203,7 @@ func resourceArmLogAnalyticsWorkspaceDelete(d *schema.ResourceData, meta interfa return nil } -func validateAzureRmLogAnalyticsWorkspaceName(v interface{}, _ string) (ws []string, errors []error) { +func validateAzureRmLogAnalyticsWorkspaceName(v interface{}, _ string) (warnings []string, errors []error) { value := v.(string) r, _ := regexp.Compile("^[A-Za-z0-9][A-Za-z0-9-]+[A-Za-z0-9]$") @@ -216,5 +216,5 @@ func validateAzureRmLogAnalyticsWorkspaceName(v interface{}, _ string) (ws []str errors = append(errors, fmt.Errorf("Workspace Name can only be between 4 and 63 letters")) } - return ws, errors + return warnings, errors } diff --git a/azurerm/resource_arm_logic_app_trigger_http_request.go b/azurerm/resource_arm_logic_app_trigger_http_request.go index e2af993348ee..891ea851366a 100644 --- a/azurerm/resource_arm_logic_app_trigger_http_request.go +++ b/azurerm/resource_arm_logic_app_trigger_http_request.go @@ -188,7 +188,7 @@ func resourceArmLogicAppTriggerHttpRequestDelete(d *schema.ResourceData, meta in return nil } -func validateLogicAppTriggerHttpRequestRelativePath(v interface{}, _ string) (ws []string, errors []error) { +func validateLogicAppTriggerHttpRequestRelativePath(v interface{}, _ string) (warnings []string, errors []error) { value := v.(string) r, _ := regexp.Compile("^[A-Za-z0-9_/}{]+$") @@ -196,5 +196,5 @@ func validateLogicAppTriggerHttpRequestRelativePath(v interface{}, _ string) (ws errors = append(errors, fmt.Errorf("Relative Path can only contain alphanumeric characters, underscores, forward slashes and curly braces.")) } - return ws, errors + return warnings, errors } diff --git a/azurerm/resource_arm_managed_disk.go b/azurerm/resource_arm_managed_disk.go index 30e6fde9a5f4..8dc9cf40fe94 100644 --- a/azurerm/resource_arm_managed_disk.go +++ b/azurerm/resource_arm_managed_disk.go @@ -103,13 +103,13 @@ func resourceArmManagedDisk() *schema.Resource { } } -func validateDiskSizeGB(v interface{}, _ string) (ws []string, errors []error) { +func validateDiskSizeGB(v interface{}, _ string) (warnings []string, errors []error) { value := v.(int) if value < 0 || value > 4095 { errors = append(errors, fmt.Errorf( "The `disk_size_gb` can only be between 0 and 4095")) } - return ws, errors + return warnings, errors } func resourceArmManagedDiskCreate(d *schema.ResourceData, meta interface{}) error { diff --git a/azurerm/resource_arm_management_lock.go b/azurerm/resource_arm_management_lock.go index c216a3e7cb5a..8bc79582a130 100644 --- a/azurerm/resource_arm_management_lock.go +++ b/azurerm/resource_arm_management_lock.go @@ -160,16 +160,16 @@ func parseAzureRMLockId(id string) (*AzureManagementLockId, error) { return &lockId, nil } -func validateArmManagementLockName(v interface{}, k string) (ws []string, es []error) { +func validateArmManagementLockName(v interface{}, k string) (warnings []string, errors []error) { input := v.(string) if !regexp.MustCompile(`[A-Za-z0-9-_]`).MatchString(input) { - es = append(es, fmt.Errorf("%s can only consist of alphanumeric characters, dashes and underscores", k)) + errors = append(errors, fmt.Errorf("%s can only consist of alphanumeric characters, dashes and underscores", k)) } if len(input) >= 260 { - es = append(es, fmt.Errorf("%s can only be a maximum of 260 characters", k)) + errors = append(errors, fmt.Errorf("%s can only be a maximum of 260 characters", k)) } - return ws, es + return warnings, errors } diff --git a/azurerm/resource_arm_metric_alertrule.go b/azurerm/resource_arm_metric_alertrule.go index 838ab1b96e9d..cc1669fa0115 100644 --- a/azurerm/resource_arm_metric_alertrule.go +++ b/azurerm/resource_arm_metric_alertrule.go @@ -420,17 +420,17 @@ func resourceGroupAndAlertRuleNameFromId(alertRuleId string) (string, string, er return resourceGroup, name, nil } -func validateMetricAlertRuleTags(v interface{}, f string) (ws []string, es []error) { +func validateMetricAlertRuleTags(v interface{}, f string) (warnings []string, errors []error) { // Normal validation required by any AzureRM resource. - ws, es = validateAzureRMTags(v, f) + warnings, errors = validateAzureRMTags(v, f) tagsMap := v.(map[string]interface{}) for k := range tagsMap { if strings.EqualFold(k, "$type") { - es = append(es, fmt.Errorf("the %q is not allowed as tag name", k)) + errors = append(errors, fmt.Errorf("the %q is not allowed as tag name", k)) } } - return ws, es + return warnings, errors } diff --git a/azurerm/resource_arm_redis_cache.go b/azurerm/resource_arm_redis_cache.go index e207b423bbd4..1356957ff743 100644 --- a/azurerm/resource_arm_redis_cache.go +++ b/azurerm/resource_arm_redis_cache.go @@ -653,7 +653,7 @@ func flattenRedisPatchSchedules(schedule redis.PatchSchedule) []interface{} { return outputs } -func validateRedisFamily(v interface{}, _ string) (ws []string, errors []error) { +func validateRedisFamily(v interface{}, _ string) (warnings []string, errors []error) { value := strings.ToLower(v.(string)) families := map[string]bool{ "c": true, @@ -663,10 +663,10 @@ func validateRedisFamily(v interface{}, _ string) (ws []string, errors []error) if !families[value] { errors = append(errors, fmt.Errorf("Redis Family can only be C or P")) } - return ws, errors + return warnings, errors } -func validateRedisMaxMemoryPolicy(v interface{}, _ string) (ws []string, errors []error) { +func validateRedisMaxMemoryPolicy(v interface{}, _ string) (warnings []string, errors []error) { value := strings.ToLower(v.(string)) families := map[string]bool{ "noeviction": true, @@ -681,10 +681,10 @@ func validateRedisMaxMemoryPolicy(v interface{}, _ string) (ws []string, errors errors = append(errors, fmt.Errorf("Redis Max Memory Policy can only be 'noeviction' / 'allkeys-lru' / 'volatile-lru' / 'allkeys-random' / 'volatile-random' / 'volatile-ttl'")) } - return ws, errors + return warnings, errors } -func validateRedisBackupFrequency(v interface{}, _ string) (ws []string, errors []error) { +func validateRedisBackupFrequency(v interface{}, _ string) (warnings []string, errors []error) { value := v.(int) families := map[int]bool{ 15: true, @@ -699,5 +699,5 @@ func validateRedisBackupFrequency(v interface{}, _ string) (ws []string, errors errors = append(errors, fmt.Errorf("Redis Backup Frequency can only be '15', '30', '60', '360', '720' or '1440'")) } - return ws, errors + return warnings, errors } diff --git a/azurerm/resource_arm_redis_firewall_rule.go b/azurerm/resource_arm_redis_firewall_rule.go index 758875b79ad2..d18c5549cfb1 100644 --- a/azurerm/resource_arm_redis_firewall_rule.go +++ b/azurerm/resource_arm_redis_firewall_rule.go @@ -144,12 +144,12 @@ func resourceArmRedisFirewallRuleDelete(d *schema.ResourceData, meta interface{} return nil } -func validateRedisFirewallRuleName(v interface{}, k string) (ws []string, es []error) { +func validateRedisFirewallRuleName(v interface{}, k string) (warnings []string, errors []error) { value := v.(string) if matched := regexp.MustCompile(`^[0-9a-zA-Z]+$`).Match([]byte(value)); !matched { - es = append(es, fmt.Errorf("%q may only contain alphanumeric characters", k)) + errors = append(errors, fmt.Errorf("%q may only contain alphanumeric characters", k)) } - return ws, es + return warnings, errors } diff --git a/azurerm/resource_arm_snapshot.go b/azurerm/resource_arm_snapshot.go index 8f0c042e8c80..d96d79fefa73 100644 --- a/azurerm/resource_arm_snapshot.go +++ b/azurerm/resource_arm_snapshot.go @@ -215,7 +215,7 @@ func resourceArmSnapshotDelete(d *schema.ResourceData, meta interface{}) error { return nil } -func validateSnapshotName(v interface{}, _ string) (ws []string, errors []error) { +func validateSnapshotName(v interface{}, _ string) (warnings []string, errors []error) { // a-z, A-Z, 0-9, _ and -. The max name length is 80 value := v.(string) @@ -229,5 +229,5 @@ func validateSnapshotName(v interface{}, _ string) (ws []string, errors []error) errors = append(errors, fmt.Errorf("Snapshot Name can be up to 80 characters, currently %d.", length)) } - return ws, errors + return warnings, errors } diff --git a/azurerm/resource_arm_sql_virtual_network_rule.go b/azurerm/resource_arm_sql_virtual_network_rule.go index cd7568ed1cef..a7c4eeb7d40b 100644 --- a/azurerm/resource_arm_sql_virtual_network_rule.go +++ b/azurerm/resource_arm_sql_virtual_network_rule.go @@ -175,7 +175,7 @@ func resourceArmSqlVirtualNetworkRuleDelete(d *schema.ResourceData, meta interfa This function checks the format of the SQL Virtual Network Rule Name to make sure that it does not contain any potentially invalid values. */ -func validateSqlVirtualNetworkRuleName(v interface{}, k string) (ws []string, errors []error) { +func validateSqlVirtualNetworkRuleName(v interface{}, k string) (warnings []string, errors []error) { value := v.(string) // Cannot be empty @@ -211,7 +211,7 @@ func validateSqlVirtualNetworkRuleName(v interface{}, k string) (ws []string, er // There are multiple returns in the case that there is more than one invalid // case applied to the name. - return ws, errors + return warnings, errors } /* diff --git a/azurerm/resource_arm_storage_account.go b/azurerm/resource_arm_storage_account.go index b8495897b6cd..ae81cebfde85 100644 --- a/azurerm/resource_arm_storage_account.go +++ b/azurerm/resource_arm_storage_account.go @@ -1,7 +1,6 @@ package azurerm import ( - "errors" "fmt" "log" "regexp" @@ -300,27 +299,27 @@ func resourceArmStorageAccount() *schema.Resource { } } -func validateAzureRMStorageAccountTags(v interface{}, _ string) (ws []string, es []error) { +func validateAzureRMStorageAccountTags(v interface{}, _ string) (warnings []string, errors []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")) + errors = append(errors, fmt.Errorf("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))) + errors = append(errors, 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) + errors = append(errors, 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))) + errors = append(errors, 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 + return warnings, errors } func resourceArmStorageAccountCreate(d *schema.ResourceData, meta interface{}) error { @@ -914,17 +913,17 @@ func flattenStorageAccountBypass(input storage.Bypass) []interface{} { return bypass } -func validateArmStorageAccountName(v interface{}, _ string) (ws []string, es []error) { +func validateArmStorageAccountName(v interface{}, _ string) (warnings []string, errors []error) { input := v.(string) if !regexp.MustCompile(`\A([a-z0-9]{3,24})\z`).MatchString(input) { - es = append(es, fmt.Errorf("name can only consist of lowercase letters and numbers, and must be between 3 and 24 characters long")) + errors = append(errors, fmt.Errorf("name can only consist of lowercase letters and numbers, and must be between 3 and 24 characters long")) } - return ws, es + return warnings, errors } -func validateArmStorageAccountType(v interface{}, _ string) (ws []string, es []error) { +func validateArmStorageAccountType(v interface{}, _ string) (warnings []string, errors []error) { validAccountTypes := []string{"standard_lrs", "standard_zrs", "standard_grs", "standard_ragrs", "premium_lrs"} @@ -936,8 +935,8 @@ func validateArmStorageAccountType(v interface{}, _ string) (ws []string, es []e } } - es = append(es, fmt.Errorf("Invalid storage account type %q", input)) - return ws, es + errors = append(errors, fmt.Errorf("Invalid storage account type %q", input)) + return warnings, errors } func expandAzureRmStorageAccountIdentity(d *schema.ResourceData) *storage.Identity { diff --git a/azurerm/resource_arm_storage_container.go b/azurerm/resource_arm_storage_container.go index d1a3123da0c4..c65b64971d94 100644 --- a/azurerm/resource_arm_storage_container.go +++ b/azurerm/resource_arm_storage_container.go @@ -55,7 +55,7 @@ func resourceArmStorageContainer() *schema.Resource { } //Following the naming convention as laid out in the docs -func validateArmStorageContainerName(v interface{}, k string) (ws []string, errors []error) { +func validateArmStorageContainerName(v interface{}, k string) (warnings []string, errors []error) { value := v.(string) if !regexp.MustCompile(`^\$root$|^[0-9a-z-]+$`).MatchString(value) { errors = append(errors, fmt.Errorf( @@ -70,10 +70,10 @@ func validateArmStorageContainerName(v interface{}, k string) (ws []string, erro errors = append(errors, fmt.Errorf( "%q cannot begin with a hyphen: %q", k, value)) } - return ws, errors + return warnings, errors } -func validateArmStorageContainerAccessType(v interface{}, _ string) (ws []string, errors []error) { +func validateArmStorageContainerAccessType(v interface{}, _ string) (warnings []string, errors []error) { value := strings.ToLower(v.(string)) validTypes := map[string]struct{}{ "private": {}, @@ -84,7 +84,7 @@ func validateArmStorageContainerAccessType(v interface{}, _ string) (ws []string if _, ok := validTypes[value]; !ok { errors = append(errors, fmt.Errorf("Storage container access type %q is invalid, must be %q, %q or %q", value, "private", "blob", "page")) } - return ws, errors + return warnings, errors } func resourceArmStorageContainerCreateUpdate(d *schema.ResourceData, meta interface{}) error { diff --git a/azurerm/resource_arm_storage_queue.go b/azurerm/resource_arm_storage_queue.go index 1e4569c60a56..60c8b326f725 100644 --- a/azurerm/resource_arm_storage_queue.go +++ b/azurerm/resource_arm_storage_queue.go @@ -39,7 +39,7 @@ func resourceArmStorageQueue() *schema.Resource { } } -func validateArmStorageQueueName(v interface{}, k string) (ws []string, errors []error) { +func validateArmStorageQueueName(v interface{}, k string) (warnings []string, errors []error) { value := v.(string) if !regexp.MustCompile(`^[a-z0-9-]+$`).MatchString(value) { @@ -65,7 +65,7 @@ func validateArmStorageQueueName(v interface{}, k string) (ws []string, errors [ "%q must be at least 3 characters", k)) } - return ws, errors + return warnings, errors } func resourceArmStorageQueueCreate(d *schema.ResourceData, meta interface{}) error { diff --git a/azurerm/resource_arm_storage_share.go b/azurerm/resource_arm_storage_share.go index b7b93068ff92..663fe0be27ec 100644 --- a/azurerm/resource_arm_storage_share.go +++ b/azurerm/resource_arm_storage_share.go @@ -213,7 +213,7 @@ func resourceArmStorageShareDelete(d *schema.ResourceData, meta interface{}) err } //Following the naming convention as laid out in the docs https://msdn.microsoft.com/library/azure/dn167011.aspx -func validateArmStorageShareName(v interface{}, k string) (ws []string, errors []error) { +func validateArmStorageShareName(v interface{}, k string) (warnings []string, errors []error) { value := v.(string) if !regexp.MustCompile(`^[0-9a-z-]+$`).MatchString(value) { errors = append(errors, fmt.Errorf( @@ -232,5 +232,5 @@ func validateArmStorageShareName(v interface{}, k string) (ws []string, errors [ errors = append(errors, fmt.Errorf( "%q does not allow consecutive hyphens: %q", k, value)) } - return ws, errors + return warnings, errors } diff --git a/azurerm/resource_arm_storage_table.go b/azurerm/resource_arm_storage_table.go index 8188d2c118db..c669f874025f 100644 --- a/azurerm/resource_arm_storage_table.go +++ b/azurerm/resource_arm_storage_table.go @@ -39,7 +39,7 @@ func resourceArmStorageTable() *schema.Resource { } } -func validateArmStorageTableName(v interface{}, k string) (ws []string, errors []error) { +func validateArmStorageTableName(v interface{}, k string) (warnings []string, errors []error) { value := v.(string) if value == "table" { errors = append(errors, fmt.Errorf( @@ -52,7 +52,7 @@ func validateArmStorageTableName(v interface{}, k string) (ws []string, errors [ k, value)) } - return ws, errors + return warnings, errors } func resourceArmStorageTableCreate(d *schema.ResourceData, meta interface{}) error { diff --git a/azurerm/resource_arm_virtual_network_gateway.go b/azurerm/resource_arm_virtual_network_gateway.go index be6971fe006d..715b065a54df 100644 --- a/azurerm/resource_arm_virtual_network_gateway.go +++ b/azurerm/resource_arm_virtual_network_gateway.go @@ -711,30 +711,30 @@ func resourceGroupAndVirtualNetworkGatewayFromId(virtualNetworkGatewayId string) return resGroup, name, nil } -func validateArmVirtualNetworkGatewaySubnetId(i interface{}, k string) (s []string, es []error) { +func validateArmVirtualNetworkGatewaySubnetId(i interface{}, k string) (warnings []string, errors []error) { value, ok := i.(string) if !ok { - es = append(es, fmt.Errorf("expected type of %s to be string", k)) + errors = append(errors, fmt.Errorf("expected type of %s to be string", k)) return } id, err := parseAzureResourceID(value) if err != nil { - es = append(es, fmt.Errorf("expected %s to be an Azure resource id", k)) + errors = append(errors, fmt.Errorf("expected %s to be an Azure resource id", k)) return } subnet, ok := id.Path["subnets"] if !ok { - es = append(es, fmt.Errorf("expected %s to reference a subnet resource", k)) + errors = append(errors, fmt.Errorf("expected %s to reference a subnet resource", k)) return } if strings.ToLower(subnet) != "gatewaysubnet" { - es = append(es, fmt.Errorf("expected %s to reference a gateway subnet with name GatewaySubnet", k)) + errors = append(errors, fmt.Errorf("expected %s to reference a gateway subnet with name GatewaySubnet", k)) } - return s, es + return warnings, errors } func validateArmVirtualNetworkGatewayPolicyBasedVpnSku() schema.SchemaValidateFunc { diff --git a/azurerm/tags.go b/azurerm/tags.go index 20d27a741abf..1cfc33a7ff6c 100644 --- a/azurerm/tags.go +++ b/azurerm/tags.go @@ -1,7 +1,6 @@ package azurerm import ( - "errors" "fmt" "strings" @@ -45,27 +44,27 @@ func tagValueToString(v interface{}) (string, error) { } } -func validateAzureRMTags(v interface{}, _ string) (ws []string, es []error) { +func validateAzureRMTags(v interface{}, _ string) (warnings []string, errors []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")) + errors = append(errors, fmt.Errorf("a maximum of 15 tags can be applied to each ARM resource")) } for k, v := range tagsMap { if len(k) > 512 { - es = append(es, fmt.Errorf("the maximum length for a tag key is 512 characters: %q is %d characters", k, len(k))) + errors = append(errors, fmt.Errorf("the maximum length for a tag key is 512 characters: %q is %d characters", k, len(k))) } value, err := tagValueToString(v) if err != nil { - es = append(es, err) + errors = append(errors, 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))) + errors = append(errors, 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 + return warnings, errors } func expandTags(tagsMap map[string]interface{}) map[string]*string { diff --git a/azurerm/validators.go b/azurerm/validators.go index 6190fddd53ba..3b99d746adb5 100644 --- a/azurerm/validators.go +++ b/azurerm/validators.go @@ -12,47 +12,52 @@ import ( "github.com/satori/uuid" ) -func validateRFC3339Date(v interface{}, k string) (ws []string, errors []error) { +func validateRFC3339Date(v interface{}, k string) (warnings []string, errors []error) { dateString := v.(string) if _, err := date.ParseTime(time.RFC3339, dateString); err != nil { errors = append(errors, fmt.Errorf("%q is an invalid RFC3339 date: %+v", k, err)) } - return ws, errors + return warnings, errors } -func validateUUID(v interface{}, k string) (ws []string, errors []error) { +func validateUUID(v interface{}, k string) (warnings []string, errors []error) { if _, err := uuid.FromString(v.(string)); err != nil { errors = append(errors, fmt.Errorf("%q is an invalid UUUID: %s", k, err)) } - return ws, errors + return warnings, errors } func evaluateSchemaValidateFunc(i interface{}, k string, validateFunc schema.SchemaValidateFunc) (bool, error) { // nolint: unparam - _, es := validateFunc(i, k) + _, errors := validateFunc(i, k) - if len(es) > 0 { - return false, es[0] + errorStrings := []string{} + for _, e := range errors { + errorStrings = append(errorStrings, e.Error()) + } + + if len(errors) > 0 { + return false, fmt.Errorf(strings.Join(errorStrings, "\n")) } return true, nil } func validateIso8601Duration() schema.SchemaValidateFunc { - return func(i interface{}, k string) (s []string, es []error) { + return func(i interface{}, k string) (warnings []string, errors []error) { v, ok := i.(string) if !ok { - es = append(es, fmt.Errorf("expected type of %s to be string", k)) + errors = append(errors, fmt.Errorf("expected type of %s to be string", k)) return } matched, _ := regexp.MatchString(`^P([0-9]+Y)?([0-9]+M)?([0-9]+W)?([0-9]+D)?(T([0-9]+H)?([0-9]+M)?([0-9]+(\.?[0-9]+)?S)?)?$`, v) if !matched { - es = append(es, fmt.Errorf("expected %s to be in ISO 8601 duration format, got %s", k, v)) + errors = append(errors, fmt.Errorf("expected %s to be in ISO 8601 duration format, got %s", k, v)) } - return s, es + return warnings, errors } } @@ -171,32 +176,32 @@ func validateAzureVirtualMachineTimeZone() schema.SchemaValidateFunc { } func validateCollation() schema.SchemaValidateFunc { - return func(i interface{}, k string) (s []string, es []error) { + return func(i interface{}, k string) (warnings []string, errors []error) { v, ok := i.(string) if !ok { - es = append(es, fmt.Errorf("expected type of %s to be string", k)) + errors = append(errors, fmt.Errorf("expected type of %s to be string", k)) return } matched, _ := regexp.MatchString(`^[A-Za-z0-9_. ]+$`, v) if !matched { - es = append(es, fmt.Errorf("%s contains invalid characters, only underscores are supported, got %s", k, v)) + errors = append(errors, fmt.Errorf("%s contains invalid characters, only underscores are supported, got %s", k, v)) return } - return s, es + return warnings, errors } } func validateFilePath() schema.SchemaValidateFunc { - return func(v interface{}, k string) (ws []string, es []error) { + return func(v interface{}, k string) (warnings []string, errors []error) { val := v.(string) if !strings.HasPrefix(val, "/") { - es = append(es, fmt.Errorf("%q must start with `/`", k)) + errors = append(errors, fmt.Errorf("%q must start with `/`", k)) } - return ws, es + return warnings, errors } }