schema

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2023 License: MPL-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AttrImport         = "github.com/hashicorp/terraform-plugin-framework/attr"
	BaseTypesImport    = "github.com/hashicorp/terraform-plugin-framework/types/basetypes"
	ContextImport      = "context"
	DiagImport         = "github.com/hashicorp/terraform-plugin-framework/diag"
	FmtImport          = "fmt"
	PlanModifierImport = "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
	StringsImport      = "strings"
	TfTypesImport      = "github.com/hashicorp/terraform-plugin-go/tftypes"
	TypesImport        = "github.com/hashicorp/terraform-plugin-framework/types"
	ValidatorImport    = "github.com/hashicorp/terraform-plugin-framework/schema/validator"
)

Variables

View Source
var BoolFromTemplate string
View Source
var BoolToTemplate string
View Source
var BoolTypeEqualTemplate string
View Source
var BoolTypeStringTemplate string
View Source
var BoolTypeTypableTemplate string
View Source
var BoolTypeTypeTemplate string
View Source
var BoolTypeValueFromBoolTemplate string
View Source
var BoolTypeValueFromTerraformTemplate string
View Source
var BoolTypeValueTypeTemplate string
View Source
var BoolValueEqualTemplate string
View Source
var BoolValueTypeTemplate string
View Source
var BoolValueValuableTemplate string
View Source
var BoolValueValueTemplate string
View Source
var Float64FromTemplate string
View Source
var Float64ToTemplate string
View Source
var Float64TypeEqualTemplate string
View Source
var Float64TypeStringTemplate string
View Source
var Float64TypeTypableTemplate string
View Source
var Float64TypeTypeTemplate string
View Source
var Float64TypeValueFromFloat64Template string
View Source
var Float64TypeValueFromTerraformTemplate string
View Source
var Float64TypeValueTypeTemplate string
View Source
var Float64ValueEqualTemplate string
View Source
var Float64ValueTypeTemplate string
View Source
var Float64ValueValuableTemplate string
View Source
var Float64ValueValueTemplate string
View Source
var Int64FromTemplate string
View Source
var Int64ToTemplate string
View Source
var Int64TypeEqualTemplate string
View Source
var Int64TypeStringTemplate string
View Source
var Int64TypeTypableTemplate string
View Source
var Int64TypeTypeTemplate string
View Source
var Int64TypeValueFromInt64Template string
View Source
var Int64TypeValueFromTerraformTemplate string
View Source
var Int64TypeValueTypeTemplate string
View Source
var Int64ValueEqualTemplate string
View Source
var Int64ValueTypeTemplate string
View Source
var Int64ValueValuableTemplate string
View Source
var Int64ValueValueTemplate string
View Source
var NumberFromTemplate string
View Source
var NumberToTemplate string
View Source
var NumberTypeEqualTemplate string
View Source
var NumberTypeStringTemplate string
View Source
var NumberTypeTypableTemplate string
View Source
var NumberTypeTypeTemplate string
View Source
var NumberTypeValueFromNumberTemplate string
View Source
var NumberTypeValueFromTerraformTemplate string
View Source
var NumberTypeValueTypeTemplate string
View Source
var NumberValueEqualTemplate string
View Source
var NumberValueTypeTemplate string
View Source
var NumberValueValuableTemplate string
View Source
var NumberValueValueTemplate string
View Source
var ObjectFromTemplate string
View Source
var ObjectToTemplate string
View Source
var ObjectTypeEqualTemplate string
View Source
var ObjectTypeStringTemplate string
View Source
var ObjectTypeTypableTemplate string
View Source
var ObjectTypeTypeTemplate string
View Source
var ObjectTypeValueFromObjectTemplate string
View Source
var ObjectTypeValueFromTerraformTemplate string
View Source
var ObjectTypeValueMustTemplate string
View Source
var ObjectTypeValueNullTemplate string
View Source
var ObjectTypeValueTemplate string
View Source
var ObjectTypeValueTypeTemplate string
View Source
var ObjectTypeValueUnknownTemplate string
View Source
var ObjectValueAttributeTypesTemplate string
View Source
var ObjectValueEqualTemplate string
View Source
var ObjectValueIsNullTemplate string
View Source
var ObjectValueIsUnknownTemplate string
View Source
var ObjectValueStringTemplate string
View Source
var ObjectValueToObjectValueTemplate string
View Source
var ObjectValueToTerraformValueTemplate string
View Source
var ObjectValueTypeTemplate string
View Source
var ObjectValueValuableTemplate string
View Source
var ObjectValueValueTemplate string
View Source
var SchemaGoTemplate string
View Source
var StringFromTemplate string
View Source
var StringToTemplate string
View Source
var StringTypeEqualTemplate string
View Source
var StringTypeStringTemplate string
View Source
var StringTypeTypableTemplate string
View Source
var StringTypeTypeTemplate string
View Source
var StringTypeValueFromStringTemplate string
View Source
var StringTypeValueFromTerraformTemplate string
View Source
var StringTypeValueTypeTemplate string
View Source
var StringValueEqualTemplate string
View Source
var StringValueTypeTemplate string
View Source
var StringValueValuableTemplate string
View Source
var StringValueValueTemplate string

Functions

func AttrTypesString

func AttrTypesString(attrTypes specschema.ObjectAttributeTypes) (string, error)

func ElementTypeString

func ElementTypeString(elementType specschema.ElementType) (string, error)

func GetAttrTypes

func GetAttrTypes(attrTypes specschema.ObjectAttributeTypes) string

GetAttrTypes generates the strings for use within templates for specifying the types to use with object attribute types.

func GetElementType

func GetElementType(e specschema.ElementType) string

GetElementType generates the strings for use within templates for specifying the types to use with collection (i.e., list, map and set) element types.

Types

type AssocExtType

type AssocExtType struct {
	*schema.AssociatedExternalType
}

func NewAssocExtType

func NewAssocExtType(assocExtType *schema.AssociatedExternalType) *AssocExtType

func (*AssocExtType) Equal

func (a *AssocExtType) Equal(other *AssocExtType) bool

func (*AssocExtType) Imports

func (a *AssocExtType) Imports() *Imports

func (*AssocExtType) ToCamelCase added in v0.2.0

func (a *AssocExtType) ToCamelCase() string

func (*AssocExtType) ToPascalCase

func (a *AssocExtType) ToPascalCase() string

func (*AssocExtType) Type

func (a *AssocExtType) Type() string

func (*AssocExtType) TypeReference

func (a *AssocExtType) TypeReference() string

type AttrType added in v0.2.0

type AttrType interface {
	AttrType(FrameworkIdentifier) string
}

type AttrValue added in v0.2.0

type AttrValue interface {
	AttrValue(FrameworkIdentifier) string
}

type Attributes

type Attributes interface {
	GetAttributes() GeneratorAttributes
}

type Attrs

type Attrs interface {
	AttrTypes() specschema.ObjectAttributeTypes
}

type Blocks

type Blocks interface {
	Attributes
	GetBlocks() GeneratorBlocks
}

type CustomBoolType added in v0.2.0

type CustomBoolType struct {
	Name FrameworkIdentifier
	// contains filtered or unexported fields
}

func NewCustomBoolType added in v0.2.0

func NewCustomBoolType(name string) CustomBoolType

func (CustomBoolType) Render added in v0.2.0

func (c CustomBoolType) Render() ([]byte, error)

type CustomBoolValue added in v0.2.0

type CustomBoolValue struct {
	Name FrameworkIdentifier
	// contains filtered or unexported fields
}

func NewCustomBoolValue added in v0.2.0

func NewCustomBoolValue(name string) CustomBoolValue

func (CustomBoolValue) Render added in v0.2.0

func (c CustomBoolValue) Render() ([]byte, error)

type CustomFloat64Type added in v0.2.0

type CustomFloat64Type struct {
	Name FrameworkIdentifier
	// contains filtered or unexported fields
}

func NewCustomFloat64Type added in v0.2.0

func NewCustomFloat64Type(name string) CustomFloat64Type

func (CustomFloat64Type) Render added in v0.2.0

func (c CustomFloat64Type) Render() ([]byte, error)

type CustomFloat64Value added in v0.2.0

type CustomFloat64Value struct {
	Name FrameworkIdentifier
	// contains filtered or unexported fields
}

func NewCustomFloat64Value added in v0.2.0

func NewCustomFloat64Value(name string) CustomFloat64Value

func (CustomFloat64Value) Render added in v0.2.0

func (c CustomFloat64Value) Render() ([]byte, error)

type CustomInt64Type added in v0.2.0

type CustomInt64Type struct {
	Name FrameworkIdentifier
	// contains filtered or unexported fields
}

func NewCustomInt64Type added in v0.2.0

func NewCustomInt64Type(name string) CustomInt64Type

func (CustomInt64Type) Render added in v0.2.0

func (c CustomInt64Type) Render() ([]byte, error)

type CustomInt64Value added in v0.2.0

type CustomInt64Value struct {
	Name FrameworkIdentifier
	// contains filtered or unexported fields
}

func NewCustomInt64Value added in v0.2.0

func NewCustomInt64Value(name string) CustomInt64Value

func (CustomInt64Value) Render added in v0.2.0

func (c CustomInt64Value) Render() ([]byte, error)

type CustomNumberType added in v0.2.0

type CustomNumberType struct {
	Name FrameworkIdentifier
	// contains filtered or unexported fields
}

func NewCustomNumberType added in v0.2.0

func NewCustomNumberType(name string) CustomNumberType

func (CustomNumberType) Render added in v0.2.0

func (c CustomNumberType) Render() ([]byte, error)

type CustomNumberValue added in v0.2.0

type CustomNumberValue struct {
	Name FrameworkIdentifier
	// contains filtered or unexported fields
}

func NewCustomNumberValue added in v0.2.0

func NewCustomNumberValue(name string) CustomNumberValue

func (CustomNumberValue) Render added in v0.2.0

func (c CustomNumberValue) Render() ([]byte, error)

type CustomObjectType

type CustomObjectType struct {
	Name       FrameworkIdentifier
	AttrValues map[FrameworkIdentifier]string
	// contains filtered or unexported fields
}

func NewCustomObjectType

func NewCustomObjectType(name string, attrValues map[string]string) CustomObjectType

func (CustomObjectType) Render

func (c CustomObjectType) Render() ([]byte, error)

type CustomObjectValue

type CustomObjectValue struct {
	Name           FrameworkIdentifier
	AttributeTypes map[FrameworkIdentifier]string
	AttrTypes      map[FrameworkIdentifier]string
	AttrValues     map[FrameworkIdentifier]string
	// contains filtered or unexported fields
}

func NewCustomObjectValue

func NewCustomObjectValue(name string, attributeTypes, attrTypes, attrValues map[string]string) CustomObjectValue

func (CustomObjectValue) Render

func (c CustomObjectValue) Render() ([]byte, error)

type CustomStringType added in v0.2.0

type CustomStringType struct {
	Name FrameworkIdentifier
	// contains filtered or unexported fields
}

func NewCustomStringType added in v0.2.0

func NewCustomStringType(name string) CustomStringType

func (CustomStringType) Render added in v0.2.0

func (c CustomStringType) Render() ([]byte, error)

type CustomStringValue added in v0.2.0

type CustomStringValue struct {
	Name FrameworkIdentifier
	// contains filtered or unexported fields
}

func NewCustomStringValue added in v0.2.0

func NewCustomStringValue(name string) CustomStringValue

func (CustomStringValue) Render added in v0.2.0

func (c CustomStringValue) Render() ([]byte, error)

type CustomTypeAndValue

type CustomTypeAndValue interface {
	CustomTypeAndValue(name string) ([]byte, error)
}

type Elements

type Elements interface {
	ElemType() specschema.ElementType
}

type FrameworkIdentifier

type FrameworkIdentifier string

FrameworkIdentifier is a string that implements helpful methods for validating and converting identifier names that are valid in Terraform Plugin Framework

func (FrameworkIdentifier) ToCamelCase

func (identifier FrameworkIdentifier) ToCamelCase() string

ToCamelCase will return a camel case formatted string of the identifier. Example:

  • example_resource_thing -> exampleResourceThing

func (FrameworkIdentifier) ToPascalCase

func (identifier FrameworkIdentifier) ToPascalCase() string

ToPascalCase will return a pascal case formatted string of the identifier. Example:

  • example_resource_thing -> ExampleResourceThing

func (FrameworkIdentifier) ToString

func (identifier FrameworkIdentifier) ToString() string

ToString returns the FrameworkIdentifier as a string without any formatting. Example:

  • example_resource_thing -> example_resource_thing

func (FrameworkIdentifier) Valid

func (identifier FrameworkIdentifier) Valid() bool

Valid will return whether the identifier string is a valid identifier in Terraform Plugin Framework

type From added in v0.2.0

type From interface {
	From() ToFromConversion
}

type GeneratorAttribute

type GeneratorAttribute interface {
	Equal(GeneratorAttribute) bool
	GeneratorSchemaType() Type
	Imports() *Imports
	ModelField(FrameworkIdentifier) (model.Field, error)
	Schema(FrameworkIdentifier) (string, error)
}

type GeneratorAttributeAssocExtType

type GeneratorAttributeAssocExtType interface {
	GeneratorAttribute
	AssocExtType() *AssocExtType
}

type GeneratorAttributes

type GeneratorAttributes map[string]GeneratorAttribute

func (GeneratorAttributes) AttrTypes

func (g GeneratorAttributes) AttrTypes() (map[string]string, error)

AttrTypes returns a mapping of attribute names to string representations of the underlying attr.Type.

func (GeneratorAttributes) AttrValues

func (g GeneratorAttributes) AttrValues() (map[string]string, error)

AttrValues returns a mapping of attribute names to string representations of the underlying attr.Value.

func (GeneratorAttributes) AttributeTypes

func (g GeneratorAttributes) AttributeTypes() (map[string]string, error)

AttributeTypes returns a mapping of attribute names to string representations of the attribute type.

func (GeneratorAttributes) FromFuncs

func (g GeneratorAttributes) FromFuncs() map[string]ToFromConversion

FromFuncs returns a mapping of attribute names to string representations of the function that converts a Go value to a framework value.

func (GeneratorAttributes) Schema

func (g GeneratorAttributes) Schema() (string, error)

func (GeneratorAttributes) SortedKeys

func (g GeneratorAttributes) SortedKeys() []string

func (GeneratorAttributes) ToFuncs

ToFuncs returns a mapping of attribute names to string representations of the function that converts a framework value to a Go value.

type GeneratorBlock

type GeneratorBlock interface {
	Equal(GeneratorBlock) bool
	GeneratorSchemaType() Type
	Imports() *Imports
	ModelField(FrameworkIdentifier) (model.Field, error)
	Schema(FrameworkIdentifier) (string, error)
}

type GeneratorBlockAssocExtType

type GeneratorBlockAssocExtType interface {
	GeneratorBlock
	AssocExtType() *AssocExtType
}

type GeneratorBlocks

type GeneratorBlocks map[string]GeneratorBlock

func (GeneratorBlocks) AttrTypes

func (g GeneratorBlocks) AttrTypes() (map[string]string, error)

AttrTypes returns a mapping of block names to string representations of the underlying attr.Type.

func (GeneratorBlocks) AttrValues

func (g GeneratorBlocks) AttrValues() (map[string]string, error)

AttrValues returns a mapping of block names to string representations of the underlying attr.Value.

func (GeneratorBlocks) BlockTypes

func (g GeneratorBlocks) BlockTypes() (map[string]string, error)

BlockTypes returns a mapping of block names to string representations of the block type.

func (GeneratorBlocks) FromFuncs

func (g GeneratorBlocks) FromFuncs() map[string]string

FromFuncs returns a mapping of block names to string representations of the function that converts a Go value to a framework value.

func (GeneratorBlocks) Schema

func (g GeneratorBlocks) Schema() (string, error)

func (GeneratorBlocks) SortedKeys

func (g GeneratorBlocks) SortedKeys() []string

func (GeneratorBlocks) ToFuncs

func (g GeneratorBlocks) ToFuncs() map[string]string

ToFuncs returns a mapping of block names to string representations of the function that converts a framework value to a Go value.

type GeneratorSchema

type GeneratorSchema struct {
	Attributes GeneratorAttributes
	Blocks     GeneratorBlocks
}

func (GeneratorSchema) CustomTypeValueBytes

func (g GeneratorSchema) CustomTypeValueBytes() ([]byte, error)

CustomTypeValueBytes iterates over all the attributes and blocks to generate code for custom type and value types for use in the schema and data models.

func (GeneratorSchema) Imports

func (g GeneratorSchema) Imports() (string, error)

func (GeneratorSchema) Models

func (g GeneratorSchema) Models(name string) ([]model.Model, error)

func (GeneratorSchema) Schema

func (g GeneratorSchema) Schema(name, packageName, generatorType string) ([]byte, error)

func (GeneratorSchema) ToFromFunctions

func (g GeneratorSchema) ToFromFunctions() ([]byte, error)

ToFromFunctions generates code for converting to an associated external type from a framework type, and from an associated external type to a framework type.

type GeneratorSchemas

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

TODO: Field(s) could be added to handle end-user supplying their own templates to allow overriding.

func NewGeneratorSchemas

func NewGeneratorSchemas(schemas map[string]GeneratorSchema) GeneratorSchemas

func (GeneratorSchemas) CustomTypeValue

func (g GeneratorSchemas) CustomTypeValue() (map[string][]byte, error)

func (GeneratorSchemas) Models

func (g GeneratorSchemas) Models() (map[string][]byte, error)

func (GeneratorSchemas) Schemas

func (g GeneratorSchemas) Schemas(packageName, generatorType string) (map[string][]byte, error)

func (GeneratorSchemas) ToFromFunctions

func (g GeneratorSchemas) ToFromFunctions() (map[string][]byte, error)

type Imports

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

func AssociatedExternalTypeImports added in v0.2.0

func AssociatedExternalTypeImports() *Imports

func AttrImports

func AttrImports() *Imports

func CustomDefaultImports

func CustomDefaultImports(c *specschema.CustomDefault) *Imports

func CustomPlanModifierImports

func CustomPlanModifierImports(c *specschema.CustomPlanModifier) *Imports

func CustomTypeImports

func CustomTypeImports(c *specschema.CustomType) *Imports

func CustomValidatorImports

func CustomValidatorImports(cv *specschema.CustomValidator) *Imports

func GetAttrTypesImports

func GetAttrTypesImports(customType *specschema.CustomType, attrTypes specschema.ObjectAttributeTypes) *Imports

func GetElementTypeImports

func GetElementTypeImports(e specschema.ElementType) *Imports

func NewImports

func NewImports() *Imports

func (*Imports) Add

func (i *Imports) Add(c ...code.Import)

func (*Imports) All

func (i *Imports) All() []code.Import

func (*Imports) Append

func (i *Imports) Append(imps ...*Imports)

type To added in v0.2.0

type To interface {
	To() ToFromConversion
}

type ToFrom

type ToFrom interface {
	ToFromFunctions(name string) ([]byte, error)
}

type ToFromBool added in v0.2.0

type ToFromBool struct {
	Name         FrameworkIdentifier
	AssocExtType *AssocExtType
	// contains filtered or unexported fields
}

func NewToFromBool added in v0.2.0

func NewToFromBool(name string, assocExtType *AssocExtType) ToFromBool

func (ToFromBool) Render added in v0.2.0

func (o ToFromBool) Render() ([]byte, error)

type ToFromConversion added in v0.2.0

type ToFromConversion struct {
	Default      string
	AssocExtType *AssocExtType
}

type ToFromFloat64 added in v0.2.0

type ToFromFloat64 struct {
	Name         FrameworkIdentifier
	AssocExtType *AssocExtType
	// contains filtered or unexported fields
}

func NewToFromFloat64 added in v0.2.0

func NewToFromFloat64(name string, assocExtType *AssocExtType) ToFromFloat64

func (ToFromFloat64) Render added in v0.2.0

func (o ToFromFloat64) Render() ([]byte, error)

type ToFromInt64 added in v0.2.0

type ToFromInt64 struct {
	Name         FrameworkIdentifier
	AssocExtType *AssocExtType
	// contains filtered or unexported fields
}

func NewToFromInt64 added in v0.2.0

func NewToFromInt64(name string, assocExtType *AssocExtType) ToFromInt64

func (ToFromInt64) Render added in v0.2.0

func (o ToFromInt64) Render() ([]byte, error)

type ToFromNumber added in v0.2.0

type ToFromNumber struct {
	Name         FrameworkIdentifier
	AssocExtType *AssocExtType
	// contains filtered or unexported fields
}

func NewToFromNumber added in v0.2.0

func NewToFromNumber(name string, assocExtType *AssocExtType) ToFromNumber

func (ToFromNumber) Render added in v0.2.0

func (o ToFromNumber) Render() ([]byte, error)

type ToFromObject

type ToFromObject struct {
	Name         FrameworkIdentifier
	AssocExtType *AssocExtType
	ToFuncs      map[FrameworkIdentifier]ToFromConversion
	FromFuncs    map[FrameworkIdentifier]ToFromConversion
	// contains filtered or unexported fields
}

func NewToFromObject

func NewToFromObject(name string, assocExtType *AssocExtType, toFuncs, fromFuncs map[string]ToFromConversion) ToFromObject

func (ToFromObject) Render

func (o ToFromObject) Render() ([]byte, error)

type ToFromString added in v0.2.0

type ToFromString struct {
	Name         FrameworkIdentifier
	AssocExtType *AssocExtType
	// contains filtered or unexported fields
}

func NewToFromString added in v0.2.0

func NewToFromString(name string, assocExtType *AssocExtType) ToFromString

func (ToFromString) Render added in v0.2.0

func (o ToFromString) Render() ([]byte, error)

type Type

type Type int64
const (
	InvalidGeneratorSchemaType Type = iota
	GeneratorBoolAttribute
	GeneratorFloat64Attribute
	GeneratorInt64Attribute
	GeneratorListAttribute
	GeneratorListNestedAttribute
	GeneratorListNestedBlock
	GeneratorMapAttribute
	GeneratorMapNestedAttribute
	GeneratorNumberAttribute
	GeneratorObjectAttribute
	GeneratorSetAttribute
	GeneratorSetNestedAttribute
	GeneratorSetNestedBlock
	GeneratorSingleNestedAttribute
	GeneratorSingleNestedBlock
	GeneratorStringAttribute
)

Jump to

Keyboard shortcuts

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