golden

package module
v0.0.0-...-29ee5f6 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2025 License: MIT Imports: 32 Imported by: 5

README

Golden

Golden is a project implemented in Go language. It is a DSL (Domain Specific Language) engine that uses HCL (HashiCorp Configuration Language) as its base, like grept.

Golden assumes a DSL engine which is composited by Plan phase and Apply phase, just like Terraform.

It supports two block interfaces: PlanBlock and ApplyBlock, you can implement your own block type, in Terraform, there are data, resource, local, variable, output. In grept, there are data, rule, fix, local.

Golden has implemented local block.

Golden has implemented support for for_each and precondition in blocks.

A simple example to show how to customize your own DSL is in our roadmap.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MetaAttributeNames = hashset.New("for_each", "depends_on")
View Source
var MetaNestedBlockNames = hashset.New("precondition", "dynamic")
View Source
var NoValue = VariableValueRead{}

Functions

func AddCustomTypeMapping

func AddCustomTypeMapping[T any](customType cty.Type)

func BlockToString

func BlockToString(f Block) string

func Blocks

func Blocks[T Block](c directedAcyclicGraph) []T

func CloneHclSyntaxBlock

func CloneHclSyntaxBlock(hb *hclsyntax.Block) *hclsyntax.Block

func CtyValueToString

func CtyValueToString(val cty.Value) string

func Decode

func Decode(b Block) error

func GoTypeToCtyType

func GoTypeToCtyType(goType reflect.Type) cty.Type

func InitConfig

func InitConfig(config Config, hclBlocks []*HclBlock) error

func Int

func Int(i int) *int

func IsBlockTypeWanted

func IsBlockTypeWanted(bt string) bool

func RegisterBaseBlock

func RegisterBaseBlock(factory func() BlockType)

func RegisterBlock

func RegisterBlock(t Block)

func SingleValues

func SingleValues(blocks []SingleValueBlock) cty.Value

func StructToCtyType

func StructToCtyType(typ reflect.Type) cty.Type

func ToCtyValue

func ToCtyValue(input any) cty.Value

ToCtyValue is a function that converts a primary/collection type to cty.Value

func Traverse

func Traverse[T Block](c *BaseConfig, walker func(b T) error) error

func Value

func Value(b Block) map[string]cty.Value

func Values

func Values[T Block](blocks []T) cty.Value

Types

type ApplyBlock

type ApplyBlock interface {
	Block
	Apply() error
}

type BaseBlock

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

func NewBaseBlock

func NewBaseBlock(c Config, hb *HclBlock) *BaseBlock

func (*BaseBlock) Address

func (bb *BaseBlock) Address() string

func (*BaseBlock) BaseValues

func (bb *BaseBlock) BaseValues() map[string]cty.Value

func (*BaseBlock) Config

func (bb *BaseBlock) Config() Config

func (*BaseBlock) Context

func (bb *BaseBlock) Context() context.Context

func (*BaseBlock) EvalContext

func (bb *BaseBlock) EvalContext() *hcl.EvalContext

func (*BaseBlock) HclBlock

func (bb *BaseBlock) HclBlock() *HclBlock

func (*BaseBlock) Id

func (bb *BaseBlock) Id() string

func (*BaseBlock) Name

func (bb *BaseBlock) Name() string

func (*BaseBlock) PreConditionCheck

func (bb *BaseBlock) PreConditionCheck(ctx *hcl.EvalContext) ([]PreCondition, error)

type BaseConfig

type BaseConfig struct {
	OverrideFunctions map[string]function.Function
	// contains filtered or unexported fields
}

func NewBasicConfig

func NewBasicConfig(basedir, dslFullName, dslAbbreviation string, varConfigDir *string, cliFlagAssignedVariables []CliFlagAssignedVariables, ctx context.Context) *BaseConfig

func NewBasicConfigFromArgs

func NewBasicConfigFromArgs(a NewBaseConfigArgs) *BaseConfig

func (*BaseConfig) Context

func (c *BaseConfig) Context() context.Context

func (*BaseConfig) DslAbbreviation

func (c *BaseConfig) DslAbbreviation() string

func (*BaseConfig) DslFullName

func (c *BaseConfig) DslFullName() string

func (*BaseConfig) EmptyEvalContext

func (c *BaseConfig) EmptyEvalContext() *hcl.EvalContext

func (*BaseConfig) EvalContext

func (c *BaseConfig) EvalContext() *hcl.EvalContext

func (*BaseConfig) GetAncestors

func (c *BaseConfig) GetAncestors(id string) (map[string]interface{}, error)

func (*BaseConfig) GetChildren

func (c *BaseConfig) GetChildren(id string) (map[string]interface{}, error)

func (*BaseConfig) GetVertices

func (c *BaseConfig) GetVertices() map[string]interface{}

func (*BaseConfig) ReadVariablesFromSingleVarFile

func (c *BaseConfig) ReadVariablesFromSingleVarFile(fileContent []byte, fileName string) (map[string]VariableValueRead, error)

func (*BaseConfig) RunPlan

func (c *BaseConfig) RunPlan() error

func (*BaseConfig) RunPrePlan

func (c *BaseConfig) RunPrePlan() error

func (*BaseConfig) ValidBlockAddress

func (c *BaseConfig) ValidBlockAddress(address string) bool

type BaseDecode

type BaseDecode interface {
	BaseDecode(hb *HclBlock, context *hcl.EvalContext) error
}

type Block

type Block interface {
	Id() string
	Name() string
	Type() string
	BlockType() string
	Address() string
	HclBlock() *HclBlock
	EvalContext() *hcl.EvalContext
	BaseValues() map[string]cty.Value
	PreConditionCheck(*hcl.EvalContext) ([]PreCondition, error)
	AddressLength() int
	CanExecutePrePlan() bool
	Config() Config
	// contains filtered or unexported methods
}

type BlockCustomizedRefType

type BlockCustomizedRefType interface {
	CustomizedRefType() string
}

type BlockType

type BlockType interface {
	BlockType() string
}

type CliFlagAssignedVariable

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

func NewCliFlagAssignedVariable

func NewCliFlagAssignedVariable(varName, rawValue string) CliFlagAssignedVariable

func (CliFlagAssignedVariable) Variables

type CliFlagAssignedVariableFile

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

func NewCliFlagAssignedVariableFile

func NewCliFlagAssignedVariableFile(varFileName string) CliFlagAssignedVariableFile

func (CliFlagAssignedVariableFile) Variables

type CliFlagAssignedVariables

type CliFlagAssignedVariables interface {
	Variables(c *BaseConfig) (map[string]VariableValueRead, error)
}

type Config

type Config interface {
	Context() context.Context
	EmptyEvalContext() *hcl.EvalContext
	EvalContext() *hcl.EvalContext
	RunPrePlan() error
	RunPlan() error
	ValidBlockAddress(address string) bool
	DslFullName() string
	DslAbbreviation() string
	// contains filtered or unexported methods
}

type CustomDecode

type CustomDecode interface {
	Decode(*HclBlock, *hcl.EvalContext) error
}

type Dag

type Dag struct {
	*dag.DAG
}

type ForEach

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

func NewForEach

func NewForEach(key, value cty.Value) *ForEach

type HclAttribute

type HclAttribute struct {
	*hclsyntax.Attribute
	// contains filtered or unexported fields
}

func NewHclAttribute

func NewHclAttribute(ra *hclsyntax.Attribute, wa *hclwrite.Attribute) *HclAttribute

func (*HclAttribute) ExprString

func (ha *HclAttribute) ExprString() string

func (*HclAttribute) ExprTokens

func (ha *HclAttribute) ExprTokens() hclwrite.Tokens

func (*HclAttribute) Value

func (ha *HclAttribute) Value(ctx *hcl.EvalContext) (cty.Value, error)

type HclBlock

type HclBlock struct {
	*hclsyntax.Block

	*ForEach
	// contains filtered or unexported fields
}

func AsHclBlocks

func AsHclBlocks(syntaxBlocks hclsyntax.Blocks, writeBlocks []*hclwrite.Block) []*HclBlock

func CloneHclBlock

func CloneHclBlock(hb *HclBlock) *HclBlock

func NewHclBlock

func NewHclBlock(rb *hclsyntax.Block, wb *hclwrite.Block, each *ForEach) *HclBlock

func (*HclBlock) Attributes

func (hb *HclBlock) Attributes() map[string]*HclAttribute

func (*HclBlock) ExpandDynamicBlocks

func (hb *HclBlock) ExpandDynamicBlocks(evalContext *hcl.EvalContext) (*HclBlock, error)

func (*HclBlock) NestedBlocks

func (hb *HclBlock) NestedBlocks() []*HclBlock

type Local

type Local interface {
	SingleValueBlock
	// discriminator func
	Local()
}

type LocalBlock

type LocalBlock struct {
	*BaseBlock
	LocalValue cty.Value `hcl:"value"`
}

func (*LocalBlock) AddressLength

func (l *LocalBlock) AddressLength() int

func (*LocalBlock) BlockType

func (l *LocalBlock) BlockType() string

func (*LocalBlock) CanExecutePrePlan

func (l *LocalBlock) CanExecutePrePlan() bool

func (*LocalBlock) ExecuteBeforePlan

func (l *LocalBlock) ExecuteBeforePlan() error

func (*LocalBlock) ExecuteDuringPlan

func (l *LocalBlock) ExecuteDuringPlan() error

func (*LocalBlock) Local

func (l *LocalBlock) Local()

func (*LocalBlock) Type

func (l *LocalBlock) Type() string

func (*LocalBlock) Value

func (l *LocalBlock) Value() cty.Value

type NewBaseConfigArgs

type NewBaseConfigArgs struct {
	Basedir                  string
	VarConfigDir             *string
	Ctx                      context.Context
	DslAbbreviation          string
	DslFullName              string
	IgnoreUnknownVariables   bool
	CliFlagAssignedVariables []CliFlagAssignedVariables
}

type Plan

type Plan interface {
	String() string
	Apply() error
}

type PlanBlock

type PlanBlock interface {
	Block
	ExecuteDuringPlan() error
}

type PreCondition

type PreCondition struct {
	Body         *hclsyntax.Body
	Condition    bool   `hcl:"condition"`
	ErrorMessage string `hcl:"error_message,optional"`
}

type PrePlanBlock

type PrePlanBlock interface {
	ExecuteBeforePlan() error
}

type SingleValueBlock

type SingleValueBlock interface {
	Block
	Value() cty.Value
}

type Valuable

type Valuable interface {
	Values() map[string]cty.Value
}

type Variable

type Variable interface {
	SingleValueBlock
	Variable()
}

type VariableBlock

type VariableBlock struct {
	*BaseBlock
	Description *string
	Validations []VariableValidation
	// contains filtered or unexported fields
}

func (*VariableBlock) Address

func (v *VariableBlock) Address() string

func (*VariableBlock) AddressLength

func (v *VariableBlock) AddressLength() int

func (*VariableBlock) BlockType

func (v *VariableBlock) BlockType() string

func (*VariableBlock) CanExecutePrePlan

func (v *VariableBlock) CanExecutePrePlan() bool

func (*VariableBlock) CustomizedRefType

func (v *VariableBlock) CustomizedRefType() string

func (*VariableBlock) Decode

func (v *VariableBlock) Decode(block *HclBlock, context *hcl.EvalContext) error

func (*VariableBlock) ExecuteBeforePlan

func (v *VariableBlock) ExecuteBeforePlan() error

func (*VariableBlock) ExecuteDuringPlan

func (v *VariableBlock) ExecuteDuringPlan() error

func (*VariableBlock) Type

func (v *VariableBlock) Type() string

func (*VariableBlock) Value

func (v *VariableBlock) Value() cty.Value

func (*VariableBlock) Variable

func (v *VariableBlock) Variable()

type VariableValidation

type VariableValidation struct {
	Condition    bool   `hcl:"condition"`
	ErrorMessage string `hcl:"error_message"`
}

type VariableValueRead

type VariableValueRead struct {
	Name  string
	Value *cty.Value
	Error error
}

func NewVariableValueRead

func NewVariableValueRead(name string, value *cty.Value, err error) VariableValueRead

func (VariableValueRead) HasError

func (r VariableValueRead) HasError() bool

Jump to

Keyboard shortcuts

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