schema

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 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 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

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) ToPascalCase

func (a *AssocExtType) ToPascalCase() string

func (*AssocExtType) Type

func (a *AssocExtType) Type() string

func (*AssocExtType) TypeReference

func (a *AssocExtType) TypeReference() 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 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 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 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]string

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

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

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

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

type ToFromObject

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

func NewToFromObject

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

func (ToFromObject) Render

func (o ToFromObject) 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