schema

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2021 License: MPL-2.0 Imports: 6 Imported by: 4

Documentation

Index

Constants

This section is empty.

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 or attribute of a complex type, not a nested
	// attribute.
	ErrPathInsideAtomicAttribute = errors.New("path leads to element or attribute of a schema.Attribute that has no schema associated with it")
)

Functions

This section is empty.

Types

type Attribute

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 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.
	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.
	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 a message to display to practitioners
	// using this attribute, warning them that it is deprecated and
	// instructing them on what upgrade steps to take.
	DeprecationMessage string
}

Attribute defines the constraints and behaviors of a single 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

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

func (a Attribute) Equal(o Attribute) bool

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

type ListNestedAttributesOptions

type ListNestedAttributesOptions struct {
	MinItems int
	MaxItems int
}

ListNestedAttributesOptions captures additional, optional parameters for ListNestedAttributes.

type MapNestedAttributesOptions

type MapNestedAttributesOptions struct {
	MinItems int
	MaxItems int
}

MapNestedAttributesOptions captures additional, optional parameters for MapNestedAttributes.

type NestedAttributes

type NestedAttributes interface {
	tftypes.AttributePathStepper
	AttributeType() attr.Type
	GetNestingMode() NestingMode
	GetAttributes() map[string]Attribute
	GetMinItems() int64
	GetMaxItems() int64
	Equal(NestedAttributes) bool
	// contains filtered or unexported methods
}

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.

func ListNestedAttributes

func ListNestedAttributes(attributes map[string]Attribute, opts ListNestedAttributesOptions) NestedAttributes

ListNestedAttributes nests `attributes` under another attribute, allowing multiple instances of that group of attributes to appear in the configuration. Minimum and maximum numbers of times the group can appear in the configuration can be set using `opts`.

func MapNestedAttributes

func MapNestedAttributes(attributes map[string]Attribute, opts MapNestedAttributesOptions) 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. Minimum and maximum numbers of times the group can appear in the configuration can be set using `opts`.

func SetNestedAttributes

func SetNestedAttributes(attributes map[string]Attribute, opts SetNestedAttributesOptions) 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. Minimum and maximum numbers of times the group can appear in the configuration can be set using `opts`.

func SingleNestedAttributes

func SingleNestedAttributes(attributes map[string]Attribute) NestedAttributes

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

type NestingMode

type NestingMode uint8

NestingMode is an enum type of the ways nested attributes can be nested. They can be a list, a set, or 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 struct {
	// Attributes are the 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.
	Attributes map[string]Attribute

	// 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

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

ApplyTerraform5AttributePathStep applies the given AttributePathStep to the schema.

func (Schema) AttributeAtPath

func (s Schema) AttributeAtPath(path *tftypes.AttributePath) (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) AttributeType

func (s Schema) AttributeType() attr.Type

AttributeType returns a types.ObjectType composed from the schema types.

func (Schema) AttributeTypeAtPath

func (s Schema) AttributeTypeAtPath(path *tftypes.AttributePath) (attr.Type, error)

AttributeTypeAtPath returns the attr.Type of the attribute at the given path.

func (Schema) TerraformType

func (s Schema) TerraformType(ctx context.Context) tftypes.Type

TerraformType returns a tftypes.Type that can represent the schema.

type SetNestedAttributesOptions

type SetNestedAttributesOptions struct {
	MinItems int
	MaxItems int
}

SetNestedAttributesOptions captures additional, optional parameters for SetNestedAttributes.

Jump to

Keyboard shortcuts

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