tfsdk

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2021 License: MPL-2.0 Imports: 10 Imported by: 150

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewProtocol6Server added in v0.2.0

func NewProtocol6Server(p Provider) tfprotov6.ProviderServer

NewProtocol6Server returns a tfprotov6.ProviderServer implementation based on the passed Provider implementation.

func Serve

func Serve(ctx context.Context, factory func() Provider, opts ServeOpts) error

Serve serves a provider, blocking until the context is canceled.

Types

type Config

type Config struct {
	Raw    tftypes.Value
	Schema schema.Schema
}

Config represents a Terraform config.

func (Config) Get

func (c Config) Get(ctx context.Context, target interface{}) error

Get populates the struct passed as `target` with the entire config.

func (Config) GetAttribute

func (c Config) GetAttribute(ctx context.Context, path *tftypes.AttributePath) (attr.Value, error)

GetAttribute retrieves the attribute found at `path` and returns it as an attr.Value. Consumers should assert the type of the returned value with the desired attr.Type.

type ConfigureProviderRequest

type ConfigureProviderRequest struct {
	// TerraformVersion is the version of Terraform executing the request.
	// This is supplied for logging, analytics, and User-Agent purposes
	// only. Providers should not try to gate provider behavior on
	// Terraform versions.
	TerraformVersion string

	// Config is the configuration the user supplied for the provider. This
	// information should usually be persisted to the underlying type
	// that's implementing the Provider interface, for use in later
	// resource CRUD operations.
	Config Config
}

ConfigureProviderRequest represents a request containing the values the user specified for the provider configuration block, along with other runtime information from Terraform or the Plugin SDK. An instance of this request struct is supplied as an argument to the provider's Configure function.

type ConfigureProviderResponse

type ConfigureProviderResponse struct {
	// Diagnostics report errors or warnings related to configuring the
	// provider. An empty slice indicates success, with no warnings or
	// errors generated.
	Diagnostics []*tfprotov6.Diagnostic
}

ConfigureProviderResponse represents a response to a ConfigureProviderRequest. An instance of this response struct is supplied as an argument to the provider's Configure function, in which the provider should set values on the ConfigureProviderResponse as appropriate.

func (*ConfigureProviderResponse) AddAttributeError

func (r *ConfigureProviderResponse) AddAttributeError(attributePath *tftypes.AttributePath, summary, detail string)

AddAttributeError appends an error diagnostic to the response and labels it with a specific attribute.

func (*ConfigureProviderResponse) AddAttributeWarning

func (r *ConfigureProviderResponse) AddAttributeWarning(attributePath *tftypes.AttributePath, summary, detail string)

AddAttributeWarning appends a warning diagnostic to the response and labels it with a specific attribute.

func (*ConfigureProviderResponse) AddError

func (r *ConfigureProviderResponse) AddError(summary, detail string)

AddError appends an error diagnostic to the response. If the error concerns a particular attribute, AddAttributeError should be used instead.

func (*ConfigureProviderResponse) AddWarning

func (r *ConfigureProviderResponse) AddWarning(summary, detail string)

AddWarning appends a warning diagnostic to the response. If the warning concerns a particular attribute, AddAttributeWarning should be used instead.

type CreateResourceRequest

type CreateResourceRequest struct {
	// Config is the configuration the user supplied for the resource.
	//
	// 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.
	Config Config

	// Plan is the planned state for the resource.
	Plan Plan

	// ProviderMeta is metadata from the provider_meta block of the module.
	ProviderMeta Config
}

CreateResourceRequest represents a request for the provider to create a resource. An instance of this request struct is supplied as an argument to the resource's Create function.

type CreateResourceResponse

type CreateResourceResponse struct {
	// State is the state of the resource following the Create operation.
	// This field is pre-populated from CreateResourceRequest.Plan and
	// should be set during the resource's Create operation.
	State State

	// Diagnostics report errors or warnings related to creating the
	// resource. An empty slice indicates a successful operation with no
	// warnings or errors generated.
	Diagnostics []*tfprotov6.Diagnostic
}

CreateResourceResponse represents a response to a CreateResourceRequest. An instance of this response struct is supplied as an argument to the resource's Create function, in which the provider should set values on the CreateResourceResponse as appropriate.

func (*CreateResourceResponse) AddAttributeError

func (r *CreateResourceResponse) AddAttributeError(attributePath *tftypes.AttributePath, summary, detail string)

AddAttributeError appends an error diagnostic to the response and labels it with a specific attribute.

func (*CreateResourceResponse) AddAttributeWarning

func (r *CreateResourceResponse) AddAttributeWarning(attributePath *tftypes.AttributePath, summary, detail string)

AddAttributeWarning appends a warning diagnostic to the response and labels it with a specific attribute.

func (*CreateResourceResponse) AddError

func (r *CreateResourceResponse) AddError(summary, detail string)

AddError appends an error diagnostic to the response. If the error concerns a particular attribute, AddAttributeError should be used instead.

func (*CreateResourceResponse) AddWarning

func (r *CreateResourceResponse) AddWarning(summary, detail string)

AddWarning appends a warning diagnostic to the response. If the warning concerns a particular attribute, AddAttributeWarning should be used instead.

type DataSource

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
	// ReadDataSourceRequest and new state values set on the
	// ReadDataSourceResponse.
	Read(context.Context, ReadDataSourceRequest, *ReadDataSourceResponse)
}

DataSource implements a data source instance.

type DataSourceType

type DataSourceType interface {
	// GetSchema returns the schema for this data source.
	GetSchema(context.Context) (schema.Schema, []*tfprotov6.Diagnostic)

	// NewDataSource instantiates a new DataSource of this DataSourceType.
	NewDataSource(context.Context, Provider) (DataSource, []*tfprotov6.Diagnostic)
}

A DataSourceType is a type of data source. For each type of data source this provider supports, it should define a type implementing DataSourceType and return an instance of it in the map returned by Provider.GetDataSources.

type DeleteResourceRequest

type DeleteResourceRequest struct {
	// State is the current state of the resource prior to the Delete
	// operation.
	State State

	// ProviderMeta is metadata from the provider_meta block of the module.
	ProviderMeta Config
}

DeleteResourceRequest represents a request for the provider to delete a resource. An instance of this request struct is supplied as an argument to the resource's Delete function.

type DeleteResourceResponse

type DeleteResourceResponse struct {
	// State is the state of the resource following the Delete operation.
	// This field is pre-populated from UpdateResourceRequest.Plan and
	// should be set during the resource's Update operation.
	State State

	// Diagnostics report errors or warnings related to deleting the
	// resource. An empty slice indicates a successful operation with no
	// warnings or errors generated.
	Diagnostics []*tfprotov6.Diagnostic
}

DeleteResourceResponse represents a response to a DeleteResourceRequest. An instance of this response struct is supplied as an argument to the resource's Delete function, in which the provider should set values on the DeleteResourceResponse as appropriate.

func (*DeleteResourceResponse) AddAttributeError

func (r *DeleteResourceResponse) AddAttributeError(attributePath *tftypes.AttributePath, summary, detail string)

AddAttributeError appends an error diagnostic to the response and labels it with a specific attribute.

func (*DeleteResourceResponse) AddAttributeWarning

func (r *DeleteResourceResponse) AddAttributeWarning(attributePath *tftypes.AttributePath, summary, detail string)

AddAttributeWarning appends a warning diagnostic to the response and labels it with a specific attribute.

func (*DeleteResourceResponse) AddError

func (r *DeleteResourceResponse) AddError(summary, detail string)

AddError appends an error diagnostic to the response. If the error concerns a particular attribute, AddAttributeError should be used instead.

func (*DeleteResourceResponse) AddWarning

func (r *DeleteResourceResponse) AddWarning(summary, detail string)

AddWarning appends a warning diagnostic to the response. If the warning concerns a particular attribute, AddAttributeWarning should be used instead.

type Plan

type Plan struct {
	Raw    tftypes.Value
	Schema schema.Schema
}

Plan represents a Terraform plan.

func (Plan) Get

func (p Plan) Get(ctx context.Context, target interface{}) error

Get populates the struct passed as `target` with the entire plan.

func (Plan) GetAttribute

func (p Plan) GetAttribute(ctx context.Context, path *tftypes.AttributePath) (attr.Value, error)

GetAttribute retrieves the attribute found at `path` and returns it as an attr.Value. Consumers should assert the type of the returned value with the desired attr.Type.

func (*Plan) Set

func (p *Plan) Set(ctx context.Context, val interface{}) error

Set populates the entire plan using the supplied Go value. The value `val` should be a struct whose values have one of the attr.Value types. Each field must be tagged with the corresponding schema field.

func (*Plan) SetAttribute

func (p *Plan) SetAttribute(ctx context.Context, path *tftypes.AttributePath, val interface{}) error

SetAttribute sets the attribute at `path` using the supplied Go value.

type Provider

type Provider interface {
	// GetSchema returns the schema for this provider's configuration. If
	// this provider has no configuration, return an empty schema.Schema.
	GetSchema(context.Context) (schema.Schema, []*tfprotov6.Diagnostic)

	// Configure is called at the beginning of the provider lifecycle, when
	// Terraform sends to the provider the values the user specified in the
	// provider configuration block. These are supplied in the
	// ConfigureProviderRequest argument.
	// Values from provider configuration are often used to initialise an
	// API client, which should be stored on the struct implementing the
	// Provider interface.
	Configure(context.Context, ConfigureProviderRequest, *ConfigureProviderResponse)

	// GetResources returns a map of the resource types this provider
	// supports.
	GetResources(context.Context) (map[string]ResourceType, []*tfprotov6.Diagnostic)

	// GetDataSources returns a map of the data source types this provider
	// supports.
	GetDataSources(context.Context) (map[string]DataSourceType, []*tfprotov6.Diagnostic)
}

Provider is the core interface that all Terraform providers must implement.

type ProviderWithProviderMeta

type ProviderWithProviderMeta interface {
	Provider
	// GetMetaSchema returns the provider meta schema.
	GetMetaSchema(context.Context) (schema.Schema, []*tfprotov6.Diagnostic)
}

ProviderWithProviderMeta is a provider with a provider meta schema. This functionality is currently experimental and subject to change or break without warning; it should only be used by providers that are collaborating on its use with the Terraform team.

type ReadDataSourceRequest

type ReadDataSourceRequest 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.
	Config Config

	// ProviderMeta is metadata from the provider_meta block of the module.
	ProviderMeta Config
}

ReadDataSourceRequest represents a request for the provider to read a data source, i.e., update values in state according to the real state of the data source. An instance of this request struct is supplied as an argument to the data source's Read function.

type ReadDataSourceResponse

type ReadDataSourceResponse struct {
	// State is the state of the data source following the Read operation.
	// This field should be set during the resource's Read operation.
	State 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.
	Diagnostics []*tfprotov6.Diagnostic
}

ReadDataSourceResponse represents a response to a ReadDataSourceRequest. An instance of this response struct is supplied as an argument to the data source's Read function, in which the provider should set values on the ReadDataSourceResponse as appropriate.

type ReadResourceRequest

type ReadResourceRequest struct {
	// State is the current state of the resource prior to the Read
	// operation.
	State State

	// ProviderMeta is metadata from the provider_meta block of the module.
	ProviderMeta Config
}

ReadResourceRequest represents a request for the provider to read a resource, i.e., update values in state according to the real state of the resource. An instance of this request struct is supplied as an argument to the resource's Read function.

type ReadResourceResponse

type ReadResourceResponse struct {
	// State is the state of the resource following the Read operation.
	// This field is pre-populated from ReadResourceRequest.State and
	// should be set during the resource's Read operation.
	State State

	// Diagnostics report errors or warnings related to reading the
	// resource. An empty slice indicates a successful operation with no
	// warnings or errors generated.
	Diagnostics []*tfprotov6.Diagnostic
}

ReadResourceResponse represents a response to a ReadResourceRequest. An instance of this response struct is supplied as an argument to the resource's Read function, in which the provider should set values on the ReadResourceResponse as appropriate.

func (*ReadResourceResponse) AddAttributeError

func (r *ReadResourceResponse) AddAttributeError(attributePath *tftypes.AttributePath, summary, detail string)

AddAttributeError appends an error diagnostic to the response and labels it with a specific attribute.

func (*ReadResourceResponse) AddAttributeWarning

func (r *ReadResourceResponse) AddAttributeWarning(attributePath *tftypes.AttributePath, summary, detail string)

AddAttributeWarning appends a warning diagnostic to the response and labels it with a specific attribute.

func (*ReadResourceResponse) AddError

func (r *ReadResourceResponse) AddError(summary, detail string)

AddError appends an error diagnostic to the response. If the error concerns a particular attribute, AddAttributeError should be used instead.

func (*ReadResourceResponse) AddWarning

func (r *ReadResourceResponse) AddWarning(summary, detail string)

AddWarning appends a warning diagnostic to the response. If the warning concerns a particular attribute, AddAttributeWarning should be used instead.

type Resource

type Resource interface {
	// Create is called when the provider must create a new resource. Config
	// and planned state values should be read from the
	// CreateResourceRequest and new state values set on the
	// CreateResourceResponse.
	Create(context.Context, CreateResourceRequest, *CreateResourceResponse)

	// Read is called when the provider must read resource values in order
	// to update state. Planned state values should be read from the
	// ReadResourceRequest and new state values set on the
	// ReadResourceResponse.
	Read(context.Context, ReadResourceRequest, *ReadResourceResponse)

	// Update is called to update the state of the resource. Config, planned
	// state, and prior state values should be read from the
	// UpdateResourceRequest and new state values set on the
	// UpdateResourceResponse.
	Update(context.Context, UpdateResourceRequest, *UpdateResourceResponse)

	// Delete is called when the provider must delete the resource. Config
	// values may be read from the DeleteResourceRequest.
	Delete(context.Context, DeleteResourceRequest, *DeleteResourceResponse)
}

Resource represents a resource instance. This is the core interface that all resources must implement.

type ResourceType

type ResourceType interface {
	// GetSchema returns the schema for this resource.
	GetSchema(context.Context) (schema.Schema, []*tfprotov6.Diagnostic)

	// NewResource instantiates a new Resource of this ResourceType.
	NewResource(context.Context, Provider) (Resource, []*tfprotov6.Diagnostic)
}

A ResourceType is a type of resource. For each type of resource this provider supports, it should define a type implementing ResourceType and return an instance of it in the map returned by Provider.GeResources.

type ServeOpts

type ServeOpts struct {
	// Name is the name of the provider, in full address form. For example:
	// registry.terraform.io/hashicorp/random.
	Name string
}

ServeOpts are options for serving the provider.

type State

type State struct {
	Raw    tftypes.Value
	Schema schema.Schema
}

State represents a Terraform state.

func (State) Get

func (s State) Get(ctx context.Context, target interface{}) error

Get populates the struct passed as `target` with the entire state.

func (State) GetAttribute

func (s State) GetAttribute(ctx context.Context, path *tftypes.AttributePath) (attr.Value, error)

GetAttribute retrieves the attribute found at `path` and returns it as an attr.Value. Consumers should assert the type of the returned value with the desired attr.Type.

func (*State) RemoveResource

func (s *State) RemoveResource(ctx context.Context)

RemoveResource removes the entire resource from state.

func (*State) Set

func (s *State) Set(ctx context.Context, val interface{}) error

Set populates the entire state using the supplied Go value. The value `val` should be a struct whose values have one of the attr.Value types. Each field must be tagged with the corresponding schema field.

func (*State) SetAttribute

func (s *State) SetAttribute(ctx context.Context, path *tftypes.AttributePath, val interface{}) error

SetAttribute sets the attribute at `path` using the supplied Go value.

type UpdateResourceRequest

type UpdateResourceRequest struct {
	// Config is the configuration the user supplied for the resource.
	//
	// 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.
	Config Config

	// Plan is the planned state for the resource.
	Plan Plan

	// State is the current state of the resource prior to the Update
	// operation.
	State State

	// ProviderMeta is metadata from the provider_meta block of the module.
	ProviderMeta Config
}

UpdateResourceRequest represents a request for the provider to update a resource. An instance of this request struct is supplied as an argument to the resource's Update function.

type UpdateResourceResponse

type UpdateResourceResponse struct {
	// State is the state of the resource following the Update operation.
	// This field is pre-populated from UpdateResourceRequest.Plan and
	// should be set during the resource's Update operation.
	State State

	// Diagnostics report errors or warnings related to updating the
	// resource. An empty slice indicates a successful operation with no
	// warnings or errors generated.
	Diagnostics []*tfprotov6.Diagnostic
}

UpdateResourceResponse represents a response to an UpdateResourceRequest. An instance of this response struct is supplied as an argument to the resource's Update function, in which the provider should set values on the UpdateResourceResponse as appropriate.

func (*UpdateResourceResponse) AddAttributeError

func (r *UpdateResourceResponse) AddAttributeError(attributePath *tftypes.AttributePath, summary, detail string)

AddAttributeError appends an error diagnostic to the response and labels it with a specific attribute.

func (*UpdateResourceResponse) AddAttributeWarning

func (r *UpdateResourceResponse) AddAttributeWarning(attributePath *tftypes.AttributePath, summary, detail string)

AddAttributeWarning appends a warning diagnostic to the response and labels it with a specific attribute.

func (*UpdateResourceResponse) AddError

func (r *UpdateResourceResponse) AddError(summary, detail string)

AddError appends an error diagnostic to the response. If the error concerns a particular attribute, AddAttributeError should be used instead.

func (*UpdateResourceResponse) AddWarning

func (r *UpdateResourceResponse) AddWarning(summary, detail string)

AddWarning appends a warning diagnostic to the response. If the warning concerns a particular attribute, AddAttributeWarning should be used instead.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL