github.com/maheshbr/terraform@v0.3.1-0.20141020033300-deec7194a3ea/terraform/semantics.go (about) 1 package terraform 2 3 import ( 4 "fmt" 5 6 "github.com/hashicorp/terraform/config" 7 ) 8 9 // smcUserVariables does all the semantic checks to verify that the 10 // variables given satisfy the configuration itself. 11 func smcUserVariables(c *config.Config, vs map[string]string) []error { 12 var errs []error 13 14 cvs := make(map[string]*config.Variable) 15 for _, v := range c.Variables { 16 cvs[v.Name] = v 17 } 18 19 // Check that all required variables are present 20 required := make(map[string]struct{}) 21 for _, v := range c.Variables { 22 if v.Required() { 23 required[v.Name] = struct{}{} 24 } 25 } 26 for k, _ := range vs { 27 delete(required, k) 28 } 29 if len(required) > 0 { 30 for k, _ := range required { 31 errs = append(errs, fmt.Errorf( 32 "Required variable not set: %s", k)) 33 } 34 } 35 36 // Check that types match up 37 for k, _ := range vs { 38 v, ok := cvs[k] 39 if !ok { 40 continue 41 } 42 43 if v.Type() != config.VariableTypeString { 44 errs = append(errs, fmt.Errorf( 45 "%s: cannot assign string value to map type", 46 k)) 47 } 48 } 49 50 // TODO(mitchellh): variables that are unknown 51 52 return errs 53 }