/
data_source.go
94 lines (82 loc) · 3.72 KB
/
data_source.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package datasource
import (
"context"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
)
// DataSource represents an instance of a data source type. This is the core
// interface that all data sources must implement.
//
// Data sources can optionally implement these additional concepts:
//
// - Configure: Include provider-level data or clients.
// - Validation: Schema-based via tfsdk.Attribute or entire configuration
// via DataSourceWithConfigValidators or DataSourceWithValidateConfig.
type DataSource interface {
// Read is called when the provider must read data source values in
// order to update state. Config values should be read from the
// ReadRequest and new state values set on the ReadResponse.
Read(context.Context, ReadRequest, *ReadResponse)
}
// DataSourceWithConfigure is an interface type that extends DataSource to
// include a method which the framework will automatically call so provider
// developers have the opportunity to setup any necessary provider-level data
// or clients in the DataSource type.
//
// This method is intended to replace the provider.DataSourceType type
// NewDataSource method in a future release.
type DataSourceWithConfigure interface {
DataSource
// Configure enables provider-level data or clients to be set in the
// provider-defined DataSource type. It is separately executed for each
// ReadDataSource RPC.
Configure(context.Context, ConfigureRequest, *ConfigureResponse)
}
// DataSourceWithConfigValidators is an interface type that extends DataSource to include declarative validations.
//
// Declaring validation using this methodology simplifies implmentation of
// reusable functionality. These also include descriptions, which can be used
// for automating documentation.
//
// Validation will include ConfigValidators and ValidateConfig, if both are
// implemented, in addition to any Attribute or Type validation.
type DataSourceWithConfigValidators interface {
DataSource
// ConfigValidators returns a list of ConfigValidators. Each ConfigValidator's Validate method will be called when validating the data source.
ConfigValidators(context.Context) []ConfigValidator
}
// DataSourceWithGetSchema is an interface type that extends DataSource to
// return its schema definition.
//
// This method will be required in the DataSource interface in a future
// release.
type DataSourceWithGetSchema interface {
// GetSchema returns the schema for this data source.
GetSchema(context.Context) (tfsdk.Schema, diag.Diagnostics)
}
// DataSourceWithMetadata is an interface type that extends DataSource to
// return metadata, such as its data source type name. For example, if the
// provider is named examplecloud and the data source reads a thing, this
// should return examplecloud_thing.
//
// This method will be required in the DataSource interface a future release.
type DataSourceWithMetadata interface {
DataSource
// Metadata should return the full name of the data source, such as
// examplecloud_thing.
Metadata(context.Context, MetadataRequest, *MetadataResponse)
}
// DataSourceWithValidateConfig is an interface type that extends DataSource to include imperative validation.
//
// Declaring validation using this methodology simplifies one-off
// functionality that typically applies to a single data source. Any
// documentation of this functionality must be manually added into schema
// descriptions.
//
// Validation will include ConfigValidators and ValidateConfig, if both are
// implemented, in addition to any Attribute or Type validation.
type DataSourceWithValidateConfig interface {
DataSource
// ValidateConfig performs the validation.
ValidateConfig(context.Context, ValidateConfigRequest, *ValidateConfigResponse)
}