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

     1  package provisioners
     2  
     3  import (
     4  	"github.com/hashicorp/terraform-plugin-sdk/internal/configs/configschema"
     5  	"github.com/hashicorp/terraform-plugin-sdk/internal/tfdiags"
     6  	"github.com/zclconf/go-cty/cty"
     7  )
     8  
     9  // Interface is the set of methods required for a resource provisioner plugin.
    10  type Interface interface {
    11  	// GetSchema returns the schema for the provisioner configuration.
    12  	GetSchema() GetSchemaResponse
    13  
    14  	// ValidateProvisionerConfig allows the provisioner to validate the
    15  	// configuration values.
    16  	ValidateProvisionerConfig(ValidateProvisionerConfigRequest) ValidateProvisionerConfigResponse
    17  
    18  	// ProvisionResource runs the provisioner with provided configuration.
    19  	// ProvisionResource blocks until the execution is complete.
    20  	// If the returned diagnostics contain any errors, the resource will be
    21  	// left in a tainted state.
    22  	ProvisionResource(ProvisionResourceRequest) ProvisionResourceResponse
    23  
    24  	// Stop is called to interrupt the provisioner.
    25  	//
    26  	// Stop should not block waiting for in-flight actions to complete. It
    27  	// should take any action it wants and return immediately acknowledging it
    28  	// has received the stop request. Terraform will not make any further API
    29  	// calls to the provisioner after Stop is called.
    30  	//
    31  	// The error returned, if non-nil, is assumed to mean that signaling the
    32  	// stop somehow failed and that the user should expect potentially waiting
    33  	// a longer period of time.
    34  	Stop() error
    35  
    36  	// Close shuts down the plugin process if applicable.
    37  	Close() error
    38  }
    39  
    40  type GetSchemaResponse struct {
    41  	// Provisioner contains the schema for this provisioner.
    42  	Provisioner *configschema.Block
    43  
    44  	// Diagnostics contains any warnings or errors from the method call.
    45  	Diagnostics tfdiags.Diagnostics
    46  }
    47  
    48  // UIOutput provides the Output method for resource provisioner
    49  // plugins to write any output to the UI.
    50  //
    51  // Provisioners may call the Output method multiple times while Apply is in
    52  // progress. It is invalid to call Output after Apply returns.
    53  type UIOutput interface {
    54  	Output(string)
    55  }
    56  
    57  type ValidateProvisionerConfigRequest struct {
    58  	// Config is the complete configuration to be used for the provisioner.
    59  	Config cty.Value
    60  }
    61  
    62  type ValidateProvisionerConfigResponse struct {
    63  	// Diagnostics contains any warnings or errors from the method call.
    64  	Diagnostics tfdiags.Diagnostics
    65  }
    66  
    67  type ProvisionResourceRequest struct {
    68  	// Config is the complete provisioner configuration.
    69  	Config cty.Value
    70  
    71  	// Connection contains any information required to access the resource
    72  	// instance.
    73  	Connection cty.Value
    74  
    75  	// UIOutput is used to return output during the Apply operation.
    76  	UIOutput UIOutput
    77  }
    78  
    79  type ProvisionResourceResponse struct {
    80  	// Diagnostics contains any warnings or errors from the method call.
    81  	Diagnostics tfdiags.Diagnostics
    82  }