mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-11 08:05:33 -06:00
31 lines
497 B
Go
31 lines
497 B
Go
package terraform
|
|
|
|
// EvalIf is an EvalNode that is a conditional.
|
|
type EvalIf struct {
|
|
If func(EvalContext) (bool, error)
|
|
Node EvalNode
|
|
}
|
|
|
|
func (n *EvalIf) Args() ([]EvalNode, []EvalType) {
|
|
return nil, nil
|
|
}
|
|
|
|
// TODO: test
|
|
func (n *EvalIf) Eval(
|
|
ctx EvalContext, args []interface{}) (interface{}, error) {
|
|
yes, err := n.If(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if yes {
|
|
return EvalRaw(n.Node, ctx)
|
|
}
|
|
|
|
return nil, nil
|
|
}
|
|
|
|
func (n *EvalIf) Type() EvalType {
|
|
return EvalTypeNull
|
|
}
|