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