github.com/hashicorp/terraform-plugin-sdk@v1.17.2/terraform/eval_provisioner.go (about)

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