tfschema

package
v1.58.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildDataSourceAttributeMap

func BuildDataSourceAttributeMap(attributes map[string]AttributeBuilder) map[string]dataschema.Attribute

BuildDataSourceAttributeMap takes a map from string to AttributeBuilder and returns a map from string to datasource.schema.Attribute.

func BuildDataSourceBlockMap added in v1.54.0

func BuildDataSourceBlockMap(attributes map[string]BlockBuilder) map[string]dataschema.Block

func BuildResourceAttributeMap

func BuildResourceAttributeMap(attributes map[string]AttributeBuilder) map[string]schema.Attribute

BuildResourceAttributeMap takes a map from string to AttributeBuilder and returns a map from string to resource.schema.Attribute.

func BuildResourceBlockMap added in v1.54.0

func BuildResourceBlockMap(attributes map[string]BlockBuilder) map[string]schema.Block

func DataSourceStructToSchema

func DataSourceStructToSchema(v any, customizeSchema func(CustomizableSchema) CustomizableSchema) dataschema.Schema

DataSourceStructToSchema builds a data source schema from a tfsdk struct, with custoimzations applied.

func DataSourceStructToSchemaMap

func DataSourceStructToSchemaMap(v any, customizeSchema func(CustomizableSchema) CustomizableSchema) (map[string]dataschema.Attribute, map[string]dataschema.Block)

DataSourceStructToSchemaMap returns twp maps from string to data source schema attributes and blocks using a tfsdk struct, with custoimzations applied.

func ResourceStructToSchema

func ResourceStructToSchema(v any, customizeSchema func(CustomizableSchema) CustomizableSchema) schema.Schema

ResourceStructToSchema builds a resource schema from a tfsdk struct, with custoimzations applied.

func ResourceStructToSchemaMap

func ResourceStructToSchemaMap(v any, customizeSchema func(CustomizableSchema) CustomizableSchema) (map[string]schema.Attribute, map[string]schema.Block)

ResourceStructToSchemaMap returns two maps from string to resource schema attributes and blocks using a tfsdk struct, with custoimzations applied.

Types

type AttributeBuilder

type AttributeBuilder interface {
	BaseSchemaBuilder
	BuildDataSourceAttribute() dataschema.Attribute
	BuildResourceAttribute() schema.Attribute
}

AttributeBuilder is the common interface for all attributes, it can be used to build data source attribute and resource attribute. We need this because in terraform plugin framework, the datasource schema and resource schema are in two separate packages. This common interface prevents us from keeping two copies of StructToSchema and CustomizableSchema.

type BaseSchemaBuilder added in v1.54.0

type BaseSchemaBuilder interface {
	SetOptional() BaseSchemaBuilder
	SetRequired() BaseSchemaBuilder
	SetSensitive() BaseSchemaBuilder
	SetComputed() BaseSchemaBuilder
	SetReadOnly() BaseSchemaBuilder
	SetDeprecated(string) BaseSchemaBuilder
}

BaseSchemaBuilder is the common interface for all blocks and attributes, it can be used to build data source and resource. Both AttributeBuilder and BlockBuilder extend this interface.

type BlockBuilder added in v1.54.0

type BlockBuilder interface {
	BaseSchemaBuilder
	BuildDataSourceBlock() dataschema.Block
	BuildResourceBlock() schema.Block
}

BlockBuilder is the common interface for all blocks, it can be used to build data source blocks and resource blocks. We need this because in terraform plugin framework, the datasource schema and resource schema are in two separate packages. This common interface prevents us from keeping two copies of StructToSchema and CustomizableSchema.

type BoolAttributeBuilder

type BoolAttributeBuilder struct {
	Optional           bool
	Required           bool
	Sensitive          bool
	Computed           bool
	DeprecationMessage string
	Validators         []validator.Bool
	PlanModifiers      []planmodifier.Bool
}

func (BoolAttributeBuilder) AddPlanModifier

func (BoolAttributeBuilder) AddValidator

func (BoolAttributeBuilder) BuildDataSourceAttribute

func (a BoolAttributeBuilder) BuildDataSourceAttribute() dataschema.Attribute

func (BoolAttributeBuilder) BuildResourceAttribute

func (a BoolAttributeBuilder) BuildResourceAttribute() schema.Attribute

func (BoolAttributeBuilder) SetComputed

func (a BoolAttributeBuilder) SetComputed() BaseSchemaBuilder

func (BoolAttributeBuilder) SetDeprecated

func (a BoolAttributeBuilder) SetDeprecated(msg string) BaseSchemaBuilder

func (BoolAttributeBuilder) SetOptional

func (a BoolAttributeBuilder) SetOptional() BaseSchemaBuilder

func (BoolAttributeBuilder) SetReadOnly

func (a BoolAttributeBuilder) SetReadOnly() BaseSchemaBuilder

func (BoolAttributeBuilder) SetRequired

func (a BoolAttributeBuilder) SetRequired() BaseSchemaBuilder

func (BoolAttributeBuilder) SetSensitive

func (a BoolAttributeBuilder) SetSensitive() BaseSchemaBuilder

type CustomizableSchema

type CustomizableSchema struct {
	// contains filtered or unexported fields
}

CustomizableSchema is a wrapper struct on top of BaseSchemaBuilder that can be used to navigate through nested schema add customizations.

func ConstructCustomizableSchema

func ConstructCustomizableSchema(nestedObject NestedBlockObject) *CustomizableSchema

ConstructCustomizableSchema constructs a CustomizableSchema given a NestedBlockObject.

func (*CustomizableSchema) AddPlanModifier

func (s *CustomizableSchema) AddPlanModifier(v any, path ...string) *CustomizableSchema

func (*CustomizableSchema) AddValidator

func (s *CustomizableSchema) AddValidator(v any, path ...string) *CustomizableSchema

func (*CustomizableSchema) SetComputed

func (s *CustomizableSchema) SetComputed(path ...string) *CustomizableSchema

func (*CustomizableSchema) SetDeprecated

func (s *CustomizableSchema) SetDeprecated(msg string, path ...string) *CustomizableSchema

func (*CustomizableSchema) SetOptional

func (s *CustomizableSchema) SetOptional(path ...string) *CustomizableSchema

func (*CustomizableSchema) SetReadOnly

func (s *CustomizableSchema) SetReadOnly(path ...string) *CustomizableSchema

SetReadOnly sets the schema to be read-only (i.e. computed, non-optional). This should be used for fields that are not user-configurable but are returned by the platform.

func (*CustomizableSchema) SetRequired

func (s *CustomizableSchema) SetRequired(path ...string) *CustomizableSchema

func (*CustomizableSchema) SetSensitive

func (s *CustomizableSchema) SetSensitive(path ...string) *CustomizableSchema

func (*CustomizableSchema) ToNestedBlockObject added in v1.54.0

func (s *CustomizableSchema) ToNestedBlockObject() NestedBlockObject

ToAttributeMap converts CustomizableSchema into BaseSchemaBuilder.

type Float64AttributeBuilder

type Float64AttributeBuilder struct {
	Optional           bool
	Required           bool
	Sensitive          bool
	Computed           bool
	DeprecationMessage string
	Validators         []validator.Float64
	PlanModifiers      []planmodifier.Float64
}

func (Float64AttributeBuilder) AddPlanModifier

func (Float64AttributeBuilder) AddValidator

func (Float64AttributeBuilder) BuildDataSourceAttribute

func (a Float64AttributeBuilder) BuildDataSourceAttribute() dataschema.Attribute

func (Float64AttributeBuilder) BuildResourceAttribute

func (a Float64AttributeBuilder) BuildResourceAttribute() schema.Attribute

func (Float64AttributeBuilder) SetComputed

func (Float64AttributeBuilder) SetDeprecated

func (a Float64AttributeBuilder) SetDeprecated(msg string) BaseSchemaBuilder

func (Float64AttributeBuilder) SetOptional

func (Float64AttributeBuilder) SetReadOnly

func (Float64AttributeBuilder) SetRequired

func (Float64AttributeBuilder) SetSensitive

func (a Float64AttributeBuilder) SetSensitive() BaseSchemaBuilder

type Int64AttributeBuilder

type Int64AttributeBuilder struct {
	Optional           bool
	Required           bool
	Sensitive          bool
	Computed           bool
	DeprecationMessage string
	Validators         []validator.Int64
	PlanModifiers      []planmodifier.Int64
}

func (Int64AttributeBuilder) AddPlanModifier

func (Int64AttributeBuilder) AddValidator

func (Int64AttributeBuilder) BuildDataSourceAttribute

func (a Int64AttributeBuilder) BuildDataSourceAttribute() dataschema.Attribute

func (Int64AttributeBuilder) BuildResourceAttribute

func (a Int64AttributeBuilder) BuildResourceAttribute() schema.Attribute

func (Int64AttributeBuilder) SetComputed

func (a Int64AttributeBuilder) SetComputed() BaseSchemaBuilder

func (Int64AttributeBuilder) SetDeprecated

func (a Int64AttributeBuilder) SetDeprecated(msg string) BaseSchemaBuilder

func (Int64AttributeBuilder) SetOptional

func (a Int64AttributeBuilder) SetOptional() BaseSchemaBuilder

func (Int64AttributeBuilder) SetReadOnly

func (a Int64AttributeBuilder) SetReadOnly() BaseSchemaBuilder

func (Int64AttributeBuilder) SetRequired

func (a Int64AttributeBuilder) SetRequired() BaseSchemaBuilder

func (Int64AttributeBuilder) SetSensitive

func (a Int64AttributeBuilder) SetSensitive() BaseSchemaBuilder

type ListAttributeBuilder

type ListAttributeBuilder struct {
	ElementType        attr.Type
	Optional           bool
	Required           bool
	Sensitive          bool
	Computed           bool
	DeprecationMessage string
	Validators         []validator.List
	PlanModifiers      []planmodifier.List
}

ListAttributteBuilder represents a list of primitive types.

func (ListAttributeBuilder) AddPlanModifier

func (ListAttributeBuilder) AddValidator

func (ListAttributeBuilder) BuildDataSourceAttribute

func (a ListAttributeBuilder) BuildDataSourceAttribute() dataschema.Attribute

func (ListAttributeBuilder) BuildResourceAttribute

func (a ListAttributeBuilder) BuildResourceAttribute() schema.Attribute

func (ListAttributeBuilder) SetComputed

func (a ListAttributeBuilder) SetComputed() BaseSchemaBuilder

func (ListAttributeBuilder) SetDeprecated

func (a ListAttributeBuilder) SetDeprecated(msg string) BaseSchemaBuilder

func (ListAttributeBuilder) SetOptional

func (a ListAttributeBuilder) SetOptional() BaseSchemaBuilder

func (ListAttributeBuilder) SetReadOnly

func (a ListAttributeBuilder) SetReadOnly() BaseSchemaBuilder

func (ListAttributeBuilder) SetRequired

func (a ListAttributeBuilder) SetRequired() BaseSchemaBuilder

func (ListAttributeBuilder) SetSensitive

func (a ListAttributeBuilder) SetSensitive() BaseSchemaBuilder

type ListNestedAttributeBuilder

type ListNestedAttributeBuilder struct {
	NestedObject       NestedAttributeObject
	Optional           bool
	Required           bool
	Sensitive          bool
	Computed           bool
	DeprecationMessage string
	Validators         []validator.List
	PlanModifiers      []planmodifier.List
}

ListNestedAttributteBuilder represents a list of complex (non-primitive) types.

func (ListNestedAttributeBuilder) AddPlanModifier

func (ListNestedAttributeBuilder) AddValidator

func (ListNestedAttributeBuilder) BuildDataSourceAttribute

func (a ListNestedAttributeBuilder) BuildDataSourceAttribute() dataschema.Attribute

func (ListNestedAttributeBuilder) BuildResourceAttribute

func (a ListNestedAttributeBuilder) BuildResourceAttribute() schema.Attribute

func (ListNestedAttributeBuilder) SetComputed

func (ListNestedAttributeBuilder) SetDeprecated

func (ListNestedAttributeBuilder) SetOptional

func (ListNestedAttributeBuilder) SetReadOnly

func (ListNestedAttributeBuilder) SetRequired

func (ListNestedAttributeBuilder) SetSensitive

type ListNestedBlockBuilder added in v1.54.0

type ListNestedBlockBuilder struct {
	NestedObject       NestedBlockObject
	Optional           bool
	Required           bool
	Sensitive          bool
	Computed           bool
	DeprecationMessage string
	Validators         []validator.List
	PlanModifiers      []planmodifier.List
}

ListNestedBlockBuilder represents a list of complex (non-primitive) types. To be compatible with our sdkv2 schema, all struct types in the gosdk are represented with this type.

func (ListNestedBlockBuilder) AddPlanModifier added in v1.54.0

func (ListNestedBlockBuilder) AddValidator added in v1.54.0

func (ListNestedBlockBuilder) BuildDataSourceBlock added in v1.54.0

func (a ListNestedBlockBuilder) BuildDataSourceBlock() dataschema.Block

func (ListNestedBlockBuilder) BuildResourceBlock added in v1.54.0

func (a ListNestedBlockBuilder) BuildResourceBlock() schema.Block

func (ListNestedBlockBuilder) SetComputed added in v1.54.0

func (a ListNestedBlockBuilder) SetComputed() BaseSchemaBuilder

func (ListNestedBlockBuilder) SetDeprecated added in v1.54.0

func (a ListNestedBlockBuilder) SetDeprecated(msg string) BaseSchemaBuilder

func (ListNestedBlockBuilder) SetOptional added in v1.54.0

func (a ListNestedBlockBuilder) SetOptional() BaseSchemaBuilder

func (ListNestedBlockBuilder) SetReadOnly added in v1.54.0

func (a ListNestedBlockBuilder) SetReadOnly() BaseSchemaBuilder

func (ListNestedBlockBuilder) SetRequired added in v1.54.0

func (a ListNestedBlockBuilder) SetRequired() BaseSchemaBuilder

func (ListNestedBlockBuilder) SetSensitive added in v1.54.0

func (a ListNestedBlockBuilder) SetSensitive() BaseSchemaBuilder

type MapAttributeBuilder

type MapAttributeBuilder struct {
	ElementType        attr.Type
	Optional           bool
	Required           bool
	Sensitive          bool
	Computed           bool
	DeprecationMessage string
	Validators         []validator.Map
	PlanModifiers      []planmodifier.Map
}

MapAttributteBuilder represents a map of primitive types.

func (MapAttributeBuilder) AddPlanModifier

func (MapAttributeBuilder) AddValidator

func (MapAttributeBuilder) BuildDataSourceAttribute

func (a MapAttributeBuilder) BuildDataSourceAttribute() dataschema.Attribute

func (MapAttributeBuilder) BuildResourceAttribute

func (a MapAttributeBuilder) BuildResourceAttribute() schema.Attribute

func (MapAttributeBuilder) SetComputed

func (a MapAttributeBuilder) SetComputed() BaseSchemaBuilder

func (MapAttributeBuilder) SetDeprecated

func (a MapAttributeBuilder) SetDeprecated(msg string) BaseSchemaBuilder

func (MapAttributeBuilder) SetOptional

func (a MapAttributeBuilder) SetOptional() BaseSchemaBuilder

func (MapAttributeBuilder) SetReadOnly

func (a MapAttributeBuilder) SetReadOnly() BaseSchemaBuilder

func (MapAttributeBuilder) SetRequired

func (a MapAttributeBuilder) SetRequired() BaseSchemaBuilder

func (MapAttributeBuilder) SetSensitive

func (a MapAttributeBuilder) SetSensitive() BaseSchemaBuilder

type MapNestedAttributeBuilder

type MapNestedAttributeBuilder struct {
	NestedObject       NestedAttributeObject
	Optional           bool
	Required           bool
	Sensitive          bool
	Computed           bool
	DeprecationMessage string
	Validators         []validator.Map
	PlanModifiers      []planmodifier.Map
}

MapNestedAttributteBuilder represents a map of complex (non-primitive) types.

func (MapNestedAttributeBuilder) AddPlanModifier

func (MapNestedAttributeBuilder) AddValidator

func (MapNestedAttributeBuilder) BuildDataSourceAttribute

func (a MapNestedAttributeBuilder) BuildDataSourceAttribute() dataschema.Attribute

func (MapNestedAttributeBuilder) BuildResourceAttribute

func (a MapNestedAttributeBuilder) BuildResourceAttribute() schema.Attribute

func (MapNestedAttributeBuilder) SetComputed

func (MapNestedAttributeBuilder) SetDeprecated

func (a MapNestedAttributeBuilder) SetDeprecated(msg string) BaseSchemaBuilder

func (MapNestedAttributeBuilder) SetOptional

func (MapNestedAttributeBuilder) SetReadOnly

func (MapNestedAttributeBuilder) SetRequired

func (MapNestedAttributeBuilder) SetSensitive

type NestedAttributeObject

type NestedAttributeObject struct {
	Attributes map[string]AttributeBuilder
}

NestedAttributteObject is the intermediate type for nested complex (non-primitive) types.

func (NestedAttributeObject) BuildDataSourceAttribute

func (a NestedAttributeObject) BuildDataSourceAttribute() dataschema.NestedAttributeObject

func (NestedAttributeObject) BuildResourceAttribute

func (a NestedAttributeObject) BuildResourceAttribute() schema.NestedAttributeObject

type NestedBlockObject added in v1.54.0

type NestedBlockObject struct {
	Attributes map[string]AttributeBuilder
	Blocks     map[string]BlockBuilder
}

NestedAttributteObject is the intermediate type for nested complex (non-primitive) types.

func (NestedBlockObject) BuildDataSourceAttribute added in v1.54.0

func (a NestedBlockObject) BuildDataSourceAttribute() dataschema.NestedBlockObject

func (NestedBlockObject) BuildResourceAttribute added in v1.54.0

func (a NestedBlockObject) BuildResourceAttribute() schema.NestedBlockObject

type SingleNestedAttributeBuilder

type SingleNestedAttributeBuilder struct {
	Attributes         map[string]AttributeBuilder
	Optional           bool
	Required           bool
	Sensitive          bool
	Computed           bool
	DeprecationMessage string
	Validators         []validator.Object
	PlanModifiers      []planmodifier.Object
}

SingleNestedAttributteBuilder represents single complex (struct) types.

func (SingleNestedAttributeBuilder) AddPlanModifier

func (SingleNestedAttributeBuilder) AddValidator

func (SingleNestedAttributeBuilder) BuildDataSourceAttribute

func (a SingleNestedAttributeBuilder) BuildDataSourceAttribute() dataschema.Attribute

func (SingleNestedAttributeBuilder) BuildResourceAttribute

func (a SingleNestedAttributeBuilder) BuildResourceAttribute() schema.Attribute

func (SingleNestedAttributeBuilder) SetComputed

func (SingleNestedAttributeBuilder) SetDeprecated

func (SingleNestedAttributeBuilder) SetOptional

func (SingleNestedAttributeBuilder) SetReadOnly

func (SingleNestedAttributeBuilder) SetRequired

func (SingleNestedAttributeBuilder) SetSensitive

type SingleNestedBlockBuilder added in v1.54.0

type SingleNestedBlockBuilder struct {
	NestedObject       NestedBlockObject
	Optional           bool
	Required           bool
	Sensitive          bool
	Computed           bool
	DeprecationMessage string
	Validators         []validator.Object
	PlanModifiers      []planmodifier.Object
}

SingleNestedBlockBuilder represents a single nested complex (non-primitive) type.

func (SingleNestedBlockBuilder) AddPlanModifier added in v1.54.0

func (SingleNestedBlockBuilder) AddValidator added in v1.54.0

func (SingleNestedBlockBuilder) BuildDataSourceAttribute added in v1.54.0

func (a SingleNestedBlockBuilder) BuildDataSourceAttribute() dataschema.Attribute

func (SingleNestedBlockBuilder) BuildDataSourceBlock added in v1.54.0

func (a SingleNestedBlockBuilder) BuildDataSourceBlock() dataschema.Block

func (SingleNestedBlockBuilder) BuildResourceAttribute added in v1.54.0

func (a SingleNestedBlockBuilder) BuildResourceAttribute() schema.Attribute

func (SingleNestedBlockBuilder) BuildResourceBlock added in v1.54.0

func (a SingleNestedBlockBuilder) BuildResourceBlock() schema.Block

func (SingleNestedBlockBuilder) SetComputed added in v1.54.0

func (SingleNestedBlockBuilder) SetDeprecated added in v1.54.0

func (a SingleNestedBlockBuilder) SetDeprecated(msg string) BaseSchemaBuilder

func (SingleNestedBlockBuilder) SetOptional added in v1.54.0

func (SingleNestedBlockBuilder) SetReadOnly added in v1.54.0

func (SingleNestedBlockBuilder) SetRequired added in v1.54.0

func (SingleNestedBlockBuilder) SetSensitive added in v1.54.0

type StringAttributeBuilder

type StringAttributeBuilder struct {
	Optional           bool
	Required           bool
	Sensitive          bool
	Computed           bool
	DeprecationMessage string
	Validators         []validator.String
	PlanModifiers      []planmodifier.String
}

func (StringAttributeBuilder) AddPlanModifier

func (StringAttributeBuilder) AddValidator

func (StringAttributeBuilder) BuildDataSourceAttribute

func (a StringAttributeBuilder) BuildDataSourceAttribute() dataschema.Attribute

func (StringAttributeBuilder) BuildResourceAttribute

func (a StringAttributeBuilder) BuildResourceAttribute() schema.Attribute

func (StringAttributeBuilder) SetComputed

func (a StringAttributeBuilder) SetComputed() BaseSchemaBuilder

func (StringAttributeBuilder) SetDeprecated

func (a StringAttributeBuilder) SetDeprecated(msg string) BaseSchemaBuilder

func (StringAttributeBuilder) SetOptional

func (a StringAttributeBuilder) SetOptional() BaseSchemaBuilder

func (StringAttributeBuilder) SetReadOnly

func (a StringAttributeBuilder) SetReadOnly() BaseSchemaBuilder

func (StringAttributeBuilder) SetRequired

func (a StringAttributeBuilder) SetRequired() BaseSchemaBuilder

func (StringAttributeBuilder) SetSensitive

func (a StringAttributeBuilder) SetSensitive() BaseSchemaBuilder

Jump to

Keyboard shortcuts

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