opentofu/terraform/eval_if.go

27 lines
426 B
Go
Raw Normal View History

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)
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 {
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
}