tfsdk

package
Version: v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2022 License: MPL-2.0 Imports: 14 Imported by: 52

Documentation

Overview

Package tfsdk contains core framework functionality for schemas and schema data.

Index

Constants

View Source
const (
	BlockNestingModeList   = fwschema.BlockNestingModeList
	BlockNestingModeSet    = fwschema.BlockNestingModeSet
	BlockNestingModeSingle = fwschema.BlockNestingModeSingle
)

Variables

View Source
var (
	// ErrPathInsideAtomicAttribute is used with AttributeAtPath is called
	// on a path that doesn't have a schema associated with it, because
	// it's an element, attribute, or block of a complex type, not a nested
	// attribute.
	ErrPathInsideAtomicAttribute = errors.New("path leads to element, attribute, or block of a schema.Attribute that has no schema associated with it")

	// ErrPathIsBlock is used with AttributeAtPath is called on a path is a
	// block, not an attribute. Use blockAtPath on the path instead.
	ErrPathIsBlock = errors.New("path leads to block, not an attribute")
)

Functions

func ConvertValue added in v0.4.0

func ConvertValue(ctx context.Context, val attr.Value, typ attr.Type) (attr.Value, diag.Diagnostics)

ConvertValue creates a new attr.Value of the attr.Type `typ`, using the data in `val`, which can be of any attr.Type so long as its TerraformType method returns a tftypes.Type that `typ`'s ValueFromTerraform method can accept.

func ListNestedAttributes added in v0.3.0

func ListNestedAttributes(attributes map[string]Attribute) fwschema.NestedAttributes

ListNestedAttributes nests `attributes` under another attribute, allowing multiple instances of that group of attributes to appear in the configuration.

func MapNestedAttributes added in v0.3.0

func MapNestedAttributes(attributes map[string]Attribute) fwschema.NestedAttributes

MapNestedAttributes nests `attributes` under another attribute, allowing multiple instances of that group of attributes to appear in the configuration. Each group will need to be associated with a unique string by the user.

func SetNestedAttributes added in v0.3.0

func SetNestedAttributes(attributes map[string]Attribute) fwschema.NestedAttributes

SetNestedAttributes nests `attributes` under another attribute, allowing multiple instances of that group of attributes to appear in the configuration, while requiring each group of values be unique.

func SingleNestedAttributes added in v0.3.0

func SingleNestedAttributes(attributes map[string]Attribute) fwschema.NestedAttributes

SingleNestedAttributes nests `attributes` under another attribute, only allowing one instance of that group of attributes to appear in the configuration.

func ValueAs added in v0.3.0

func ValueAs(ctx context.Context, val attr.Value, target interface{}) diag.Diagnostics

ValueAs takes the attr.Value `val` and populates the Go value `target` with its content.

This is achieved using reflection rules provided by the internal/reflect package.

func ValueFrom added in v0.9.0

func ValueFrom(ctx context.Context, val interface{}, targetType attr.Type, target interface{}) diag.Diagnostics

ValueFrom takes the Go value `val` and populates `target` with an attr.Value, based on the type definition provided in `targetType`.

This is achieved using reflection rules provided by the internal/reflect package.

Types

type Attribute added in v0.3.0

type Attribute struct {
	// Type indicates what kind of attribute this is. You'll most likely
	// want to use one of the types in the types package.
	//
	// If Type is set, Attributes cannot be.
	Type attr.Type

	// Attributes can have their own, nested attributes. This nested map of
	// attributes behaves exactly like the map of attributes on the Schema
	// type.
	//
	// If Attributes is set, Type cannot be.
	Attributes fwschema.NestedAttributes

	// Description is used in various tooling, like the language server, to
	// give practitioners more information about what this attribute is,
	// what it's for, and how it should be used. It should be written as
	// plain text, with no special formatting.
	Description string

	// MarkdownDescription is used in various tooling, like the
	// documentation generator, to give practitioners more information
	// about what this attribute is, what it's for, and how it should be
	// used. It should be formatted using Markdown.
	MarkdownDescription string

	// Required indicates whether the practitioner must enter a value for
	// this attribute or not. Required and Optional cannot both be true,
	// and Required and Computed cannot both be true.
	Required bool

	// Optional indicates whether the practitioner can choose not to enter
	// a value for this attribute or not. Optional and Required cannot both
	// be true.
	//
	// When defining an attribute that has Optional set to true,
	// and uses PlanModifiers to set a "default value" when none is provided,
	// Computed must also be set to true. This is necessary because default
	// values are, in effect, set by the provider (i.e. computed).
	Optional bool

	// Computed indicates whether the provider may return its own value for
	// this Attribute or not. Required and Computed cannot both be true. If
	// Required and Optional are both false, Computed must be true, and the
	// attribute will be considered "read only" for the practitioner, with
	// only the provider able to set its value.
	//
	// When defining an Optional Attribute that has a "default value"
	// plan modifier, Computed must also be set to true. Otherwise,
	// Terraform will return an error like:
	//
	//      planned value ... for a non-computed attribute
	//
	Computed bool

	// Sensitive indicates whether the value of this attribute should be
	// considered sensitive data. Setting it to true will obscure the value
	// in CLI output. Sensitive does not impact how values are stored, and
	// practitioners are encouraged to store their state as if the entire
	// file is sensitive.
	Sensitive bool

	// DeprecationMessage defines warning diagnostic details to display when
	// practitioner configurations use this Attribute. The warning diagnostic
	// summary is automatically set to "Attribute Deprecated" along with
	// configuration source file and line information.
	//
	// Set this field to a practitioner actionable message such as:
	//
	//  - "Configure other_attribute instead. This attribute will be removed
	//    in the next major version of the provider."
	//  - "Remove this attribute's configuration as it no longer is used and
	//    the attribute will be removed in the next major version of the
	//    provider."
	//
	// In Terraform 1.2.7 and later, this warning diagnostic is displayed any
	// time a practitioner attempts to configure a value for this attribute and
	// certain scenarios where this attribute is referenced.
	//
	// In Terraform 1.2.6 and earlier, this warning diagnostic is only
	// displayed when the Attribute is Required or Optional, and if the
	// practitioner configuration sets the value to a known or unknown value
	// (which may eventually be null). It has no effect when the Attribute is
	// Computed-only (read-only; not Required or Optional).
	//
	// Across any Terraform version, there are no warnings raised for
	// practitioner configuration values set directly to null, as there is no
	// way for the framework to differentiate between an unset and null
	// configuration due to how Terraform sends configuration information
	// across the protocol.
	//
	// Additional information about deprecation enhancements for read-only
	// attributes can be found in:
	//
	//  - https://github.com/hashicorp/terraform/issues/7569
	//
	DeprecationMessage string

	// Validators define value validation functionality for the attribute. All
	// elements of the slice of AttributeValidator are run, regardless of any
	// previous error diagnostics.
	//
	// Many common use case validators can be found in the
	// github.com/hashicorp/terraform-plugin-framework-validators Go module.
	//
	// If the Type field points to a custom type that implements the
	// xattr.TypeWithValidate interface, the validators defined in this field
	// are run in addition to the validation defined by the type.
	Validators []AttributeValidator

	// PlanModifiers defines a sequence of modifiers for this attribute at
	// plan time. Attribute-level plan modifications occur before any
	// resource-level plan modifications.
	//
	// Any errors will prevent further execution of this sequence
	// of modifiers and modifiers associated with any nested Attribute, but
	// will not prevent execution of PlanModifiers on any other Attribute or
	// Block in the Schema.
	//
	// Plan modification only applies to resources, not data sources or
	// providers. Setting PlanModifiers on a data source or provider attribute
	// will have no effect.
	//
	// When providing PlanModifiers, it's necessary to set Computed to true.
	PlanModifiers AttributePlanModifiers
}

Attribute defines the constraints and behaviors of a single value field in a schema. Attributes are the fields that show up in Terraform state files and can be used in configuration files.

func (Attribute) ApplyTerraform5AttributePathStep added in v0.3.0

func (a Attribute) ApplyTerraform5AttributePathStep(step tftypes.AttributePathStep) (interface{}, error)

ApplyTerraform5AttributePathStep transparently calls ApplyTerraform5AttributePathStep on a.Type or a.Attributes, whichever is non-nil. It allows Attributes to be walked using tftypes.Walk and tftypes.Transform.

func (Attribute) Equal added in v0.3.0

func (a Attribute) Equal(o fwschema.Attribute) bool

Equal returns true if `a` and `o` should be considered Equal.

func (Attribute) FrameworkType added in v0.11.0

func (a Attribute) FrameworkType() attr.Type

FrameworkType returns the framework type, whether the direct type or nested attributes type, of the attribute.

func (Attribute) GetAttributes added in v0.11.0

func (a Attribute) GetAttributes() fwschema.NestedAttributes

GetAttributes satisfies the fwschema.Attribute interface.

func (Attribute) GetDeprecationMessage added in v0.11.0

func (a Attribute) GetDeprecationMessage() string

GetDeprecationMessage satisfies the fwschema.Attribute interface.

func (Attribute) GetDescription added in v0.11.0

func (a Attribute) GetDescription() string

GetDescription satisfies the fwschema.Attribute interface.

func (Attribute) GetMarkdownDescription added in v0.11.0

func (a Attribute) GetMarkdownDescription() string

GetMarkdownDescription satisfies the fwschema.Attribute interface.

func (Attribute) GetPlanModifiers added in v0.11.0

func (a Attribute) GetPlanModifiers() AttributePlanModifiers

GetPlanModifiers satisfies the fwxschema.AttributeWithPlanModifiers interface.

func (Attribute) GetType added in v0.11.0

func (a Attribute) GetType() attr.Type

GetType satisfies the fwschema.Attribute interface.

func (Attribute) GetValidators added in v0.11.0

func (a Attribute) GetValidators() []AttributeValidator

GetValidators satisfies the fwxschema.AttributeWithValidators interface.

func (Attribute) IsComputed added in v0.11.0

func (a Attribute) IsComputed() bool

IsComputed satisfies the fwschema.Attribute interface.

func (Attribute) IsOptional added in v0.11.0

func (a Attribute) IsOptional() bool

IsOptional satisfies the fwschema.Attribute interface.

func (Attribute) IsRequired added in v0.11.0

func (a Attribute) IsRequired() bool

IsRequired satisfies the fwschema.Attribute interface.

func (Attribute) IsSensitive added in v0.11.0

func (a Attribute) IsSensitive() bool

IsSensitive satisfies the fwschema.Attribute interface.

type AttributePlanModifier added in v0.3.0

type AttributePlanModifier interface {
	// Description is used in various tooling, like the language server, to
	// give practitioners more information about what this modifier is,
	// what it's for, and how it should be used. It should be written as
	// plain text, with no special formatting.
	Description(context.Context) string

	// MarkdownDescription is used in various tooling, like the
	// documentation generator, to give practitioners more information
	// about what this modifier is, what it's for, and how it should be
	// used. It should be formatted using Markdown.
	MarkdownDescription(context.Context) string

	// Modify is called when the provider has an opportunity to modify
	// the plan: once during the plan phase when Terraform is determining
	// the diff that should be shown to the user for approval, and once
	// during the apply phase with any unknown values from configuration
	// filled in with their final values.
	//
	// The Modify function has access to the config, state, and plan for
	// both the attribute in question and the entire resource, but it can
	// only modify the value of the one attribute.
	//
	// Any returned errors will stop further execution of plan modifications
	// for this Attribute and any nested Attribute. Other Attribute at the same
	// or higher levels of the Schema will still execute any plan modifications
	// to ensure all warnings and errors across all root Attribute are
	// captured.
	//
	// Please see the documentation for ResourceWithModifyPlan#ModifyPlan
	// for further details.
	Modify(context.Context, ModifyAttributePlanRequest, *ModifyAttributePlanResponse)
}

AttributePlanModifier represents a modifier for an attribute at plan time. An AttributePlanModifier can only modify the planned value for the attribute on which it is defined. For plan-time modifications that modify the values of several attributes at once, please instead use the ResourceWithModifyPlan interface by defining a ModifyPlan function on the resource.

type AttributePlanModifiers added in v0.3.0

type AttributePlanModifiers []AttributePlanModifier

AttributePlanModifiers represents a sequence of AttributePlanModifiers, in order.

type AttributeValidator added in v0.3.0

type AttributeValidator interface {
	// Description describes the validation in plain text formatting.
	//
	// This information may be automatically added to schema plain text
	// descriptions by external tooling.
	Description(context.Context) string

	// MarkdownDescription describes the validation in Markdown formatting.
	//
	// This information may be automatically added to schema Markdown
	// descriptions by external tooling.
	MarkdownDescription(context.Context) string

	// Validate performs the validation.
	Validate(context.Context, ValidateAttributeRequest, *ValidateAttributeResponse)
}

AttributeValidator describes reusable Attribute validation functionality.

type Block added in v0.5.0

type Block struct {
	// Attributes are value fields inside the block. This map of attributes
	// behaves exactly like the map of attributes on the Schema type.
	Attributes map[string]Attribute

	// Blocks can have their own nested blocks. This nested map of blocks
	// behaves exactly like the map of blocks on the Schema type.
	Blocks map[string]Block

	// DeprecationMessage defines warning diagnostic details to display to
	// practitioners configuring this Block. The warning diagnostic summary
	// is automatically set to "Block Deprecated" along with configuration
	// source file and line information.
	//
	// This warning diagnostic is only displayed during Terraform's validation
	// phase when this field is a non-empty string and if the practitioner
	// configuration attempts to set the block value to a known or unknown
	// value (which may eventually be null).
	//
	// Set this field to a practitioner actionable message such as:
	//
	//     - "Configure other_attribute instead. This block will be removed
	//       in the next major version of the provider."
	//     - "Remove this block's configuration as it no longer is used and
	//       the block will be removed in the next major version of the
	//       provider."
	//
	DeprecationMessage string

	// Description is used in various tooling, like the language server, to
	// give practitioners more information about what this attribute is,
	// what it's for, and how it should be used. It should be written as
	// plain text, with no special formatting.
	Description string

	// MarkdownDescription is used in various tooling, like the
	// documentation generator, to give practitioners more information
	// about what this attribute is, what it's for, and how it should be
	// used. It should be formatted using Markdown.
	MarkdownDescription string

	// MaxItems is the maximum number of blocks that can be present in a
	// practitioner configuration.
	MaxItems int64

	// MinItems is the minimum number of blocks that must be present in a
	// practitioner configuration. Setting to 1 or above effectively marks
	// this configuration as required.
	MinItems int64

	// NestingMode indicates the block kind. This field must be set or a
	// runtime error will be raised by the framework when fetching the schema.
	NestingMode fwschema.BlockNestingMode

	// PlanModifiers defines a sequence of modifiers for this block at
	// plan time. Block-level plan modifications occur before any
	// resource-level plan modifications.
	//
	// Any errors will prevent further execution of this sequence
	// of modifiers and modifiers associated with any nested Attribute or
	// Block, but will not prevent execution of PlanModifiers on any
	// other Attribute or Block in the Schema.
	//
	// Plan modification only applies to resources, not data sources or
	// providers. Setting PlanModifiers on a data source or provider attribute
	// will have no effect.
	PlanModifiers AttributePlanModifiers

	// Validators defines validation functionality for the block.
	Validators []AttributeValidator
}

Block defines the constraints and behaviors of a single structural field in a schema.

The NestingMode field must be set or a runtime error will be raised by the framework when fetching the schema.

func (Block) ApplyTerraform5AttributePathStep added in v0.5.0

func (b Block) ApplyTerraform5AttributePathStep(step tftypes.AttributePathStep) (interface{}, error)

ApplyTerraform5AttributePathStep allows Blocks to be walked using tftypes.Walk and tftypes.Transform.

func (Block) Equal added in v0.5.0

func (b Block) Equal(o fwschema.Block) bool

Equal returns true if `b` and `o` should be considered Equal.

func (Block) GetAttributes added in v0.11.0

func (b Block) GetAttributes() map[string]fwschema.Attribute

GetAttributes satisfies the fwschema.Block interface.

func (Block) GetBlocks added in v0.11.0

func (b Block) GetBlocks() map[string]fwschema.Block

GetBlocks satisfies the fwschema.Block interface.

func (Block) GetDeprecationMessage added in v0.11.0

func (b Block) GetDeprecationMessage() string

GetDeprecationMessage satisfies the fwschema.Block interface.

func (Block) GetDescription added in v0.11.0

func (b Block) GetDescription() string

GetDescription satisfies the fwschema.Block interface.

func (Block) GetMarkdownDescription added in v0.11.0

func (b Block) GetMarkdownDescription() string

GetMarkdownDescription satisfies the fwschema.Block interface.

func (Block) GetMaxItems added in v0.11.0

func (b Block) GetMaxItems() int64

GetMaxItems satisfies the fwschema.Block interface.

func (Block) GetMinItems added in v0.11.0

func (b Block) GetMinItems() int64

GetMinItems satisfies the fwschema.Block interface.

func (Block) GetNestingMode added in v0.11.0

func (b Block) GetNestingMode() fwschema.BlockNestingMode

GetNestingMode satisfies the fwschema.Block interface.

func (Block) GetPlanModifiers added in v0.11.0

func (b Block) GetPlanModifiers() AttributePlanModifiers

GetPlanModifiers satisfies the fwxschema.BlockWithPlanModifiers interface.

func (Block) GetValidators added in v0.11.0

func (b Block) GetValidators() []AttributeValidator

GetValidators satisfies the fwxschema.BlockWithValidators interface.

func (Block) Type added in v0.11.0

func (b Block) Type() attr.Type

attributeType returns an attr.Type corresponding to the block.

type Config

type Config struct {
	Raw    tftypes.Value
	Schema Schema
}

Config represents a Terraform config.

func (Config) Get

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

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

func (Config) GetAttribute

func (c Config) GetAttribute(ctx context.Context, path path.Path, target interface{}) diag.Diagnostics

GetAttribute retrieves the attribute found at `path` and populates the `target` with the value.

func (Config) PathMatches added in v0.10.0

func (c Config) PathMatches(ctx context.Context, pathExpr path.Expression) (path.Paths, diag.Diagnostics)

PathMatches returns all matching path.Paths from the given path.Expression.

If a parent path is null or unknown, which would prevent a full expression from matching, the parent path is returned rather than no match to prevent false positives.

type ModifyAttributePlanRequest added in v0.3.0

type ModifyAttributePlanRequest struct {
	// AttributePath is the path of the attribute. Use this path for any
	// response diagnostics.
	AttributePath path.Path

	// AttributePathExpression is the expression matching the exact path of the
	// attribute.
	AttributePathExpression path.Expression

	// Config is the configuration the user supplied for the resource.
	Config Config

	// State is the current state of the resource.
	State State

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

	// AttributeConfig is the configuration the user supplied for the attribute.
	AttributeConfig attr.Value

	// AttributeState is the current state of the attribute.
	AttributeState attr.Value

	// AttributePlan is the planned new state for the attribute.
	AttributePlan attr.Value

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

	// Private is provider-defined resource private state data which was previously
	// stored with the resource state. This data is opaque to Terraform and does
	// not affect plan output. Any existing data is copied to
	// ModifyAttributePlanResponse.Private to prevent accidental private state data loss.
	//
	// The private state data is always the original data when the schema-based plan
	// modification began or, is updated as the logic traverses deeper into underlying
	// attributes.
	//
	// Use the GetKey method to read data. Use the SetKey method on
	// ModifyAttributePlanResponse.Private to update or remove a value.
	Private *privatestate.ProviderData
}

ModifyAttributePlanRequest represents a request for the provider to modify an attribute value, or mark it as requiring replacement, at plan time. An instance of this request struct is supplied as an argument to the Modify function of an attribute's plan modifier(s).

type ModifyAttributePlanResponse added in v0.3.0

type ModifyAttributePlanResponse struct {
	// AttributePlan is the planned new state for the attribute.
	AttributePlan attr.Value

	// RequiresReplace indicates whether a change in the attribute
	// requires replacement of the whole resource.
	RequiresReplace bool

	// Private is the private state resource data following the ModifyAttributePlan operation.
	// This field is pre-populated from ModifyAttributePlanRequest.Private and
	// can be modified during the resource's ModifyAttributePlan operation.
	//
	// The private state data is always the original data when the schema-based plan
	// modification began or, is updated as the logic traverses deeper into underlying
	// attributes.
	Private *privatestate.ProviderData

	// Diagnostics report errors or warnings related to determining the
	// planned state of the requested resource. Returning an empty slice
	// indicates a successful validation with no warnings or errors
	// generated.
	Diagnostics diag.Diagnostics
}

ModifyAttributePlanResponse represents a response to a ModifyAttributePlanRequest. An instance of this response struct is supplied as an argument to the Modify function of an attribute's plan modifier(s).

type Plan

type Plan struct {
	Raw    tftypes.Value
	Schema Schema
}

Plan represents a Terraform plan.

func (Plan) Get

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

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

func (Plan) GetAttribute

func (p Plan) GetAttribute(ctx context.Context, path path.Path, target interface{}) diag.Diagnostics

GetAttribute retrieves the attribute found at `path` and populates the `target` with the value.

func (Plan) PathMatches added in v0.10.0

func (p Plan) PathMatches(ctx context.Context, pathExpr path.Expression) (path.Paths, diag.Diagnostics)

PathMatches returns all matching path.Paths from the given path.Expression.

If a parent path is null or unknown, which would prevent a full expression from matching, the parent path is returned rather than no match to prevent false positives.

func (*Plan) Set

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

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 path.Path, val interface{}) diag.Diagnostics

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

The attribute path and value must be valid with the current schema. If the attribute path already has a value, it will be overwritten. If the attribute path does not have a value, it will be added, including any parent attribute paths as necessary.

Lists can only have the next element added according to the current length.

type Schema added in v0.3.0

type Schema struct {
	// Attributes are value fields inside the resource, provider, or data
	// source that the schema is defining. The map key should be the name
	// of the attribute, and the body defines how it behaves. Names must
	// only contain lowercase letters, numbers, and underscores. Names must
	// not collide with any Blocks names.
	//
	// In practitioner configurations, an equals sign (=) is required to set
	// the value. See also:
	//   https://www.terraform.io/docs/language/syntax/configuration.html
	//
	// Attributes are strongly preferred over Blocks.
	Attributes map[string]Attribute

	// Blocks are structural fields inside the resource, provider, or data
	// source that the schema is defining. The map key should be the name
	// of the block, and the body defines how it behaves. Names must
	// only contain lowercase letters, numbers, and underscores. Names must
	// not collide with any Attributes names.
	//
	// Blocks are by definition, structural, meaning they are implicitly
	// required in values.
	//
	// In practitioner configurations, an equals sign (=) cannot be used to
	// set the value. Blocks are instead repeated as necessary, or require
	// the use of dynamic block expressions. See also:
	//   https://www.terraform.io/docs/language/syntax/configuration.html
	//   https://www.terraform.io/docs/language/expressions/dynamic-blocks.html
	//
	// Attributes are preferred over Blocks. Blocks should typically be used
	// for configuration compatibility with previously existing schemas from
	// an older Terraform Plugin SDK. Efforts should be made to convert from
	// Blocks to Attributes as a breaking change for practitioners.
	Blocks map[string]Block

	// Version indicates the current version of the schema. Schemas are
	// versioned to help with automatic upgrade process. This is not
	// typically required unless there is a change in the schema, such as
	// changing an attribute type, that needs manual upgrade handling.
	// Versions should only be incremented by one each release.
	Version int64

	DeprecationMessage  string
	Description         string
	MarkdownDescription string
}

Schema is used to define the shape of practitioner-provider information, like resources, data sources, and providers. Think of it as a type definition, but for Terraform.

func (Schema) ApplyTerraform5AttributePathStep added in v0.3.0

func (s Schema) ApplyTerraform5AttributePathStep(step tftypes.AttributePathStep) (interface{}, error)

ApplyTerraform5AttributePathStep applies the given AttributePathStep to the schema.

func (Schema) AttributeAtPath added in v0.3.0

func (s Schema) AttributeAtPath(ctx context.Context, schemaPath path.Path) (fwschema.Attribute, diag.Diagnostics)

AttributeAtPath returns the Attribute at the passed path. If the path points to an element or attribute of a complex type, rather than to an Attribute, it will return an ErrPathInsideAtomicAttribute error.

func (Schema) AttributeAtTerraformPath added in v0.11.0

func (s Schema) AttributeAtTerraformPath(_ context.Context, path *tftypes.AttributePath) (fwschema.Attribute, error)

AttributeAtPath returns the Attribute at the passed path. If the path points to an element or attribute of a complex type, rather than to an Attribute, it will return an ErrPathInsideAtomicAttribute error.

func (Schema) GetAttributes added in v0.11.0

func (s Schema) GetAttributes() map[string]fwschema.Attribute

GetAttributes satisfies the fwschema.Schema interface.

func (Schema) GetBlocks added in v0.11.0

func (s Schema) GetBlocks() map[string]fwschema.Block

GetBlocks satisfies the fwschema.Schema interface.

func (Schema) GetDeprecationMessage added in v0.11.0

func (s Schema) GetDeprecationMessage() string

GetDeprecationMessage satisfies the fwschema.Schema interface.

func (Schema) GetDescription added in v0.11.0

func (s Schema) GetDescription() string

GetDescription satisfies the fwschema.Schema interface.

func (Schema) GetMarkdownDescription added in v0.11.0

func (s Schema) GetMarkdownDescription() string

GetMarkdownDescription satisfies the fwschema.Schema interface.

func (Schema) GetVersion added in v0.11.0

func (s Schema) GetVersion() int64

GetVersion satisfies the fwschema.Schema interface.

func (Schema) Type added in v0.11.0

func (s Schema) Type() attr.Type

Type returns the framework type of the schema.

func (Schema) TypeAtPath added in v0.11.0

func (s Schema) TypeAtPath(ctx context.Context, schemaPath path.Path) (attr.Type, diag.Diagnostics)

TypeAtPath returns the framework type at the given schema path.

func (Schema) TypeAtTerraformPath added in v0.11.0

func (s Schema) TypeAtTerraformPath(_ context.Context, path *tftypes.AttributePath) (attr.Type, error)

TypeAtTerraformPath returns the framework type at the given tftypes path.

type State

type State struct {
	Raw    tftypes.Value
	Schema Schema
}

State represents a Terraform state.

func (State) Get

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

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

func (State) GetAttribute

func (s State) GetAttribute(ctx context.Context, path path.Path, target interface{}) diag.Diagnostics

GetAttribute retrieves the attribute found at `path` and populates the `target` with the value.

func (State) PathMatches added in v0.10.0

func (s State) PathMatches(ctx context.Context, pathExpr path.Expression) (path.Paths, diag.Diagnostics)

PathMatches returns all matching path.Paths from the given path.Expression.

If a parent path is null or unknown, which would prevent a full expression from matching, the parent path is returned rather than no match to prevent false positives.

func (*State) RemoveResource

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

RemoveResource removes the entire resource from state.

If a Resource type Delete method is completed without error, this is automatically called on the DeleteResourceResponse.State.

func (*State) Set

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

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 path.Path, val interface{}) diag.Diagnostics

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

The attribute path and value must be valid with the current schema. If the attribute path already has a value, it will be overwritten. If the attribute path does not have a value, it will be added, including any parent attribute paths as necessary.

Lists can only have the next element added according to the current length.

type ValidateAttributeRequest added in v0.3.0

type ValidateAttributeRequest struct {
	// AttributePath contains the path of the attribute. Use this path for any
	// response diagnostics.
	AttributePath path.Path

	// AttributePathExpression contains the expression matching the exact path
	// of the attribute.
	AttributePathExpression path.Expression

	// AttributeConfig contains the value of the attribute in the configuration.
	AttributeConfig attr.Value

	// Config contains the entire configuration of the data source, provider, or resource.
	Config Config
}

ValidateAttributeRequest repesents a request for attribute validation.

type ValidateAttributeResponse added in v0.3.0

type ValidateAttributeResponse struct {
	// Diagnostics report errors or warnings related to validating the data
	// source configuration. An empty slice indicates success, with no warnings
	// or errors generated.
	Diagnostics diag.Diagnostics
}

ValidateAttributeResponse represents a response to a ValidateAttributeRequest. An instance of this response struct is automatically passed through to each AttributeValidator.

Jump to

Keyboard shortcuts

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