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