github.com/rstandt/terraform@v0.12.32-0.20230710220336-b1063613405c/builtin/providers/terraform/provider.go (about) 1 package terraform 2 3 import ( 4 "fmt" 5 "log" 6 7 "github.com/hashicorp/terraform/providers" 8 ) 9 10 // Provider is an implementation of providers.Interface 11 type Provider struct { 12 // Provider is the schema for the provider itself. 13 Schema providers.Schema 14 15 // DataSources maps the data source name to that data source's schema. 16 DataSources map[string]providers.Schema 17 } 18 19 // NewProvider returns a new terraform provider 20 func NewProvider() *Provider { 21 return &Provider{} 22 } 23 24 // GetSchema returns the complete schema for the provider. 25 func (p *Provider) GetSchema() providers.GetSchemaResponse { 26 return providers.GetSchemaResponse{ 27 DataSources: map[string]providers.Schema{ 28 "terraform_remote_state": dataSourceRemoteStateGetSchema(), 29 }, 30 } 31 } 32 33 // ValidateProviderConfig is used to validate the configuration values. 34 func (p *Provider) PrepareProviderConfig(req providers.PrepareProviderConfigRequest) providers.PrepareProviderConfigResponse { 35 // At this moment there is nothing to configure for the terraform provider, 36 // so we will happily return without taking any action 37 var res providers.PrepareProviderConfigResponse 38 res.PreparedConfig = req.Config 39 return res 40 } 41 42 // ValidateDataSourceConfig is used to validate the data source configuration values. 43 func (p *Provider) ValidateDataSourceConfig(req providers.ValidateDataSourceConfigRequest) providers.ValidateDataSourceConfigResponse { 44 // FIXME: move the backend configuration validate call that's currently 45 // inside the read method into here so that we can catch provider configuration 46 // errors in terraform validate as well as during terraform plan. 47 var res providers.ValidateDataSourceConfigResponse 48 49 // This should not happen 50 if req.TypeName != "terraform_remote_state" { 51 res.Diagnostics.Append(fmt.Errorf("Error: unsupported data source %s", req.TypeName)) 52 return res 53 } 54 55 diags := dataSourceRemoteStateValidate(req.Config) 56 res.Diagnostics = diags 57 58 return res 59 } 60 61 // Configure configures and initializes the provider. 62 func (p *Provider) Configure(providers.ConfigureRequest) providers.ConfigureResponse { 63 // At this moment there is nothing to configure for the terraform provider, 64 // so we will happily return without taking any action 65 var res providers.ConfigureResponse 66 return res 67 } 68 69 // ReadDataSource returns the data source's current state. 70 func (p *Provider) ReadDataSource(req providers.ReadDataSourceRequest) providers.ReadDataSourceResponse { 71 // call function 72 var res providers.ReadDataSourceResponse 73 74 // This should not happen 75 if req.TypeName != "terraform_remote_state" { 76 res.Diagnostics.Append(fmt.Errorf("Error: unsupported data source %s", req.TypeName)) 77 return res 78 } 79 80 newState, diags := dataSourceRemoteStateRead(req.Config) 81 82 res.State = newState 83 res.Diagnostics = diags 84 85 return res 86 } 87 88 // Stop is called when the provider should halt any in-flight actions. 89 func (p *Provider) Stop() error { 90 log.Println("[DEBUG] terraform provider cannot Stop") 91 return nil 92 } 93 94 // All the Resource-specific functions are below. 95 // The terraform provider supplies a single data source, `terraform_remote_state` 96 // and no resources. 97 98 // UpgradeResourceState is called when the state loader encounters an 99 // instance state whose schema version is less than the one reported by the 100 // currently-used version of the corresponding provider, and the upgraded 101 // result is used for any further processing. 102 func (p *Provider) UpgradeResourceState(providers.UpgradeResourceStateRequest) providers.UpgradeResourceStateResponse { 103 panic("unimplemented - terraform_remote_state has no resources") 104 } 105 106 // ReadResource refreshes a resource and returns its current state. 107 func (p *Provider) ReadResource(providers.ReadResourceRequest) providers.ReadResourceResponse { 108 panic("unimplemented - terraform_remote_state has no resources") 109 } 110 111 // PlanResourceChange takes the current state and proposed state of a 112 // resource, and returns the planned final state. 113 func (p *Provider) PlanResourceChange(providers.PlanResourceChangeRequest) providers.PlanResourceChangeResponse { 114 panic("unimplemented - terraform_remote_state has no resources") 115 } 116 117 // ApplyResourceChange takes the planned state for a resource, which may 118 // yet contain unknown computed values, and applies the changes returning 119 // the final state. 120 func (p *Provider) ApplyResourceChange(providers.ApplyResourceChangeRequest) providers.ApplyResourceChangeResponse { 121 panic("unimplemented - terraform_remote_state has no resources") 122 } 123 124 // ImportResourceState requests that the given resource be imported. 125 func (p *Provider) ImportResourceState(providers.ImportResourceStateRequest) providers.ImportResourceStateResponse { 126 panic("unimplemented - terraform_remote_state has no resources") 127 } 128 129 // ValidateResourceTypeConfig is used to to validate the resource configuration values. 130 func (p *Provider) ValidateResourceTypeConfig(providers.ValidateResourceTypeConfigRequest) providers.ValidateResourceTypeConfigResponse { 131 // At this moment there is nothing to configure for the terraform provider, 132 // so we will happily return without taking any action 133 var res providers.ValidateResourceTypeConfigResponse 134 return res 135 } 136 137 // Close is a noop for this provider, since it's run in-process. 138 func (p *Provider) Close() error { 139 return nil 140 }