2015-02-13 14:05:34 -06:00
|
|
|
package terraform
|
|
|
|
|
|
|
|
// EvalIf is an EvalNode that is a conditional.
|
|
|
|
type EvalIf struct {
|
|
|
|
If func(EvalContext) (bool, error)
|
2015-02-27 11:38:17 -06:00
|
|
|
Then EvalNode
|
|
|
|
Else EvalNode
|
2015-02-13 14:05:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: test
|
2015-02-14 00:58:41 -06:00
|
|
|
func (n *EvalIf) Eval(ctx EvalContext) (interface{}, error) {
|
2015-02-13 14:05:34 -06:00
|
|
|
yes, err := n.If(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if yes {
|
2015-02-27 11:38:17 -06:00
|
|
|
return EvalRaw(n.Then, ctx)
|
|
|
|
} else {
|
|
|
|
if n.Else != nil {
|
|
|
|
return EvalRaw(n.Else, ctx)
|
|
|
|
}
|
2015-02-13 14:05:34 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|