github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/builtin/providers/newrelic/validation.go (about)

     1  package newrelic
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/hashicorp/terraform/helper/schema"
     7  )
     8  
     9  func float64Gte(gte float64) schema.SchemaValidateFunc {
    10  	return func(i interface{}, k string) (s []string, es []error) {
    11  		v, ok := i.(float64)
    12  		if !ok {
    13  			es = append(es, fmt.Errorf("expected type of %s to be float64", k))
    14  			return
    15  		}
    16  
    17  		if v >= gte {
    18  			return
    19  		}
    20  
    21  		es = append(es, fmt.Errorf("expected %s to be greater than or equal to %v, got %v", k, gte, v))
    22  		return
    23  	}
    24  }
    25  
    26  func intInSlice(valid []int) schema.SchemaValidateFunc {
    27  	return func(i interface{}, k string) (s []string, es []error) {
    28  		v, ok := i.(int)
    29  		if !ok {
    30  			es = append(es, fmt.Errorf("expected type of %s to be int", k))
    31  			return
    32  		}
    33  
    34  		for _, p := range valid {
    35  			if v == p {
    36  				return
    37  			}
    38  		}
    39  
    40  		es = append(es, fmt.Errorf("expected %s to be one of %v, got %v", k, valid, v))
    41  		return
    42  	}
    43  }