Documentation ¶
Overview ¶
Package eval provides both full and partial evaluation of HCL.
Index ¶
- Constants
- type Context
- func (c *Context) ChildContext() *Context
- func (c *Context) Copy() *Context
- func (c *Context) DeleteNamespace(name string)
- func (c *Context) Eval(expr hhcl.Expression) (cty.Value, error)
- func (c *Context) GetNamespace(name string) (cty.Value, bool)
- func (c *Context) HasNamespace(name string) bool
- func (c *Context) PartialEval(expr hhcl.Expression) (hhcl.Expression, bool, error)
- func (c *Context) SetEnv(environ []string)
- func (c *Context) SetFunction(name string, fn function.Function)
- func (c *Context) SetNamespace(name string, vals map[string]cty.Value)
- func (c *Context) SetNamespaceRaw(name string, val cty.Value)
- func (c *Context) Unwrap() *hhcl.EvalContext
- type CtyValue
- type Info
- type Object
- func (obj *Object) AsValueMap() map[string]cty.Value
- func (obj *Object) DeleteAt(path ObjectPath) error
- func (obj *Object) GetKeyPath(path ObjectPath) (Value, bool)
- func (obj *Object) Info() Info
- func (obj *Object) IsObject() bool
- func (obj *Object) MergeFailsIfKeyExists(path ObjectPath, value Value) error
- func (obj *Object) MergeNewKeys(path ObjectPath, value Value) error
- func (obj *Object) MergeOverwrite(path ObjectPath, value Value) error
- func (obj *Object) Set(key string, value Value)
- func (obj *Object) SetAt(path ObjectPath, value Value) error
- func (obj *Object) SetFrom(values map[string]Value) *Object
- func (obj *Object) SetFromCtyValues(values map[string]cty.Value, origin Info) *Object
- func (obj *Object) String() string
- type ObjectPath
- type Value
Constants ¶
const ( ErrPartial errors.Kind = "partial evaluation failed" ErrInterpolation errors.Kind = "interpolation failed" )
Errors returned when doing partial evaluation.
const ErrCannotExtendObject errors.Kind = "cannot extend object"
ErrCannotExtendObject is the error when an object cannot be extended.
const ErrEval errors.Kind = "eval expression"
ErrEval indicates a failure during the evaluation process
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context is used to evaluate HCL code.
func NewContext ¶
NewContext creates a new HCL evaluation context. The basedir is the base directory used by any interpolation functions that accept filesystem paths as arguments. The basedir must be an absolute path to a directory.
func NewContextFrom ¶
func NewContextFrom(ctx *hhcl.EvalContext) *Context
NewContextFrom creates a new evaluator from the hashicorp EvalContext.
func (*Context) ChildContext ¶ added in v0.9.0
ChildContext creates a new child HCL context that inherits all parent HCL variables and functions.
func (*Context) DeleteNamespace ¶
DeleteNamespace deletes the namespace name from the context. If name is not in the context, it's a no-op.
func (*Context) GetNamespace ¶
GetNamespace will retrieve the value for the given namespace.
func (*Context) HasNamespace ¶
HasNamespace returns true the evaluation context knows this namespace, false otherwise.
func (*Context) PartialEval ¶
func (c *Context) PartialEval(expr hhcl.Expression) (hhcl.Expression, bool, error)
PartialEval evaluates only the terramate variable expressions from the list of tokens, leaving all the rest as-is. It returns a modified list of tokens with no reference to terramate namespaced variables (global, let and terramate) and tm_ prefixed functions. It also returns a boolean that tells if the returned expression contains any unknown references (variables or functions). It try to reduce the expression to its simplest form, which means expressions with no unknowns are evaluated down to literals.
func (*Context) SetEnv ¶
SetEnv sets the given environment on the env namespace of the evaluation context. environ must be on the same format as os.Environ().
func (*Context) SetFunction ¶
SetFunction sets the function in the context.
func (*Context) SetNamespace ¶
SetNamespace will set the given values inside the given namespace on the evaluation context.
func (*Context) SetNamespaceRaw ¶ added in v0.10.1
SetNamespaceRaw set the given namespace name with the provided value, no matter what value type is it.
func (*Context) Unwrap ¶
func (c *Context) Unwrap() *hhcl.EvalContext
Unwrap returns the internal hhcl.EvalContext.
type CtyValue ¶
CtyValue is a wrapper for a raw cty value.
func NewCtyValue ¶
NewCtyValue creates a new cty.Value wrapper. Note: The cty.Value val is marked with the origin path and must be unmarked before use with any hashicorp API otherwise it panics.
type Info ¶
type Info struct { // Dir defines the directory from there the value is being instantiated, // which means it's the scope directory (not the file where it's defined). // For values that comes from imports, the Dir will be the directory // which imports the value. Dir project.Path // DefinedAt provides the source file where the value is defined. DefinedAt project.Path }
Info provides extra information for the configuration value.
type Object ¶
type Object struct { // Keys is a map of key names to values. Keys map[string]Value // contains filtered or unexported fields }
Object is an object container for cty.Value values supporting set at arbitrary accessor paths.
Eg.:
obj := eval.NewObject(origin) obj.Set("val", eval.NewObject())
The snippet above creates the object below:
{ val = {} }
Then values can be set inside obj.val by doing:
obj.SetAt(ObjectPath{"val", "test"}, eval.NewValue(cty.StringVal("test"), origin))
Of which creates the object below:
{ val = { test = "test" } }
func (*Object) AsValueMap ¶
AsValueMap returns a map of string to Hashicorp cty.Value.
func (*Object) DeleteAt ¶
func (obj *Object) DeleteAt(path ObjectPath) error
DeleteAt deletes the value at the specified path.
func (*Object) GetKeyPath ¶
func (obj *Object) GetKeyPath(path ObjectPath) (Value, bool)
GetKeyPath retrieves the value at path.
func (*Object) MergeFailsIfKeyExists ¶
func (obj *Object) MergeFailsIfKeyExists(path ObjectPath, value Value) error
MergeFailsIfKeyExists merge the value into obj but fails if any key in value exists in obj.
func (*Object) MergeNewKeys ¶
func (obj *Object) MergeNewKeys(path ObjectPath, value Value) error
MergeNewKeys merge the keys from value that doesn't exist in obj.
func (*Object) MergeOverwrite ¶
func (obj *Object) MergeOverwrite(path ObjectPath, value Value) error
MergeOverwrite merges value into obj by overwriting each key.
func (*Object) SetAt ¶
func (obj *Object) SetAt(path ObjectPath, value Value) error
SetAt sets a value at the specified path key.
func (*Object) SetFromCtyValues ¶
SetFromCtyValues sets the object from the values map.