use validation helper

This commit is contained in:
ebilhoo 2017-04-25 20:06:33 +00:00
parent 0cf9dbcfb4
commit 87db8b3b43
1 changed files with 9 additions and 20 deletions

View File

@ -7,6 +7,7 @@ import (
"github.com/Ensighten/udnssdk" "github.com/Ensighten/udnssdk"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
) )
func resourceUltradnsRdpool() *schema.Resource { func resourceUltradnsRdpool() *schema.Resource {
@ -39,28 +40,16 @@ func resourceUltradnsRdpool() *schema.Resource {
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
Default: "ROUND_ROBIN", Default: "ROUND_ROBIN",
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) { ValidateFunc: validation.StringInSlice([]string{
value := v.(string) "ROUND_ROBIN",
if value != "ROUND_ROBIN" && value != "FIXED" && value != "RANDOM" { "FIXED",
errors = append(errors, fmt.Errorf( "RANDOM",
"Only 'ROUND_ROBIN', 'FIXED', and 'RANDOM' are supported values for 'order'")) }, false),
}
return
},
}, },
"description": &schema.Schema{ "description": &schema.Schema{
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
ValidateFunc: func(v interface{}, k string) (ws []string, errors []error) { ValidateFunc: validation.StringLenBetween(0, 255),
if v != nil {
value := v.(string)
if len(value) > 255 {
errors = append(errors, fmt.Errorf(
"'description' length must be 0-255"))
}
}
return
},
}, },
"ttl": &schema.Schema{ "ttl": &schema.Schema{
Type: schema.TypeInt, Type: schema.TypeInt,