]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blob - vendor/github.com/hashicorp/hcl2/ext/dynblock/iteration.go
Upgrade to 0.12
[github/fretlink/terraform-provider-statuscake.git] / vendor / github.com / hashicorp / hcl2 / ext / dynblock / iteration.go
1 package dynblock
2
3 import (
4 "github.com/hashicorp/hcl2/hcl"
5 "github.com/zclconf/go-cty/cty"
6 )
7
8 type iteration struct {
9 IteratorName string
10 Key cty.Value
11 Value cty.Value
12 Inherited map[string]*iteration
13 }
14
15 func (s *expandSpec) MakeIteration(key, value cty.Value) *iteration {
16 return &iteration{
17 IteratorName: s.iteratorName,
18 Key: key,
19 Value: value,
20 Inherited: s.inherited,
21 }
22 }
23
24 func (i *iteration) Object() cty.Value {
25 return cty.ObjectVal(map[string]cty.Value{
26 "key": i.Key,
27 "value": i.Value,
28 })
29 }
30
31 func (i *iteration) EvalContext(base *hcl.EvalContext) *hcl.EvalContext {
32 new := base.NewChild()
33
34 if i != nil {
35 new.Variables = map[string]cty.Value{}
36 for name, otherIt := range i.Inherited {
37 new.Variables[name] = otherIt.Object()
38 }
39 new.Variables[i.IteratorName] = i.Object()
40 }
41
42 return new
43 }
44
45 func (i *iteration) MakeChild(iteratorName string, key, value cty.Value) *iteration {
46 if i == nil {
47 // Create entirely new root iteration, then
48 return &iteration{
49 IteratorName: iteratorName,
50 Key: key,
51 Value: value,
52 }
53 }
54
55 inherited := map[string]*iteration{}
56 for name, otherIt := range i.Inherited {
57 inherited[name] = otherIt
58 }
59 inherited[i.IteratorName] = i
60 return &iteration{
61 IteratorName: iteratorName,
62 Key: key,
63 Value: value,
64 Inherited: inherited,
65 }
66 }