diff --git a/go.mod b/go.mod index b4bda6dee8f..0f653df0380 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/hashicorp/go-cleanhttp v0.5.1 github.com/hashicorp/go-multierror v1.0.0 github.com/hashicorp/go-version v1.2.0 - github.com/hashicorp/terraform-plugin-sdk v1.5.0 + github.com/hashicorp/terraform-plugin-sdk v1.6.0 github.com/hashicorp/vault v0.10.4 github.com/jen20/awspolicyequivalence v1.1.0 github.com/json-iterator/go v1.1.8 // indirect diff --git a/go.sum b/go.sum index af58a2f0eb6..3b797dcc579 100644 --- a/go.sum +++ b/go.sum @@ -247,8 +247,8 @@ github.com/hashicorp/terraform-json v0.3.1 h1:vRiOLck4YX4UqzljVhdQKsVLixX4L+Pgnm github.com/hashicorp/terraform-json v0.3.1/go.mod h1:MdwQStcJb00ht55L/2YH0ypAO9RNtczJ1MaUlf+gJcg= github.com/hashicorp/terraform-plugin-sdk v1.4.1 h1:REgN6WbySD6aIYdF6Uob3ic4eQkfh4NXSWU/casmgb4= github.com/hashicorp/terraform-plugin-sdk v1.4.1/go.mod h1:H5QLx/uhwfxBZ59Bc5SqT19M4i+fYt7LZjHTpbLZiAg= -github.com/hashicorp/terraform-plugin-sdk v1.5.0 h1:hzac/oigJkGup0kI+PwBGI4/fvG7Na8kM8j9xCBrmWo= -github.com/hashicorp/terraform-plugin-sdk v1.5.0/go.mod h1:H5QLx/uhwfxBZ59Bc5SqT19M4i+fYt7LZjHTpbLZiAg= +github.com/hashicorp/terraform-plugin-sdk v1.6.0 h1:Um5hsAL7kKsfTHtan8lybY/d03F2bHu4fjRB1H6Ag4U= +github.com/hashicorp/terraform-plugin-sdk v1.6.0/go.mod h1:H5QLx/uhwfxBZ59Bc5SqT19M4i+fYt7LZjHTpbLZiAg= github.com/hashicorp/terraform-svchost v0.0.0-20191011084731-65d371908596 h1:hjyO2JsNZUKT1ym+FAdlBEkGPevazYsmVgIMw7dVELg= github.com/hashicorp/terraform-svchost v0.0.0-20191011084731-65d371908596/go.mod h1:kNDNcF7sN4DocDLBkQYz73HGKwN1ANB1blq4lIYLYvg= github.com/hashicorp/vault v0.10.4 h1:4x0lHxui/ZRp/B3E0Auv1QNBJpzETqHR2kQD3mHSBJU= diff --git a/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/validation/int.go b/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/validation/int.go index 54b082feb16..8ade5b1e689 100644 --- a/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/validation/int.go +++ b/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/validation/int.go @@ -2,6 +2,7 @@ package validation import ( "fmt" + "math" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) @@ -9,77 +10,116 @@ import ( // IntBetween returns a SchemaValidateFunc which tests if the provided value // is of type int and is between min and max (inclusive) func IntBetween(min, max 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)) - return + errors = append(errors, fmt.Errorf("expected type of %s to be integer", k)) + return warnings, errors } 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)) - return + errors = append(errors, fmt.Errorf("expected %s to be in the range (%d - %d), got %d", k, min, max, v)) + return warnings, errors } - return + return warnings, errors } } // IntAtLeast returns a SchemaValidateFunc which tests if the provided value // is of type int and is at least min (inclusive) func IntAtLeast(min 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)) - return + errors = append(errors, fmt.Errorf("expected type of %s to be integer", k)) + return warnings, errors } if v < min { - es = append(es, fmt.Errorf("expected %s to be at least (%d), got %d", k, min, v)) - return + errors = append(errors, fmt.Errorf("expected %s to be at least (%d), got %d", k, min, v)) + return warnings, errors } - return + return warnings, errors } } // IntAtMost returns a SchemaValidateFunc which tests if the provided value // is of type int and is at most max (inclusive) func IntAtMost(max 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)) - return + errors = append(errors, fmt.Errorf("expected type of %s to be integer", k)) + return warnings, errors } if v > max { - es = append(es, fmt.Errorf("expected %s to be at most (%d), got %d", k, max, v)) - return + errors = append(errors, fmt.Errorf("expected %s to be at most (%d), got %d", k, max, v)) + return warnings, errors } - return + 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 { + return func(i interface{}, k string) (warnings []string, errors []error) { + v, ok := i.(int) + if !ok { + errors = append(errors, fmt.Errorf("expected type of %s to be integer", k)) + return warnings, errors + } + + if math.Mod(float64(v), float64(divisor)) != 0 { + errors = append(errors, fmt.Errorf("expected %s to be divisible by %d, got: %v", k, divisor, i)) + return warnings, errors + } + + 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 { + errors = append(errors, fmt.Errorf("expected type of %s to be integer", k)) + return warnings, errors + } + + for _, validInt := range valid { + if v == validInt { + return warnings, errors + } + } + + errors = append(errors, fmt.Errorf("expected %s to be one of %v, got %d", k, valid, v)) + return warnings, errors + } +} + +// IntNotInSlice 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 IntNotInSlice(valid []int) schema.SchemaValidateFunc { + 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 an integer", k)) - return + errors = append(errors, fmt.Errorf("expected type of %s to be integer", k)) + return warnings, errors } for _, validInt := range valid { if v == validInt { - return + errors = append(errors, fmt.Errorf("expected %s to not be one of %v, got %d", k, valid, v)) } } - es = append(es, fmt.Errorf("expected %s to be one of %v, got %d", k, valid, v)) - return + return warnings, errors } } diff --git a/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/validation/list.go b/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/validation/list.go new file mode 100644 index 00000000000..d60a4882f2d --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/validation/list.go @@ -0,0 +1,41 @@ +package validation + +import "fmt" + +// ValidateListUniqueStrings is a ValidateFunc that ensures a list has no +// duplicate items in it. It's useful for when a list is needed over a set +// because order matters, yet the items still need to be unique. +// +// Deprecated: use ListOfUniqueStrings +func ValidateListUniqueStrings(i interface{}, k string) (warnings []string, errors []error) { + return ListOfUniqueStrings(i, k) +} + +// ListOfUniqueStrings is a ValidateFunc that ensures a list has no +// duplicate items in it. It's useful for when a list is needed over a set +// because order matters, yet the items still need to be unique. +func ListOfUniqueStrings(i interface{}, k string) (warnings []string, errors []error) { + v, ok := i.([]interface{}) + if !ok { + errors = append(errors, fmt.Errorf("expected type of %q to be List", k)) + return warnings, errors + } + + for _, e := range v { + if _, eok := e.(string); !eok { + errors = append(errors, fmt.Errorf("expected %q to only contain string elements, found :%v", k, e)) + return warnings, errors + } + } + + for n1, i1 := range v { + for n2, i2 := range v { + if i1.(string) == i2.(string) && n1 != n2 { + errors = append(errors, fmt.Errorf("expected %q to not have duplicates: found 2 or more of %v", k, i1)) + return warnings, errors + } + } + } + + return warnings, errors +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/validation/meta.go b/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/validation/meta.go index e2948ace2ef..b05557ac2a6 100644 --- a/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/validation/meta.go +++ b/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/validation/meta.go @@ -14,9 +14,9 @@ func NoZeroValues(i interface{}, k string) (s []string, es []error) { if reflect.ValueOf(i).Interface() == reflect.Zero(reflect.TypeOf(i)).Interface() { switch reflect.TypeOf(i).Kind() { case reflect.String: - es = append(es, fmt.Errorf("%s must not be empty", k)) + es = append(es, fmt.Errorf("%s must not be empty, got %v", k, i)) case reflect.Int, reflect.Float64: - es = append(es, fmt.Errorf("%s must not be zero", k)) + es = append(es, fmt.Errorf("%s must not be zero, got %v", k, i)) default: // this validator should only ever be applied to TypeString, TypeInt and TypeFloat panic(fmt.Errorf("can't use NoZeroValues with %T attribute %s", i, k)) diff --git a/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/validation/network.go b/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/validation/network.go index a53725a2996..4fea7179878 100644 --- a/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/validation/network.go +++ b/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/validation/network.go @@ -9,81 +9,186 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) +// SingleIP returns a SchemaValidateFunc which tests if the provided value +// is of type string, and in valid single Value notation +// +// Deprecated: use IsIPAddress instead +func SingleIP() schema.SchemaValidateFunc { + return IsIPAddress +} + +// IsIPAddress is a SchemaValidateFunc which tests if the provided value is of type string and is a single IP (v4 or v6) +func IsIPAddress(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)) + return warnings, errors + } + + ip := net.ParseIP(v) + if ip == nil { + errors = append(errors, fmt.Errorf("expected %s to contain a valid IP, got: %s", k, v)) + } + + return warnings, errors +} + +// IsIPv6Address is a SchemaValidateFunc which tests if the provided value is of type string and a valid IPv6 address +func IsIPv6Address(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)) + return warnings, errors + } + + ip := net.ParseIP(v) + if six := ip.To16(); six == nil { + errors = append(errors, fmt.Errorf("expected %s to contain a valid IPv6 address, got: %s", k, v)) + } + + return warnings, errors +} + +// IsIPv4Address is a SchemaValidateFunc which tests if the provided value is of type string and a valid IPv4 address +func IsIPv4Address(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)) + return warnings, errors + } + + ip := net.ParseIP(v) + if four := ip.To4(); four == nil { + errors = append(errors, fmt.Errorf("expected %s to contain a valid IPv4 address, got: %s", k, v)) + } + + return warnings, errors +} + +// IPRange returns a SchemaValidateFunc which tests if the provided value is of type string, and in valid IP range +// +// Deprecated: use IsIPv4Range instead +func IPRange() schema.SchemaValidateFunc { + return IsIPv4Range +} + +// IsIPv4Range is a SchemaValidateFunc which tests if the provided value is of type string, and in valid IP range +func IsIPv4Range(i interface{}, k string) (warnings []string, errors []error) { + v, ok := i.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected type of %s to be string", k)) + return warnings, errors + } + + ips := strings.Split(v, "-") + if len(ips) != 2 { + errors = append(errors, fmt.Errorf("expected %s to contain a valid IP range, got: %s", k, v)) + return warnings, errors + } + + ip1 := net.ParseIP(ips[0]) + ip2 := net.ParseIP(ips[1]) + if ip1 == nil || ip2 == nil || bytes.Compare(ip1, ip2) > 0 { + errors = append(errors, fmt.Errorf("expected %s to contain a valid IP range, got: %s", k, v)) + } + + return warnings, errors +} + +// IsCIDR is a SchemaValidateFunc which tests if the provided value is of type string and a valid CIDR +func IsCIDR(i interface{}, k string) (warnings []string, errors []error) { + v, ok := i.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected type of %s to be string", k)) + return warnings, errors + } + + if _, _, err := net.ParseCIDR(v); err != nil { + errors = append(errors, fmt.Errorf("expected %q to be a valid IPv4 Value, got %v: %v", k, i, err)) + } + + return warnings, errors +} + // CIDRNetwork returns a SchemaValidateFunc which tests if the provided value -// is of type string, is in valid CIDR network notation, and has significant bits between min and max (inclusive) +// is of type string, is in valid Value network notation, and has significant bits between min and max (inclusive) +// +// Deprecated: use IsCIDRNetwork instead func CIDRNetwork(min, max int) schema.SchemaValidateFunc { - return func(i interface{}, k string) (s []string, es []error) { + return IsCIDRNetwork(min, max) +} + +// IsCIDRNetwork returns a SchemaValidateFunc which tests if the provided value +// is of type string, is in valid Value network notation, and has significant bits between min and max (inclusive) +func IsCIDRNetwork(min, max int) schema.SchemaValidateFunc { + 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)) - return + errors = append(errors, fmt.Errorf("expected type of %s to be string", k)) + return warnings, errors } _, ipnet, err := net.ParseCIDR(v) if err != nil { - es = append(es, fmt.Errorf( - "expected %s to contain a valid CIDR, got: %s with err: %s", k, v, err)) - return + errors = append(errors, fmt.Errorf("expected %s to contain a valid Value, got: %s with err: %s", k, v, err)) + return warnings, errors } if ipnet == nil || v != ipnet.String() { - es = append(es, fmt.Errorf( - "expected %s to contain a valid network CIDR, expected %s, got %s", + errors = append(errors, fmt.Errorf("expected %s to contain a valid network Value, expected %s, got %s", k, ipnet, v)) } sigbits, _ := ipnet.Mask.Size() if sigbits < min || sigbits > max { - es = append(es, fmt.Errorf( - "expected %q to contain a network CIDR with between %d and %d significant bits, got: %d", - k, min, max, sigbits)) + errors = append(errors, fmt.Errorf("expected %q to contain a network Value with between %d and %d significant bits, got: %d", k, min, max, sigbits)) } - return + return warnings, errors } } -// SingleIP returns a SchemaValidateFunc which tests if the provided value -// is of type string, and in valid single IP notation -func SingleIP() schema.SchemaValidateFunc { - return func(i interface{}, k string) (s []string, es []error) { - v, ok := i.(string) - if !ok { - es = append(es, fmt.Errorf("expected type of %s to be string", k)) - return - } +// IsMACAddress is a SchemaValidateFunc which tests if the provided value is of type string and a valid MAC address +func IsMACAddress(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)) + return warnings, errors + } - ip := net.ParseIP(v) - if ip == nil { - es = append(es, fmt.Errorf( - "expected %s to contain a valid IP, got: %s", k, v)) - } - return + if _, err := net.ParseMAC(v); err != nil { + errors = append(errors, fmt.Errorf("expected %q to be a valid MAC address, got %v: %v", k, i, err)) } + + return warnings, errors } -// IPRange returns a SchemaValidateFunc which tests if the provided value -// is of type string, and in valid IP range notation -func IPRange() schema.SchemaValidateFunc { - return func(i interface{}, k string) (s []string, es []error) { - v, ok := i.(string) - if !ok { - es = append(es, fmt.Errorf("expected type of %s to be string", k)) - return - } +// IsPortNumber is a SchemaValidateFunc which tests if the provided value is of type string and a valid TCP Port Number +func IsPortNumber(i interface{}, k string) (warnings []string, errors []error) { + v, ok := i.(int) + if !ok { + errors = append(errors, fmt.Errorf("expected type of %q to be integer", k)) + return warnings, errors + } - ips := strings.Split(v, "-") - if len(ips) != 2 { - es = append(es, fmt.Errorf( - "expected %s to contain a valid IP range, got: %s", k, v)) - return - } - ip1 := net.ParseIP(ips[0]) - ip2 := net.ParseIP(ips[1]) - if ip1 == nil || ip2 == nil || bytes.Compare(ip1, ip2) > 0 { - es = append(es, fmt.Errorf( - "expected %s to contain a valid IP range, got: %s", k, v)) - } - return + if 1 > v || v > 65535 { + errors = append(errors, fmt.Errorf("expected %q to be a valid port number, got: %v", k, v)) } + + return warnings, errors +} + +// IsPortNumberOrZero is a SchemaValidateFunc which tests if the provided value is of type string and a valid TCP Port Number or zero +func IsPortNumberOrZero(i interface{}, k string) (warnings []string, errors []error) { + v, ok := i.(int) + if !ok { + errors = append(errors, fmt.Errorf("expected type of %q to be integer", k)) + return warnings, errors + } + + if 0 > v || v > 65535 { + errors = append(errors, fmt.Errorf("expected %q to be a valid port number or 0, got: %v", k, v)) + } + + return warnings, errors } diff --git a/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/validation/strings.go b/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/validation/strings.go index 067b77d11a5..a5bfb6bea54 100644 --- a/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/validation/strings.go +++ b/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/validation/strings.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/structure" ) -// StringIsNotEmpty is a ValidateFunc that ensures a string is not empty or consisting entirely of whitespace characters +// StringIsNotEmpty is a ValidateFunc that ensures a string is not empty func StringIsNotEmpty(i interface{}, k string) ([]string, []error) { v, ok := i.(string) if !ok { @@ -18,13 +18,13 @@ func StringIsNotEmpty(i interface{}, k string) ([]string, []error) { } if v == "" { - return nil, []error{fmt.Errorf("expected %q to not be an empty string", k)} + return nil, []error{fmt.Errorf("expected %q to not be an empty string, got %v", k, i)} } return nil, nil } -// StringIsNotEmpty is a ValidateFunc that ensures a string is not empty or consisting entirely of whitespace characters +// StringIsNotWhiteSpace is a ValidateFunc that ensures a string is not empty or consisting entirely of whitespace characters func StringIsNotWhiteSpace(i interface{}, k string) ([]string, []error) { v, ok := i.(string) if !ok { @@ -52,7 +52,7 @@ func StringIsEmpty(i interface{}, k string) ([]string, []error) { return nil, nil } -// StringIsEmpty is a ValidateFunc that ensures a string is composed of entirely whitespace +// StringIsWhiteSpace is a ValidateFunc that ensures a string is composed of entirely whitespace func StringIsWhiteSpace(i interface{}, k string) ([]string, []error) { v, ok := i.(string) if !ok { @@ -69,16 +69,18 @@ func StringIsWhiteSpace(i interface{}, k string) ([]string, []error) { // StringLenBetween returns a SchemaValidateFunc which tests if the provided value // is of type string and has length between min and max (inclusive) func StringLenBetween(min, max 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.(string) if !ok { - es = append(es, fmt.Errorf("expected type of %s to be string", k)) - return + errors = append(errors, fmt.Errorf("expected type of %s to be string", k)) + return warnings, errors } + if len(v) < min || len(v) > max { - es = append(es, fmt.Errorf("expected length of %s to be in the range (%d - %d), got %s", k, min, max, v)) + errors = append(errors, fmt.Errorf("expected length of %s to be in the range (%d - %d), got %s", k, min, max, v)) } - return + + return warnings, errors } } @@ -97,7 +99,7 @@ func StringMatch(r *regexp.Regexp, message string) schema.SchemaValidateFunc { return nil, []error{fmt.Errorf("invalid value for %s (%s)", k, message)} } - return nil, []error{fmt.Errorf("expected value of %s to match regular expression %q", k, r)} + return nil, []error{fmt.Errorf("expected value of %s to match regular expression %q, got %v", k, r, i)} } return nil, nil } @@ -118,7 +120,7 @@ func StringDoesNotMatch(r *regexp.Regexp, message string) schema.SchemaValidateF return nil, []error{fmt.Errorf("invalid value for %s (%s)", k, message)} } - return nil, []error{fmt.Errorf("expected value of %s to not match regular expression %q", k, r)} + return nil, []error{fmt.Errorf("expected value of %s to not match regular expression %q, got %v", k, r, i)} } return nil, nil } @@ -128,40 +130,40 @@ func StringDoesNotMatch(r *regexp.Regexp, message string) schema.SchemaValidateF // is of type string and matches the value of an element in the valid slice // will test with in lower case if ignoreCase is true func StringInSlice(valid []string, ignoreCase bool) 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)) - return + errors = append(errors, fmt.Errorf("expected type of %s to be string", k)) + return warnings, errors } for _, str := range valid { if v == str || (ignoreCase && strings.ToLower(v) == strings.ToLower(str)) { - return + return warnings, errors } } - es = append(es, fmt.Errorf("expected %s to be one of %v, got %s", k, valid, v)) - return + errors = append(errors, fmt.Errorf("expected %s to be one of %v, got %s", k, valid, v)) + return warnings, errors } } // StringDoesNotContainAny returns a SchemaValidateFunc which validates that the // provided value does not contain any of the specified Unicode code points in chars. func StringDoesNotContainAny(chars string) 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)) - return + errors = append(errors, fmt.Errorf("expected type of %s to be string", k)) + return warnings, errors } if strings.ContainsAny(v, chars) { - es = append(es, fmt.Errorf("expected value of %s to not contain any of %q", k, chars)) - return + errors = append(errors, fmt.Errorf("expected value of %s to not contain any of %q, got %v", k, chars, i)) + return warnings, errors } - return + return warnings, errors } } @@ -174,41 +176,56 @@ func StringIsBase64(i interface{}, k string) (warnings []string, errors []error) // NoEmptyStrings checks it is a string v, _ := i.(string) + if _, err := base64.StdEncoding.DecodeString(v); err != nil { errors = append(errors, fmt.Errorf("expected %q to be a base64 string, got %v", k, v)) } - return -} - -// ValidateListUniqueStrings is a ValidateFunc that ensures a list has no -// duplicate items in it. It's useful for when a list is needed over a set -// because order matters, yet the items still need to be unique. -func ValidateListUniqueStrings(v interface{}, k string) (ws []string, errors []error) { - for n1, v1 := range v.([]interface{}) { - for n2, v2 := range v.([]interface{}) { - if v1.(string) == v2.(string) && n1 != n2 { - errors = append(errors, fmt.Errorf("%q: duplicate entry - %s", k, v1.(string))) - } - } - } - return + return warnings, errors } // ValidateJsonString is a SchemaValidateFunc which tests to make sure the // supplied string is valid JSON. -func ValidateJsonString(v interface{}, k string) (ws []string, errors []error) { +// +// Deprecated: use StringIsJSON instead +func ValidateJsonString(i interface{}, k string) (warnings []string, errors []error) { + return StringIsJSON(i, k) +} + +// StringIsJSON is a SchemaValidateFunc which tests to make sure the supplied string is valid JSON. +func StringIsJSON(i interface{}, k string) (warnings []string, errors []error) { + v, ok := i.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected type of %s to be string", k)) + return warnings, errors + } + if _, err := structure.NormalizeJsonString(v); err != nil { errors = append(errors, fmt.Errorf("%q contains an invalid JSON: %s", k, err)) } - return + + return warnings, errors } // ValidateRegexp returns a SchemaValidateFunc which tests to make sure the // supplied string is a valid regular expression. -func ValidateRegexp(v interface{}, k string) (ws []string, errors []error) { - if _, err := regexp.Compile(v.(string)); err != nil { +// +// Deprecated: use StringIsValidRegExp instead +func ValidateRegexp(i interface{}, k string) (warnings []string, errors []error) { + return StringIsValidRegExp(i, k) +} + +// StringIsValidRegExp returns a SchemaValidateFunc which tests to make sure the supplied string is a valid regular expression. +func StringIsValidRegExp(i interface{}, k string) (warnings []string, errors []error) { + v, ok := i.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected type of %s to be string", k)) + return warnings, errors + } + + if _, err := regexp.Compile(v); err != nil { errors = append(errors, fmt.Errorf("%q: %s", k, err)) } - return + + return warnings, errors } diff --git a/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/validation/time.go b/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/validation/time.go index 30010ceb91d..1c6788c68fe 100644 --- a/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/validation/time.go +++ b/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/validation/time.go @@ -3,13 +3,59 @@ package validation import ( "fmt" "time" + + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" ) -// ValidateRFC3339TimeString is a ValidateFunc that ensures a string parses -// as time.RFC3339 format -func ValidateRFC3339TimeString(v interface{}, k string) (ws []string, errors []error) { - if _, err := time.Parse(time.RFC3339, v.(string)); err != nil { - errors = append(errors, fmt.Errorf("%q: invalid RFC3339 timestamp", k)) +// IsDayOfTheWeek id a SchemaValidateFunc which tests if the provided value is of type string and a valid english day of the week +func IsDayOfTheWeek(ignoreCase bool) schema.SchemaValidateFunc { + return StringInSlice([]string{ + "Monday", + "Tuesday", + "Wednesday", + "Thursday", + "Friday", + "Saturday", + "Sunday", + }, ignoreCase) +} + +// IsMonth id a SchemaValidateFunc which tests if the provided value is of type string and a valid english month +func IsMonth(ignoreCase bool) schema.SchemaValidateFunc { + return StringInSlice([]string{ + "January", + "February", + "March", + "April", + "May", + "June", + "July", + "August", + "September", + "October", + "November", + "December", + }, ignoreCase) +} + +// IsRFC3339Time is a SchemaValidateFunc which tests if the provided value is of type string and a valid RFC33349Time +func IsRFC3339Time(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)) + return warnings, errors } - return + + if _, err := time.Parse(time.RFC3339, v); err != nil { + errors = append(errors, fmt.Errorf("expected %q to be a valid RFC3339 date, got %q: %+v", k, i, err)) + } + + return warnings, errors +} + +// ValidateRFC3339TimeString is a ValidateFunc that ensures a string parses as time.RFC3339 format +// +// Deprecated: use IsRFC3339Time() instead +func ValidateRFC3339TimeString(i interface{}, k string) (warnings []string, errors []error) { + return IsRFC3339Time(i, k) } diff --git a/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/validation/web.go b/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/validation/web.go new file mode 100644 index 00000000000..eb5437f14bf --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/validation/web.go @@ -0,0 +1,55 @@ +package validation + +import ( + "fmt" + "net/url" + "strings" + + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" +) + +// IsURLWithHTTPS is a SchemaValidateFunc which tests if the provided value is of type string and a valid HTTPS URL +func IsURLWithHTTPS(i interface{}, k string) (_ []string, errors []error) { + return IsURLWithScheme([]string{"https"})(i, k) +} + +// IsURLWithHTTPorHTTPS is a SchemaValidateFunc which tests if the provided value is of type string and a valid HTTP or HTTPS URL +func IsURLWithHTTPorHTTPS(i interface{}, k string) (_ []string, errors []error) { + return IsURLWithScheme([]string{"http", "https"})(i, k) +} + +// IsURLWithScheme is a SchemaValidateFunc which tests if the provided value is of type string and a valid URL with the provided schemas +func IsURLWithScheme(validSchemes []string) schema.SchemaValidateFunc { + return func(i interface{}, k string) (_ []string, errors []error) { + v, ok := i.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected type of %q to be string", k)) + return + } + + if v == "" { + errors = append(errors, fmt.Errorf("expected %q url to not be empty, got %v", k, i)) + return + } + + u, err := url.Parse(v) + if err != nil { + errors = append(errors, fmt.Errorf("expected %q to be a valid url, got %v: %+v", k, v, err)) + return + } + + if u.Host == "" { + errors = append(errors, fmt.Errorf("expected %q to have a host, got %v", k, v)) + return + } + + for _, s := range validSchemes { + if u.Scheme == s { + return //last check so just return + } + } + + errors = append(errors, fmt.Errorf("expected %q to have a url with schema of: %q, got %v", k, strings.Join(validSchemes, ","), v)) + return + } +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-sdk/meta/meta.go b/vendor/github.com/hashicorp/terraform-plugin-sdk/meta/meta.go index 4dff34b1c36..e64e224b156 100644 --- a/vendor/github.com/hashicorp/terraform-plugin-sdk/meta/meta.go +++ b/vendor/github.com/hashicorp/terraform-plugin-sdk/meta/meta.go @@ -11,7 +11,7 @@ import ( ) // The main version number that is being run at the moment. -var SDKVersion = "1.5.0" +var SDKVersion = "1.6.0" // A pre-release marker for the version. If this is "" (empty string) // then it means that it is a final release. Otherwise, this is a pre-release diff --git a/vendor/modules.txt b/vendor/modules.txt index 6b51a2e987a..e07317474de 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -451,7 +451,7 @@ github.com/hashicorp/logutils github.com/hashicorp/terraform-config-inspect/tfconfig # github.com/hashicorp/terraform-json v0.3.1 github.com/hashicorp/terraform-json -# github.com/hashicorp/terraform-plugin-sdk v1.5.0 +# github.com/hashicorp/terraform-plugin-sdk v1.6.0 github.com/hashicorp/terraform-plugin-sdk/helper/acctest github.com/hashicorp/terraform-plugin-sdk/helper/customdiff github.com/hashicorp/terraform-plugin-sdk/helper/encryption