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

     1  package terraform
     2  
     3  import (
     4  	"github.com/hashicorp/terraform-plugin-sdk/internal/configs/configschema"
     5  	"github.com/hashicorp/terraform-plugin-sdk/internal/provisioners"
     6  )
     7  
     8  // ResourceProvisioner is an interface that must be implemented by any
     9  // resource provisioner: the thing that initializes resources in
    10  // a Terraform configuration.
    11  type ResourceProvisioner interface {
    12  	// GetConfigSchema returns the schema for the provisioner type's main
    13  	// configuration block. This is called prior to Validate to enable some
    14  	// basic structural validation to be performed automatically and to allow
    15  	// the configuration to be properly extracted from potentially-ambiguous
    16  	// configuration file formats.
    17  	GetConfigSchema() (*configschema.Block, error)
    18  
    19  	// Validate is called once at the beginning with the raw
    20  	// configuration (no interpolation done) and can return a list of warnings
    21  	// and/or errors.
    22  	//
    23  	// This is called once per resource.
    24  	//
    25  	// This should not assume any of the values in the resource configuration
    26  	// are valid since it is possible they have to be interpolated still.
    27  	// The primary use case of this call is to check that the required keys
    28  	// are set and that the general structure is correct.
    29  	Validate(*ResourceConfig) ([]string, []error)
    30  
    31  	// Apply runs the provisioner on a specific resource and returns the new
    32  	// resource state along with an error. Instead of a diff, the ResourceConfig
    33  	// is provided since provisioners only run after a resource has been
    34  	// newly created.
    35  	Apply(UIOutput, *InstanceState, *ResourceConfig) error
    36  
    37  	// Stop is called when the provisioner should halt any in-flight actions.
    38  	//
    39  	// This can be used to make a nicer Ctrl-C experience for Terraform.
    40  	// Even if this isn't implemented to do anything (just returns nil),
    41  	// Terraform will still cleanly stop after the currently executing
    42  	// graph node is complete. However, this API can be used to make more
    43  	// efficient halts.
    44  	//
    45  	// Stop doesn't have to and shouldn't block waiting for in-flight actions
    46  	// to complete. It should take any action it wants and return immediately
    47  	// acknowledging it has received the stop request. Terraform core will
    48  	// automatically not make any further API calls to the provider soon
    49  	// after Stop is called (technically exactly once the currently executing
    50  	// graph nodes are complete).
    51  	//
    52  	// The error returned, if non-nil, is assumed to mean that signaling the
    53  	// stop somehow failed and that the user should expect potentially waiting
    54  	// a longer period of time.
    55  	Stop() error
    56  }
    57  
    58  // ResourceProvisionerCloser is an interface that provisioners that can close
    59  // connections that aren't needed anymore must implement.
    60  type ResourceProvisionerCloser interface {
    61  	Close() error
    62  }
    63  
    64  // ResourceProvisionerFactory is a function type that creates a new instance
    65  // of a resource provisioner.
    66  type ResourceProvisionerFactory func() (ResourceProvisioner, error)
    67  
    68  // ProvisionerFactory is a function type that creates a new instance
    69  // of a provisioners.Interface.
    70  type ProvisionerFactory = provisioners.Factory