diff options
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/config')
6 files changed, 211 insertions, 4 deletions
diff --git a/vendor/github.com/hashicorp/terraform/config/config.go b/vendor/github.com/hashicorp/terraform/config/config.go index a157824..3f756dc 100644 --- a/vendor/github.com/hashicorp/terraform/config/config.go +++ b/vendor/github.com/hashicorp/terraform/config/config.go | |||
@@ -12,6 +12,7 @@ import ( | |||
12 | "github.com/hashicorp/hil" | 12 | "github.com/hashicorp/hil" |
13 | "github.com/hashicorp/hil/ast" | 13 | "github.com/hashicorp/hil/ast" |
14 | "github.com/hashicorp/terraform/helper/hilmapstructure" | 14 | "github.com/hashicorp/terraform/helper/hilmapstructure" |
15 | "github.com/hashicorp/terraform/plugin/discovery" | ||
15 | "github.com/mitchellh/reflectwalk" | 16 | "github.com/mitchellh/reflectwalk" |
16 | ) | 17 | ) |
17 | 18 | ||
@@ -64,6 +65,7 @@ type Module struct { | |||
64 | type ProviderConfig struct { | 65 | type ProviderConfig struct { |
65 | Name string | 66 | Name string |
66 | Alias string | 67 | Alias string |
68 | Version string | ||
67 | RawConfig *RawConfig | 69 | RawConfig *RawConfig |
68 | } | 70 | } |
69 | 71 | ||
@@ -238,6 +240,33 @@ func (r *Resource) Id() string { | |||
238 | } | 240 | } |
239 | } | 241 | } |
240 | 242 | ||
243 | // ProviderFullName returns the full name of the provider for this resource, | ||
244 | // which may either be specified explicitly using the "provider" meta-argument | ||
245 | // or implied by the prefix on the resource type name. | ||
246 | func (r *Resource) ProviderFullName() string { | ||
247 | return ResourceProviderFullName(r.Type, r.Provider) | ||
248 | } | ||
249 | |||
250 | // ResourceProviderFullName returns the full (dependable) name of the | ||
251 | // provider for a hypothetical resource with the given resource type and | ||
252 | // explicit provider string. If the explicit provider string is empty then | ||
253 | // the provider name is inferred from the resource type name. | ||
254 | func ResourceProviderFullName(resourceType, explicitProvider string) string { | ||
255 | if explicitProvider != "" { | ||
256 | return explicitProvider | ||
257 | } | ||
258 | |||
259 | idx := strings.IndexRune(resourceType, '_') | ||
260 | if idx == -1 { | ||
261 | // If no underscores, the resource name is assumed to be | ||
262 | // also the provider name, e.g. if the provider exposes | ||
263 | // only a single resource of each type. | ||
264 | return resourceType | ||
265 | } | ||
266 | |||
267 | return resourceType[:idx] | ||
268 | } | ||
269 | |||
241 | // Validate does some basic semantic checking of the configuration. | 270 | // Validate does some basic semantic checking of the configuration. |
242 | func (c *Config) Validate() error { | 271 | func (c *Config) Validate() error { |
243 | if c == nil { | 272 | if c == nil { |
@@ -349,7 +378,8 @@ func (c *Config) Validate() error { | |||
349 | } | 378 | } |
350 | } | 379 | } |
351 | 380 | ||
352 | // Check that providers aren't declared multiple times. | 381 | // Check that providers aren't declared multiple times and that their |
382 | // version constraints, where present, are syntactically valid. | ||
353 | providerSet := make(map[string]struct{}) | 383 | providerSet := make(map[string]struct{}) |
354 | for _, p := range c.ProviderConfigs { | 384 | for _, p := range c.ProviderConfigs { |
355 | name := p.FullName() | 385 | name := p.FullName() |
@@ -360,6 +390,16 @@ func (c *Config) Validate() error { | |||
360 | continue | 390 | continue |
361 | } | 391 | } |
362 | 392 | ||
393 | if p.Version != "" { | ||
394 | _, err := discovery.ConstraintStr(p.Version).Parse() | ||
395 | if err != nil { | ||
396 | errs = append(errs, fmt.Errorf( | ||
397 | "provider.%s: invalid version constraint %q: %s", | ||
398 | name, p.Version, err, | ||
399 | )) | ||
400 | } | ||
401 | } | ||
402 | |||
363 | providerSet[name] = struct{}{} | 403 | providerSet[name] = struct{}{} |
364 | } | 404 | } |
365 | 405 | ||
diff --git a/vendor/github.com/hashicorp/terraform/config/interpolate_funcs.go b/vendor/github.com/hashicorp/terraform/config/interpolate_funcs.go index 7b7b3f2..a298cf2 100644 --- a/vendor/github.com/hashicorp/terraform/config/interpolate_funcs.go +++ b/vendor/github.com/hashicorp/terraform/config/interpolate_funcs.go | |||
@@ -70,6 +70,7 @@ func Funcs() map[string]ast.Function { | |||
70 | "coalescelist": interpolationFuncCoalesceList(), | 70 | "coalescelist": interpolationFuncCoalesceList(), |
71 | "compact": interpolationFuncCompact(), | 71 | "compact": interpolationFuncCompact(), |
72 | "concat": interpolationFuncConcat(), | 72 | "concat": interpolationFuncConcat(), |
73 | "contains": interpolationFuncContains(), | ||
73 | "dirname": interpolationFuncDirname(), | 74 | "dirname": interpolationFuncDirname(), |
74 | "distinct": interpolationFuncDistinct(), | 75 | "distinct": interpolationFuncDistinct(), |
75 | "element": interpolationFuncElement(), | 76 | "element": interpolationFuncElement(), |
@@ -356,6 +357,22 @@ func interpolationFuncCoalesceList() ast.Function { | |||
356 | } | 357 | } |
357 | } | 358 | } |
358 | 359 | ||
360 | // interpolationFuncContains returns true if an element is in the list | ||
361 | // and return false otherwise | ||
362 | func interpolationFuncContains() ast.Function { | ||
363 | return ast.Function{ | ||
364 | ArgTypes: []ast.Type{ast.TypeList, ast.TypeString}, | ||
365 | ReturnType: ast.TypeBool, | ||
366 | Callback: func(args []interface{}) (interface{}, error) { | ||
367 | _, err := interpolationFuncIndex().Callback(args) | ||
368 | if err != nil { | ||
369 | return false, nil | ||
370 | } | ||
371 | return true, nil | ||
372 | }, | ||
373 | } | ||
374 | } | ||
375 | |||
359 | // interpolationFuncConcat implements the "concat" function that concatenates | 376 | // interpolationFuncConcat implements the "concat" function that concatenates |
360 | // multiple lists. | 377 | // multiple lists. |
361 | func interpolationFuncConcat() ast.Function { | 378 | func interpolationFuncConcat() ast.Function { |
diff --git a/vendor/github.com/hashicorp/terraform/config/loader.go b/vendor/github.com/hashicorp/terraform/config/loader.go index 0bfa89c..5dd7d46 100644 --- a/vendor/github.com/hashicorp/terraform/config/loader.go +++ b/vendor/github.com/hashicorp/terraform/config/loader.go | |||
@@ -194,7 +194,7 @@ func dirFiles(dir string) ([]string, []string, error) { | |||
194 | // Only care about files that are valid to load | 194 | // Only care about files that are valid to load |
195 | name := fi.Name() | 195 | name := fi.Name() |
196 | extValue := ext(name) | 196 | extValue := ext(name) |
197 | if extValue == "" || isIgnoredFile(name) { | 197 | if extValue == "" || IsIgnoredFile(name) { |
198 | continue | 198 | continue |
199 | } | 199 | } |
200 | 200 | ||
@@ -215,9 +215,9 @@ func dirFiles(dir string) ([]string, []string, error) { | |||
215 | return files, overrides, nil | 215 | return files, overrides, nil |
216 | } | 216 | } |
217 | 217 | ||
218 | // isIgnoredFile returns true or false depending on whether the | 218 | // IsIgnoredFile returns true or false depending on whether the |
219 | // provided file name is a file that should be ignored. | 219 | // provided file name is a file that should be ignored. |
220 | func isIgnoredFile(name string) bool { | 220 | func IsIgnoredFile(name string) bool { |
221 | return strings.HasPrefix(name, ".") || // Unix-like hidden files | 221 | return strings.HasPrefix(name, ".") || // Unix-like hidden files |
222 | strings.HasSuffix(name, "~") || // vim | 222 | strings.HasSuffix(name, "~") || // vim |
223 | strings.HasPrefix(name, "#") && strings.HasSuffix(name, "#") // emacs | 223 | strings.HasPrefix(name, "#") && strings.HasSuffix(name, "#") // emacs |
diff --git a/vendor/github.com/hashicorp/terraform/config/loader_hcl.go b/vendor/github.com/hashicorp/terraform/config/loader_hcl.go index 9abb196..e85e493 100644 --- a/vendor/github.com/hashicorp/terraform/config/loader_hcl.go +++ b/vendor/github.com/hashicorp/terraform/config/loader_hcl.go | |||
@@ -17,6 +17,20 @@ type hclConfigurable struct { | |||
17 | Root *ast.File | 17 | Root *ast.File |
18 | } | 18 | } |
19 | 19 | ||
20 | var ReservedResourceFields = []string{ | ||
21 | "connection", | ||
22 | "count", | ||
23 | "depends_on", | ||
24 | "lifecycle", | ||
25 | "provider", | ||
26 | "provisioner", | ||
27 | } | ||
28 | |||
29 | var ReservedProviderFields = []string{ | ||
30 | "alias", | ||
31 | "version", | ||
32 | } | ||
33 | |||
20 | func (t *hclConfigurable) Config() (*Config, error) { | 34 | func (t *hclConfigurable) Config() (*Config, error) { |
21 | validKeys := map[string]struct{}{ | 35 | validKeys := map[string]struct{}{ |
22 | "atlas": struct{}{}, | 36 | "atlas": struct{}{}, |
@@ -562,6 +576,7 @@ func loadProvidersHcl(list *ast.ObjectList) ([]*ProviderConfig, error) { | |||
562 | } | 576 | } |
563 | 577 | ||
564 | delete(config, "alias") | 578 | delete(config, "alias") |
579 | delete(config, "version") | ||
565 | 580 | ||
566 | rawConfig, err := NewRawConfig(config) | 581 | rawConfig, err := NewRawConfig(config) |
567 | if err != nil { | 582 | if err != nil { |
@@ -583,9 +598,22 @@ func loadProvidersHcl(list *ast.ObjectList) ([]*ProviderConfig, error) { | |||
583 | } | 598 | } |
584 | } | 599 | } |
585 | 600 | ||
601 | // If we have a version field then extract it | ||
602 | var version string | ||
603 | if a := listVal.Filter("version"); len(a.Items) > 0 { | ||
604 | err := hcl.DecodeObject(&version, a.Items[0].Val) | ||
605 | if err != nil { | ||
606 | return nil, fmt.Errorf( | ||
607 | "Error reading version for provider[%s]: %s", | ||
608 | n, | ||
609 | err) | ||
610 | } | ||
611 | } | ||
612 | |||
586 | result = append(result, &ProviderConfig{ | 613 | result = append(result, &ProviderConfig{ |
587 | Name: n, | 614 | Name: n, |
588 | Alias: alias, | 615 | Alias: alias, |
616 | Version: version, | ||
589 | RawConfig: rawConfig, | 617 | RawConfig: rawConfig, |
590 | }) | 618 | }) |
591 | } | 619 | } |
diff --git a/vendor/github.com/hashicorp/terraform/config/module/tree.go b/vendor/github.com/hashicorp/terraform/config/module/tree.go index b6f90fd..4b0b153 100644 --- a/vendor/github.com/hashicorp/terraform/config/module/tree.go +++ b/vendor/github.com/hashicorp/terraform/config/module/tree.go | |||
@@ -92,6 +92,25 @@ func (t *Tree) Children() map[string]*Tree { | |||
92 | return t.children | 92 | return t.children |
93 | } | 93 | } |
94 | 94 | ||
95 | // DeepEach calls the provided callback for the receiver and then all of | ||
96 | // its descendents in the tree, allowing an operation to be performed on | ||
97 | // all modules in the tree. | ||
98 | // | ||
99 | // Parents will be visited before their children but otherwise the order is | ||
100 | // not defined. | ||
101 | func (t *Tree) DeepEach(cb func(*Tree)) { | ||
102 | t.lock.RLock() | ||
103 | defer t.lock.RUnlock() | ||
104 | t.deepEach(cb) | ||
105 | } | ||
106 | |||
107 | func (t *Tree) deepEach(cb func(*Tree)) { | ||
108 | cb(t) | ||
109 | for _, c := range t.children { | ||
110 | c.deepEach(cb) | ||
111 | } | ||
112 | } | ||
113 | |||
95 | // Loaded says whether or not this tree has been loaded or not yet. | 114 | // Loaded says whether or not this tree has been loaded or not yet. |
96 | func (t *Tree) Loaded() bool { | 115 | func (t *Tree) Loaded() bool { |
97 | t.lock.RLock() | 116 | t.lock.RLock() |
diff --git a/vendor/github.com/hashicorp/terraform/config/providers.go b/vendor/github.com/hashicorp/terraform/config/providers.go new file mode 100644 index 0000000..7a50782 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/config/providers.go | |||
@@ -0,0 +1,103 @@ | |||
1 | package config | ||
2 | |||
3 | import "github.com/blang/semver" | ||
4 | |||
5 | // ProviderVersionConstraint presents a constraint for a particular | ||
6 | // provider, identified by its full name. | ||
7 | type ProviderVersionConstraint struct { | ||
8 | Constraint string | ||
9 | ProviderType string | ||
10 | } | ||
11 | |||
12 | // ProviderVersionConstraints is a map from provider full name to its associated | ||
13 | // ProviderVersionConstraint, as produced by Config.RequiredProviders. | ||
14 | type ProviderVersionConstraints map[string]ProviderVersionConstraint | ||
15 | |||
16 | // RequiredProviders returns the ProviderVersionConstraints for this | ||
17 | // module. | ||
18 | // | ||
19 | // This includes both providers that are explicitly requested by provider | ||
20 | // blocks and those that are used implicitly by instantiating one of their | ||
21 | // resource types. In the latter case, the returned semver Range will | ||
22 | // accept any version of the provider. | ||
23 | func (c *Config) RequiredProviders() ProviderVersionConstraints { | ||
24 | ret := make(ProviderVersionConstraints, len(c.ProviderConfigs)) | ||
25 | |||
26 | configs := c.ProviderConfigsByFullName() | ||
27 | |||
28 | // In order to find the *implied* dependencies (those without explicit | ||
29 | // "provider" blocks) we need to walk over all of the resources and | ||
30 | // cross-reference with the provider configs. | ||
31 | for _, rc := range c.Resources { | ||
32 | providerName := rc.ProviderFullName() | ||
33 | var providerType string | ||
34 | |||
35 | // Default to (effectively) no constraint whatsoever, but we might | ||
36 | // override if there's an explicit constraint in config. | ||
37 | constraint := ">=0.0.0" | ||
38 | |||
39 | config, ok := configs[providerName] | ||
40 | if ok { | ||
41 | if config.Version != "" { | ||
42 | constraint = config.Version | ||
43 | } | ||
44 | providerType = config.Name | ||
45 | } else { | ||
46 | providerType = providerName | ||
47 | } | ||
48 | |||
49 | ret[providerName] = ProviderVersionConstraint{ | ||
50 | ProviderType: providerType, | ||
51 | Constraint: constraint, | ||
52 | } | ||
53 | } | ||
54 | |||
55 | return ret | ||
56 | } | ||
57 | |||
58 | // RequiredRanges returns a semver.Range for each distinct provider type in | ||
59 | // the constraint map. If the same provider type appears more than once | ||
60 | // (e.g. because aliases are in use) then their respective constraints are | ||
61 | // combined such that they must *all* apply. | ||
62 | // | ||
63 | // The result of this method can be passed to the | ||
64 | // PluginMetaSet.ConstrainVersions method within the plugin/discovery | ||
65 | // package in order to filter down the available plugins to those which | ||
66 | // satisfy the given constraints. | ||
67 | // | ||
68 | // This function will panic if any of the constraints within cannot be | ||
69 | // parsed as semver ranges. This is guaranteed to never happen for a | ||
70 | // constraint set that was built from a configuration that passed validation. | ||
71 | func (cons ProviderVersionConstraints) RequiredRanges() map[string]semver.Range { | ||
72 | ret := make(map[string]semver.Range, len(cons)) | ||
73 | |||
74 | for _, con := range cons { | ||
75 | spec := semver.MustParseRange(con.Constraint) | ||
76 | if existing, exists := ret[con.ProviderType]; exists { | ||
77 | ret[con.ProviderType] = existing.AND(spec) | ||
78 | } else { | ||
79 | ret[con.ProviderType] = spec | ||
80 | } | ||
81 | } | ||
82 | |||
83 | return ret | ||
84 | } | ||
85 | |||
86 | // ProviderConfigsByFullName returns a map from provider full names (as | ||
87 | // returned by ProviderConfig.FullName()) to the corresponding provider | ||
88 | // configs. | ||
89 | // | ||
90 | // This function returns no new information than what's already in | ||
91 | // c.ProviderConfigs, but returns it in a more convenient shape. If there | ||
92 | // is more than one provider config with the same full name then the result | ||
93 | // is undefined, but that is guaranteed not to happen for any config that | ||
94 | // has passed validation. | ||
95 | func (c *Config) ProviderConfigsByFullName() map[string]*ProviderConfig { | ||
96 | ret := make(map[string]*ProviderConfig, len(c.ProviderConfigs)) | ||
97 | |||
98 | for _, pc := range c.ProviderConfigs { | ||
99 | ret[pc.FullName()] = pc | ||
100 | } | ||
101 | |||
102 | return ret | ||
103 | } | ||