fwschema

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2022 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package fwschema implements shared logic for describing the structure, data types, and behaviors of framework data for data sources, providers, and resources.

Refer to the internal/fwschemadata package for logic built on values based on this schema information.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attribute

type Attribute interface {
	// Implementations should include the tftypes.AttributePathStepper
	// interface methods for proper path and data handling.
	tftypes.AttributePathStepper

	// Equal should return true if the other attribute is exactly equivalent.
	Equal(o Attribute) bool

	// FrameworkType should return the framework type, whether a direct type
	// or nested attributes type, for the attribute.
	//
	// When tfsdk.Attribute is removed, this should be deprecated and renamed
	// to Type() to match other interfaces.
	FrameworkType() attr.Type

	// GetAttributes should return the nested attributes of an attribute, if
	// applicable. This is named differently than Attribute to prevent a
	// conflict with the tfsdk.Attribute field name.
	GetAttributes() NestedAttributes

	// GetDeprecationMessage should return a non-empty string if an attribute
	// is deprecated. This is named differently than DeprecationMessage to
	// prevent a conflict with the tfsdk.Attribute field name.
	GetDeprecationMessage() string

	// GetDescription should return a non-empty string if an attribute
	// has a plaintext description. This is named differently than Description
	// to prevent a conflict with the tfsdk.Attribute field name.
	GetDescription() string

	// GetMarkdownDescription should return a non-empty string if an attribute
	// has a Markdown description. This is named differently than
	// MarkdownDescription to prevent a conflict with the tfsdk.Attribute field
	// name.
	GetMarkdownDescription() string

	// GetType should return the framework type of an attribute. This is named
	// differently than Type to prevent a conflict with the tfsdk.Attribute
	// field name.
	GetType() attr.Type

	// IsComputed should return true if the attribute configuration value is
	// computed. This is named differently than Computed to prevent a conflict
	// with the tfsdk.Attribute field name.
	IsComputed() bool

	// IsOptional should return true if the attribute configuration value is
	// optional. This is named differently than Optional to prevent a conflict
	// with the tfsdk.Attribute field name.
	IsOptional() bool

	// IsRequired should return true if the attribute configuration value is
	// required. This is named differently than Required to prevent a conflict
	// with the tfsdk.Attribute field name.
	IsRequired() bool

	// IsSensitive should return true if the attribute configuration value is
	// sensitive. This is named differently than Sensitive to prevent a
	// conflict with the tfsdk.Attribute field name.
	IsSensitive() bool
}

Attribute is the core interface required for implementing Terraform schema functionality that can accept a value. This is intended to be the first abstraction of tfsdk.Attribute functionality into data source, provider, and resource specific functionality.

Refer to the internal/fwschema/fwxschema package for optional interfaces that define framework-specific functionality, such a plan modification and validation.

type Block

type Block interface {
	// Implementations should include the tftypes.AttributePathStepper
	// interface methods for proper path and data handling.
	tftypes.AttributePathStepper

	// Equal should return true if the other block is exactly equivalent.
	Equal(o Block) bool

	// GetAttributes should return the nested attributes of a block, if
	// applicable. This is named differently than Attributes to prevent a
	// conflict with the tfsdk.Block field name.
	GetAttributes() map[string]Attribute

	// GetBlocks should return the nested blocks of a block, if
	// applicable. This is named differently than Blocks to prevent a
	// conflict with the tfsdk.Block field name.
	GetBlocks() map[string]Block

	// GetDeprecationMessage should return a non-empty string if an attribute
	// is deprecated. This is named differently than DeprecationMessage to
	// prevent a conflict with the tfsdk.Attribute field name.
	GetDeprecationMessage() string

	// GetDescription should return a non-empty string if an attribute
	// has a plaintext description. This is named differently than Description
	// to prevent a conflict with the tfsdk.Attribute field name.
	GetDescription() string

	// GetMarkdownDescription should return a non-empty string if an attribute
	// has a Markdown description. This is named differently than
	// MarkdownDescription to prevent a conflict with the tfsdk.Attribute field
	// name.
	GetMarkdownDescription() string

	// GetMaxItems should return the max items of a block. This is named
	// differently than MaxItems to prevent a conflict with the tfsdk.Block
	// field name.
	GetMaxItems() int64

	// GetMinItems should return the min items of a block. This is named
	// differently than MinItems to prevent a conflict with the tfsdk.Block
	// field name.
	GetMinItems() int64

	// GetNestingMode should return the nesting mode of a block. This is named
	// differently than NestingMode to prevent a conflict with the tfsdk.Block
	// field name.
	GetNestingMode() BlockNestingMode

	// Type should return the framework type of a block.
	Type() attr.Type
}

Block is the core interface required for implementing Terraform schema functionality that structurally holds attributes and blocks. This is intended to be the first abstraction of tfsdk.Block functionality into data source, provider, and resource specific functionality.

Refer to the internal/fwschema/fwxschema package for optional interfaces that define framework-specific functionality, such a plan modification and validation.

type BlockNestingMode

type BlockNestingMode uint8

BlockNestingMode is an enum type of the ways attributes and blocks can be nested in a block. They can be a list or a set.

While the protocol and theoretically Terraform itself support map and group nesting modes, this framework intentionally only supports list, set, and single blocks as those other modes were not typically implemented or tested with Terraform since the older Terraform Plugin SDK did not support them.

const (
	// BlockNestingModeUnknown is an invalid nesting mode, used to catch when a
	// nesting mode is expected and not set.
	BlockNestingModeUnknown BlockNestingMode = 0

	// BlockNestingModeList is for attributes that represent a list of objects,
	// with multiple instances of those attributes nested inside a list
	// under another attribute.
	BlockNestingModeList BlockNestingMode = 1

	// BlockNestingModeSet is for attributes that represent a set of objects,
	// with multiple, unique instances of those attributes nested inside a
	// set under another attribute.
	BlockNestingModeSet BlockNestingMode = 2

	// BlockNestingModeSingle is for attributes that represent a single object.
	// The object cannot be repeated in the practitioner configuration.
	//
	// While the framework implements support for this block nesting mode, it
	// is not thoroughly tested in production Terraform environments beyond the
	// resource timeouts block from the older Terraform Plugin SDK. Use single
	// nested attributes for new implementations instead.
	BlockNestingModeSingle BlockNestingMode = 3
)

type ListNestedAttributes

type ListNestedAttributes struct {
	UnderlyingAttributes
}

func (ListNestedAttributes) ApplyTerraform5AttributePathStep

func (l ListNestedAttributes) ApplyTerraform5AttributePathStep(step tftypes.AttributePathStep) (interface{}, error)

func (ListNestedAttributes) AttributeType

func (l ListNestedAttributes) AttributeType() attr.Type

AttributeType returns an attr.Type corresponding to the nested attributes. Deprecated: Use Type() instead.

func (ListNestedAttributes) Equal

func (ListNestedAttributes) GetAttributes

func (l ListNestedAttributes) GetAttributes() map[string]Attribute

func (ListNestedAttributes) GetNestingMode

func (l ListNestedAttributes) GetNestingMode() NestingMode

func (ListNestedAttributes) Type

func (l ListNestedAttributes) Type() attr.Type

Type returns the framework type of the nested attributes.

type MapNestedAttributes

type MapNestedAttributes struct {
	UnderlyingAttributes
}

func (MapNestedAttributes) ApplyTerraform5AttributePathStep

func (m MapNestedAttributes) ApplyTerraform5AttributePathStep(step tftypes.AttributePathStep) (interface{}, error)

func (MapNestedAttributes) AttributeType

func (m MapNestedAttributes) AttributeType() attr.Type

AttributeType returns an attr.Type corresponding to the nested attributes. Deprecated: Use Type() instead.

func (MapNestedAttributes) Equal

func (MapNestedAttributes) GetAttributes

func (m MapNestedAttributes) GetAttributes() map[string]Attribute

func (MapNestedAttributes) GetNestingMode

func (m MapNestedAttributes) GetNestingMode() NestingMode

func (MapNestedAttributes) Type

func (m MapNestedAttributes) Type() attr.Type

Type returns the framework type of the nested attributes.

type NestedAttributes

type NestedAttributes interface {
	// Implementations should include the tftypes.AttributePathStepper
	// interface methods for proper path and data handling.
	tftypes.AttributePathStepper

	// AttributeType should return the framework type of the nested attributes.
	// This method should be deprecated in preference of Type().
	AttributeType() attr.Type

	// Equal should return true if the other NestedAttributes is equivalent.
	Equal(NestedAttributes) bool

	// GetNestingMode should return the nesting mode (list, map, set, or
	// single) of the nested attributes.
	GetNestingMode() NestingMode

	// GetAttributes() should return the mapping of names to nested attributes.
	GetAttributes() map[string]Attribute

	// Type should return the framework type of the nested attributes.
	Type() attr.Type
}

NestedAttributes surfaces a group of attributes to nest beneath another attribute, and how that nesting should behave. Nesting can have the following modes:

* SingleNestedAttributes are nested attributes that represent a struct or object; there should only be one instance of them nested beneath that specific attribute.

* ListNestedAttributes are nested attributes that represent a list of structs or objects; there can be multiple instances of them beneath that specific attribute.

* SetNestedAttributes are nested attributes that represent a set of structs or objects; there can be multiple instances of them beneath that specific attribute. Unlike ListNestedAttributes, these nested attributes must have unique values.

* MapNestedAttributes are nested attributes that represent a string-indexed map of structs or objects; there can be multiple instances of them beneath that specific attribute. Unlike ListNestedAttributes, these nested attributes must be associated with a unique key. Unlike SetNestedAttributes, the key must be explicitly set by the user.

type NestedBlock

type NestedBlock struct {
	Block
}

func (NestedBlock) ApplyTerraform5AttributePathStep

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

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

type NestingMode

type NestingMode uint8

NestingMode is an enum type of the ways nested attributes can be nested in an attribute. They can be a list, a set, a map (with string keys), or they can be nested directly, like an object.

const (
	// NestingModeUnknown is an invalid nesting mode, used to catch when a
	// nesting mode is expected and not set.
	NestingModeUnknown NestingMode = 0

	// NestingModeSingle is for attributes that represent a struct or
	// object, a single instance of those attributes directly nested under
	// another attribute.
	NestingModeSingle NestingMode = 1

	// NestingModeList is for attributes that represent a list of objects,
	// with multiple instances of those attributes nested inside a list
	// under another attribute.
	NestingModeList NestingMode = 2

	// NestingModeSet is for attributes that represent a set of objects,
	// with multiple, unique instances of those attributes nested inside a
	// set under another attribute.
	NestingModeSet NestingMode = 3

	// NestingModeMap is for attributes that represent a map of objects,
	// with multiple instances of those attributes, each associated with a
	// unique string key, nested inside a map under another attribute.
	NestingModeMap NestingMode = 4
)

type Schema

type Schema interface {
	// Implementations should include the tftypes.AttributePathStepper
	// interface methods for proper path and data handling.
	tftypes.AttributePathStepper

	// AttributeAtPath should return the Attribute at the given path or return
	// an error.
	AttributeAtPath(context.Context, path.Path) (Attribute, diag.Diagnostics)

	// AttributeAtTerraformPath should return the Attribute at the given
	// Terraform path or return an error.
	AttributeAtTerraformPath(context.Context, *tftypes.AttributePath) (Attribute, error)

	// GetAttributes should return the attributes of a schema. This is named
	// differently than Attributes to prevent a conflict with the tfsdk.Schema
	// field name.
	GetAttributes() map[string]Attribute

	// GetBlocks should return the blocks of a schema. This is named
	// differently than Blocks to prevent a conflict with the tfsdk.Schema
	// field name.
	GetBlocks() map[string]Block

	// GetDeprecationMessage should return a non-empty string if a schema
	// is deprecated. This is named differently than DeprecationMessage to
	// prevent a conflict with the tfsdk.Schema field name.
	GetDeprecationMessage() string

	// GetDescription should return a non-empty string if a schema has a
	// plaintext description. This is named differently than Description
	// to prevent a conflict with the tfsdk.Schema field name.
	GetDescription() string

	// GetMarkdownDescription should return a non-empty string if a schema has
	// a Markdown description. This is named differently than
	// MarkdownDescription to prevent a conflict with the tfsdk.Schema field
	// name.
	GetMarkdownDescription() string

	// GetVersion should return the version of a schema. This is named
	// differently than Version to prevent a conflict with the tfsdk.Schema
	// field name.
	GetVersion() int64

	// Type should return the framework type of the schema.
	Type() attr.Type

	// TypeAtPath should return the framework type of the Attribute at the
	// the given path or return an error.
	TypeAtPath(context.Context, path.Path) (attr.Type, diag.Diagnostics)

	// AttributeTypeAtPath should return the framework type of the Attribute at
	// the given Terraform path or return an error.
	TypeAtTerraformPath(context.Context, *tftypes.AttributePath) (attr.Type, error)
}

Schema is the core interface required for data sources, providers, and resources.

type SetNestedAttributes

type SetNestedAttributes struct {
	UnderlyingAttributes
}

func (SetNestedAttributes) ApplyTerraform5AttributePathStep

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

func (SetNestedAttributes) AttributeType

func (s SetNestedAttributes) AttributeType() attr.Type

AttributeType returns an attr.Type corresponding to the nested attributes. Deprecated: Use Type() instead.

func (SetNestedAttributes) Equal

func (SetNestedAttributes) GetAttributes

func (s SetNestedAttributes) GetAttributes() map[string]Attribute

func (SetNestedAttributes) GetNestingMode

func (s SetNestedAttributes) GetNestingMode() NestingMode

func (SetNestedAttributes) Type

func (s SetNestedAttributes) Type() attr.Type

Type returns the framework type of the nested attributes.

type SingleNestedAttributes

type SingleNestedAttributes struct {
	UnderlyingAttributes
}

func (SingleNestedAttributes) ApplyTerraform5AttributePathStep

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

func (SingleNestedAttributes) AttributeType deprecated

func (s SingleNestedAttributes) AttributeType() attr.Type

Deprecated: Use Type() instead.

func (SingleNestedAttributes) Equal

func (SingleNestedAttributes) GetAttributes

func (s SingleNestedAttributes) GetAttributes() map[string]Attribute

func (SingleNestedAttributes) GetNestingMode

func (s SingleNestedAttributes) GetNestingMode() NestingMode

func (SingleNestedAttributes) Type

func (s SingleNestedAttributes) Type() attr.Type

Type returns the framework type of the nested attributes.

type UnderlyingAttributes

type UnderlyingAttributes map[string]Attribute

func (UnderlyingAttributes) ApplyTerraform5AttributePathStep

func (n UnderlyingAttributes) ApplyTerraform5AttributePathStep(step tftypes.AttributePathStep) (interface{}, error)

func (UnderlyingAttributes) Type

func (n UnderlyingAttributes) Type() attr.Type

Type returns the framework type of the nested attributes.

Directories

Path Synopsis
Package fwxschema implements extra framework-based schema functionality on top of base Terraform attribute functionality.
Package fwxschema implements extra framework-based schema functionality on top of base Terraform attribute functionality.

Jump to

Keyboard shortcuts

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