github.com/ndarilek/terraform@v0.3.8-0.20150320140257-d3135c1b2bac/terraform/eval_if.go (about)

     1  package terraform
     2  
     3  // EvalIf is an EvalNode that is a conditional.
     4  type EvalIf struct {
     5  	If   func(EvalContext) (bool, error)
     6  	Then EvalNode
     7  	Else EvalNode
     8  }
     9  
    10  // TODO: test
    11  func (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  }