golden

package module
v0.0.0-...-e2d562b Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 24 Imported by: 2

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, and variable support is in our roadmap.

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 Validate = validator.New(validator.WithRequiredStructEnabled())

Functions

func BlockToString

func BlockToString(f Block) string

func Blocks

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

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 ToCtyValue

func ToCtyValue(input any) cty.Value

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

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 {
	// contains filtered or unexported fields
}

func NewBasicConfig

func NewBasicConfig(basedir string, ctx context.Context) *BaseConfig

func (*BaseConfig) Context

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

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

type BlockType interface {
	BlockType() string
}

type Config

type Config interface {
	Context() context.Context
	EvalContext() *hcl.EvalContext
	RunPrePlan() error
	RunPlan() error
	ValidBlockAddress(address string) bool
	// 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 NewHclBlock

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

func (*HclBlock) Attributes

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

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

Jump to

Keyboard shortcuts

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