github.com/tomaszheflik/terraform@v0.7.3-0.20160827060421-32f990b41594/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  }