summaryrefslogtreecommitdiff
path: root/vendor/github.com/hashicorp/terraform/terraform/eval_if.go
blob: d6b46a1f222648893c6e0e699ba0d3dde3d448e0 (plain)
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
package terraform

// EvalIf is an EvalNode that is a conditional.
type EvalIf struct {
	If   func(EvalContext) (bool, error)
	Then EvalNode
	Else EvalNode
}

// TODO: test
func (n *EvalIf) Eval(ctx EvalContext) (interface{}, error) {
	yes, err := n.If(ctx)
	if err != nil {
		return nil, err
	}

	if yes {
		return EvalRaw(n.Then, ctx)
	} else {
		if n.Else != nil {
			return EvalRaw(n.Else, ctx)
		}
	}

	return nil, nil
}