traverser

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2025 License: Apache-2.0 Imports: 5 Imported by: 8

Documentation

Index

Constants

View Source
const (
	// FieldPathWildcard is the wildcard expression in fieldpath indices.
	FieldPathWildcard = "*"
)

Variables

This section is empty.

Functions

func AccessSchema

func AccessSchema(sch any, path []string, accessors ...SchemaAccessor) error

AccessSchema accesses the schema element at the specified path and calls the given schema accessors in order. Reports any errors encountered by the accessors. The terminal node at the end of the specified path must be a *schema.Resource or an error will be reported. The specified path must have at least one component.

func FieldPath

func FieldPath(parts []string) string

FieldPath joins the given segment strings into a field path eliminating the wildcard index segments.

func FieldPathWithWildcard

func FieldPathWithWildcard(parts []string) string

FieldPathWithWildcard joins the given segment strings into a field path.

func Traverse

func Traverse(tfName string, tfResource *schema.Resource, visitors ...SchemaTraverser) error

Traverse traverses the Terraform schema of the given Terraform resource with the given Terraform resource name and visits each of the specified visitors on the traversed schema's nodes. If any of the visitors in the chain reports an error, it stops the traversal.

Types

type Element

type Element interface {
	Accept(v SchemaTraverser) error
}

Element represents a schema element being visited and should Accept a visitor.

type Node

type Node struct {
	// TFName is the Terraform resource name
	TFName string
	// Schema is the Terraform schema associated with the visited node during a
	// traversal.
	Schema *schema.Schema
	// CRDPath is the canonical CRD field path for the node being visited.
	CRDPath []string
	// TFPath is the canonical Terraform field path for the node being visited.
	TFPath []string
}

Node represents a schema node that's being traversed.

type NoopTraverser

type NoopTraverser struct{}

NoopTraverser is a traverser that doesn't do anything when visiting a node. Meant to make the implementation of visitors easy for the cases they are not interested in a specific node type.

func (NoopTraverser) VisitResource

func (n NoopTraverser) VisitResource(*ResourceNode) error

func (NoopTraverser) VisitSchema

func (n NoopTraverser) VisitSchema(*SchemaNode) error

type ResourceNode

type ResourceNode struct {
	Node
	// ElemResource is the resource schema for the Terraform element
	// of the node being visited.
	ElemResource *schema.Resource
}

ResourceNode represents a Terraform schema.Resource node.

func (*ResourceNode) Accept

func (r *ResourceNode) Accept(v SchemaTraverser) error

type SchemaAccessor

type SchemaAccessor func(*schema.Schema) error

SchemaAccessor is a function that accesses and potentially modifies a Terraform schema.

type SchemaNode

type SchemaNode struct {
	Node
	// ElemSchema is the schema for the Terraform element of the node being
	// visited.
	ElemSchema *schema.Schema
}

SchemaNode represents a Terraform schema.Schema node.

func (*SchemaNode) Accept

func (s *SchemaNode) Accept(v SchemaTraverser) error

type SchemaTraverser

type SchemaTraverser interface {
	// VisitSchema is called on a Terraform schema.Schema node.
	VisitSchema(s *SchemaNode) error
	// VisitResource is called on a Terraform schema.Resource node.
	VisitResource(r *ResourceNode) error
}

SchemaTraverser represents a visitor on the schema.Schema and schema.Resource nodes of a Terraform resource schema.

func NewMaxItemsSync

func NewMaxItemsSync(s TFResourceSchema) SchemaTraverser

NewMaxItemsSync returns a new schema traverser capable of syncing the MaxItems constraints from the Go schema to the specified JSON schema. This will ensure the generation time and the runtime schema MaxItems constraints will be consistent. This is needed only if the generation time and runtime schemas differ.

type TFResourceSchema

type TFResourceSchema map[string]*schema.Resource

TFResourceSchema represents a provider's Terraform resource schema.

func (TFResourceSchema) Traverse

func (s TFResourceSchema) Traverse(visitors ...SchemaTraverser) error

Traverse traverses the receiver schema using the specified visitors. Reports any errors encountered by the visitors.

Jump to

Keyboard shortcuts

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