1package terraform 2 3// EvalIf is an EvalNode that is a conditional. 4type EvalIf struct { 5 If func(EvalContext) (bool, error) 6 Then EvalNode 7 Else EvalNode 8} 9 10// TODO: test 11func (n *EvalIf) Eval(ctx EvalContext) (interface{}, error) { 12 yes, err := n.If(ctx) 13 if err != nil { 14 return nil, err 15 } 16 17 if yes { 18 return EvalRaw(n.Then, ctx) 19 } else { 20 if n.Else != nil { 21 return EvalRaw(n.Else, ctx) 22 } 23 } 24 25 return nil, nil 26} 27