github.com/hooklift/terraform@v0.11.0-beta1.0.20171117000744-6786c1361ffe/terraform/eval_provisioner.go (about)

     1  package terraform
     2  
     3  import (
     4  	"fmt"
     5  )
     6  
     7  // EvalInitProvisioner is an EvalNode implementation that initializes a provisioner
     8  // and returns nothing. The provisioner can be retrieved again with the
     9  // EvalGetProvisioner node.
    10  type EvalInitProvisioner struct {
    11  	Name string
    12  }
    13  
    14  func (n *EvalInitProvisioner) Eval(ctx EvalContext) (interface{}, error) {
    15  	return ctx.InitProvisioner(n.Name)
    16  }
    17  
    18  // EvalCloseProvisioner is an EvalNode implementation that closes provisioner
    19  // connections that aren't needed anymore.
    20  type EvalCloseProvisioner struct {
    21  	Name string
    22  }
    23  
    24  func (n *EvalCloseProvisioner) Eval(ctx EvalContext) (interface{}, error) {
    25  	ctx.CloseProvisioner(n.Name)
    26  	return nil, nil
    27  }
    28  
    29  // EvalGetProvisioner is an EvalNode implementation that retrieves an already
    30  // initialized provisioner instance for the given name.
    31  type EvalGetProvisioner struct {
    32  	Name   string
    33  	Output *ResourceProvisioner
    34  }
    35  
    36  func (n *EvalGetProvisioner) Eval(ctx EvalContext) (interface{}, error) {
    37  	result := ctx.Provisioner(n.Name)
    38  	if result == nil {
    39  		return nil, fmt.Errorf("provisioner %s not initialized", n.Name)
    40  	}
    41  
    42  	if n.Output != nil {
    43  		*n.Output = result
    44  	}
    45  
    46  	return result, nil
    47  }