datasource
packageThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Overview¶
Package datasource contains all interfaces, request types, and responsetypes for a data source implementation.
In Terraform, a data source is a concept which enables provider developersto offer practitioners a read-only source of information, which is savedinto the Terraform state and can be referenced by other parts of aconfiguration. Data sources are defined by a data source type/name, such as"examplecloud_thing", a schema representing the structure and data types ofconfiguration and state, and read logic.
The main starting point for implementations in this package is theDataSource type which represents an instance of a data source type that hasits own configuration, read logic, and state. The DataSource implementationsare referenced by a [provider.Provider] type DataSources method, whichenables the data source for practitioner and testing usage.
Index¶
- type ConfigValidator
- type ConfigureRequest
- type ConfigureResponse
- type DataSource
- type DataSourceWithConfigValidators
- type DataSourceWithConfigure
- type DataSourceWithValidateConfig
- type Deferred
- type DeferredReason
- type MetadataRequest
- type MetadataResponse
- type ReadClientCapabilities
- type ReadRequest
- type ReadResponse
- type SchemaRequest
- type SchemaResponse
- type ValidateConfigRequest
- type ValidateConfigResponse
Constants¶
This section is empty.
Variables¶
This section is empty.
Functions¶
This section is empty.
Types¶
typeConfigValidator¶
type ConfigValidator interface {// Description describes the validation in plain text formatting.//// This information may be automatically added to data source plain text// descriptions by external tooling.Description(context.Context)string// MarkdownDescription describes the validation in Markdown formatting.//// This information may be automatically added to data source Markdown// descriptions by external tooling.MarkdownDescription(context.Context)string// ValidateDataSource performs the validation.//// This method name is separate from ConfigValidators in resource and other packages in// order to allow generic validators.ValidateDataSource(context.Context,ValidateConfigRequest, *ValidateConfigResponse)}ConfigValidator describes reusable data source configuration validation functionality.
typeConfigureRequest¶added inv0.12.0
type ConfigureRequest struct {// ProviderData is the data set in the// [provider.ConfigureResponse.DataSourceData] field. This data is// provider-specifc and therefore can contain any necessary remote system// clients, custom provider data, or anything else pertinent to the// functionality of the DataSource.//// This data is only set after the ConfigureProvider RPC has been called// by Terraform.ProviderDataany}ConfigureRequest represents a request for the provider to configure a datasource, i.e., set provider-level data or clients. An instance of thisrequest struct is supplied as an argument to the DataSource type Configuremethod.
typeConfigureResponse¶added inv0.12.0
type ConfigureResponse struct {// Diagnostics report errors or warnings related to configuring of the// Datasource. An empty slice indicates a successful operation with no// warnings or errors generated.Diagnosticsdiag.Diagnostics}ConfigureResponse represents a response to a ConfigureRequest. Aninstance of this response struct is supplied as an argument to theDataSource type Configure method.
typeDataSource¶
type DataSource interface {// Metadata should return the full name of the data source, such as// examplecloud_thing.Metadata(context.Context,MetadataRequest, *MetadataResponse)// Schema should return the schema for this data source.Schema(context.Context,SchemaRequest, *SchemaResponse)// 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)}DataSource represents an instance of a data source type. This is the coreinterface that all data sources must implement.
Data sources can optionally implement these additional concepts:
- Configure: Include provider-level data or clients.
- Validation: Schema-based or entire configurationvia DataSourceWithConfigValidators or DataSourceWithValidateConfig.
typeDataSourceWithConfigValidators¶
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}DataSourceWithConfigValidators is an interface type that extends DataSource to include declarative validations.
Declaring validation using this methodology simplifies implmentation ofreusable functionality. These also include descriptions, which can be usedfor automating documentation.
Validation will include ConfigValidators and ValidateConfig, if both areimplemented, in addition to any Attribute or Type validation.
typeDataSourceWithConfigure¶added inv0.12.0
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)}DataSourceWithConfigure is an interface type that extends DataSource toinclude a method which the framework will automatically call so providerdevelopers have the opportunity to setup any necessary provider-level dataor clients in the DataSource type.
This method is intended to replace the provider.DataSourceType typeNewDataSource method in a future release.
typeDataSourceWithValidateConfig¶
type DataSourceWithValidateConfig interface {DataSource// ValidateConfig performs the validation.ValidateConfig(context.Context,ValidateConfigRequest, *ValidateConfigResponse)}DataSourceWithValidateConfig is an interface type that extends DataSource to include imperative validation.
Declaring validation using this methodology simplifies one-offfunctionality that typically applies to a single data source. Anydocumentation of this functionality must be manually added into schemadescriptions.
Validation will include ConfigValidators and ValidateConfig, if both areimplemented, in addition to any Attribute or Type validation.
typeDeferred¶added inv1.9.0
type Deferred struct {// Reason is the reason for deferring the change.ReasonDeferredReason}Deferred is used to indicate to Terraform that a change needs to be deferred for a reason.
NOTE: This functionality is related to deferred action support, which is currently experimental and is subjectto change or break without warning. It is not protected by version compatibility guarantees.
typeDeferredReason¶added inv1.9.0
type DeferredReasonint32
DeferredReason represents different reasons for deferring a change.
NOTE: This functionality is related to deferred action support, which is currently experimental and is subjectto change or break without warning. It is not protected by version compatibility guarantees.
const (// DeferredReasonUnknown is used to indicate an invalid `DeferredReason`.// Provider developers should not use it.DeferredReasonUnknownDeferredReason = 0// DeferredReasonDataSourceConfigUnknown is used to indicate that the resource configuration// is partially unknown and the real values need to be known before the change can be planned.DeferredReasonDataSourceConfigUnknownDeferredReason = 1// DeferredReasonProviderConfigUnknown is used to indicate that the provider configuration// is partially unknown and the real values need to be known before the change can be planned.DeferredReasonProviderConfigUnknownDeferredReason = 2// DeferredReasonAbsentPrereq is used to indicate that a hard dependency has not been satisfied.DeferredReasonAbsentPrereqDeferredReason = 3)
func (DeferredReason)String¶added inv1.9.0
func (dDeferredReason) String()string
typeMetadataRequest¶added inv0.12.0
type MetadataRequest struct {// ProviderTypeName is the string returned from// [provider.MetadataResponse.TypeName], if the Provider type implements// the Metadata method. This string should prefix the DataSource type name// with an underscore in the response.ProviderTypeNamestring}MetadataRequest represents a request for the DataSource to return metadata,such as its type name. An instance of this request struct is supplied as anargument to the DataSource type Metadata method.
typeMetadataResponse¶added inv0.12.0
type MetadataResponse struct {// TypeName should be the full data source type, including the provider// type prefix and an underscore. For example, examplecloud_thing.TypeNamestring}MetadataResponse represents a response to a MetadataRequest. Aninstance of this response struct is supplied as an argument to theDataSource type Metadata method.
typeReadClientCapabilities¶added inv1.9.0
type ReadClientCapabilities struct {// DeferralAllowed indicates whether the Terraform client initiating// the request allows a deferral response.//// NOTE: This functionality is related to deferred action support, which is currently experimental and is subject// to change or break without warning. It is not protected by version compatibility guarantees.DeferralAllowedbool}ReadClientCapabilities allows Terraform to publish informationregarding optionally supported protocol features for the ReadDataSource RPC,such as forward-compatible Terraform behavior changes.
typeReadRequest¶
type ReadRequest struct {// Config is the configuration the user supplied for the data source.//// This configuration may contain unknown values if a user uses// interpolation or other functionality that would prevent Terraform// from knowing the value at request time.Configtfsdk.Config// ProviderMeta is metadata from the provider_meta block of the module.ProviderMetatfsdk.Config// ClientCapabilities defines optionally supported protocol features for the// ReadDataSource RPC, such as forward-compatible Terraform behavior changes.ClientCapabilitiesReadClientCapabilities}ReadRequest represents a request for the provider to read a datasource, i.e., update values in state according to the real state of thedata source. An instance of this request struct is supplied as an argumentto the data source's Read function.
typeReadResponse¶
type ReadResponse struct {// State is the state of the data source following the Read operation.// This field should be set during the resource's Read operation.Statetfsdk.State// Diagnostics report errors or warnings related to reading the data// source. An empty slice indicates a successful operation with no// warnings or errors generated.Diagnosticsdiag.Diagnostics// Deferred indicates that Terraform should defer reading this// data source until a followup apply operation.//// This field can only be set if// `(datasource.ReadRequest).ClientCapabilities.DeferralAllowed` is true.//// NOTE: This functionality is related to deferred action support, which is currently experimental and is subject// to change or break without warning. It is not protected by version compatibility guarantees.Deferred *Deferred}ReadResponse represents a response to a ReadRequest. Aninstance of this response struct is supplied as an argument to the datasource's Read function, in which the provider should set values on theReadResponse as appropriate.
typeSchemaRequest¶added inv0.17.0
type SchemaRequest struct{}SchemaRequest represents a request for the DataSource to return its schema.An instance of this request struct is supplied as an argument to theDataSource type Schema method.
typeSchemaResponse¶added inv0.17.0
type SchemaResponse struct {// Schema is the schema of the data source.Schemaschema.Schema// Diagnostics report errors or warnings related to validating the data// source configuration. An empty slice indicates success, with no warnings// or errors generated.Diagnosticsdiag.Diagnostics}SchemaResponse represents a response to a SchemaRequest. An instance of thisresponse struct is supplied as an argument to the DataSource type Schemamethod.
typeValidateConfigRequest¶
type ValidateConfigRequest struct {// Config is the configuration the user supplied for the data source.//// This configuration may contain unknown values if a user uses// interpolation or other functionality that would prevent Terraform// from knowing the value at request time.Configtfsdk.Config}ValidateConfigRequest represents a request to validate theconfiguration of a data source. An instance of this request struct issupplied as an argument to the DataSource ValidateConfig receiver methodor automatically passed through to each ConfigValidator.
typeValidateConfigResponse¶
type ValidateConfigResponse struct {// Diagnostics report errors or warnings related to validating the data// source configuration. An empty slice indicates success, with no warnings// or errors generated.Diagnosticsdiag.Diagnostics}ValidateConfigResponse represents a response to aValidateConfigRequest. An instance of this response struct issupplied as an argument to the DataSource ValidateConfig receiver methodor automatically passed through to each ConfigValidator.