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