github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/external/util.go (about) 1 package external 2 3 import ( 4 "fmt" 5 "os/exec" 6 ) 7 8 // validateProgramAttr is a validation function for the "program" attribute we 9 // accept as input on our resources. 10 // 11 // The attribute is assumed to be specified in schema as a list of strings. 12 func validateProgramAttr(v interface{}) error { 13 args := v.([]interface{}) 14 if len(args) < 1 { 15 return fmt.Errorf("'program' list must contain at least one element") 16 } 17 18 for i, vI := range args { 19 if _, ok := vI.(string); !ok { 20 return fmt.Errorf( 21 "'program' element %d is %T; a string is required", 22 i, vI, 23 ) 24 } 25 } 26 27 // first element is assumed to be an executable command, possibly found 28 // using the PATH environment variable. 29 _, err := exec.LookPath(args[0].(string)) 30 if err != nil { 31 return fmt.Errorf("can't find external program %q", args[0]) 32 } 33 34 return nil 35 }