diff options
author | Jake Champlin <jake.champlin.27@gmail.com> | 2017-06-06 12:40:07 -0400 |
---|---|---|
committer | Jake Champlin <jake.champlin.27@gmail.com> | 2017-06-06 12:40:07 -0400 |
commit | bae9f6d2fd5eb5bc80929bd393932b23f14d7c93 (patch) | |
tree | ca9ab12a7d78b1fc27a8f734729081357ce6d252 /vendor/github.com/hashicorp/terraform/config/config_tree.go | |
parent | 254c495b6bebab3fb72a243c4bce858d79e6ee99 (diff) | |
download | terraform-provider-statuscake-bae9f6d2fd5eb5bc80929bd393932b23f14d7c93.tar.gz terraform-provider-statuscake-bae9f6d2fd5eb5bc80929bd393932b23f14d7c93.tar.zst terraform-provider-statuscake-bae9f6d2fd5eb5bc80929bd393932b23f14d7c93.zip |
Initial transfer of provider code
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/config/config_tree.go')
-rw-r--r-- | vendor/github.com/hashicorp/terraform/config/config_tree.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/terraform/config/config_tree.go b/vendor/github.com/hashicorp/terraform/config/config_tree.go new file mode 100644 index 0000000..08dc0fe --- /dev/null +++ b/vendor/github.com/hashicorp/terraform/config/config_tree.go | |||
@@ -0,0 +1,43 @@ | |||
1 | package config | ||
2 | |||
3 | // configTree represents a tree of configurations where the root is the | ||
4 | // first file and its children are the configurations it has imported. | ||
5 | type configTree struct { | ||
6 | Path string | ||
7 | Config *Config | ||
8 | Children []*configTree | ||
9 | } | ||
10 | |||
11 | // Flatten flattens the entire tree down to a single merged Config | ||
12 | // structure. | ||
13 | func (t *configTree) Flatten() (*Config, error) { | ||
14 | // No children is easy: we're already merged! | ||
15 | if len(t.Children) == 0 { | ||
16 | return t.Config, nil | ||
17 | } | ||
18 | |||
19 | // Depth-first, merge all the children first. | ||
20 | childConfigs := make([]*Config, len(t.Children)) | ||
21 | for i, ct := range t.Children { | ||
22 | c, err := ct.Flatten() | ||
23 | if err != nil { | ||
24 | return nil, err | ||
25 | } | ||
26 | |||
27 | childConfigs[i] = c | ||
28 | } | ||
29 | |||
30 | // Merge all the children in order | ||
31 | config := childConfigs[0] | ||
32 | childConfigs = childConfigs[1:] | ||
33 | for _, config2 := range childConfigs { | ||
34 | var err error | ||
35 | config, err = Merge(config, config2) | ||
36 | if err != nil { | ||
37 | return nil, err | ||
38 | } | ||
39 | } | ||
40 | |||
41 | // Merge the final merged child config with our own | ||
42 | return Merge(config, t.Config) | ||
43 | } | ||