github.com/hooklift/terraform@v0.11.0-beta1.0.20171117000744-6786c1361ffe/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  }