lang

package
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MPL-2.0 Imports: 29 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package lang deals with the runtime aspects of Bogform's configuration language, with concerns such as expression evaluation. It is closely related to sibling package "configs", which is responsible for configuration parsing and static validation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CustomFunctionsInExpr

func CustomFunctionsInExpr(parseRef ParseRef, expr hcl.Expression) ([]*addrs.Reference, tfdiags.Diagnostics)

CustomFunctionsInExpr is a helper wrapper around References that searches for function traversals in an ExpressionWithFunctions, then converts the traversals into references

func References

func References(parseRef ParseRef, traversals []hcl.Traversal) ([]*addrs.Reference, tfdiags.Diagnostics)

References finds all of the references in the given set of traversals, returning diagnostics if any of the traversals cannot be interpreted as a reference.

This function does not do any de-duplication of references, since references have source location information embedded in them and so any invalid references that are duplicated should have errors reported for each occurrence.

If the returned diagnostics contains errors then the result may be incomplete or invalid. Otherwise, the returned slice has one reference per given traversal, though it is not guaranteed that the references will appear in the same order as the given traversals.

func ReferencesInBlock

func ReferencesInBlock(parseRef ParseRef, body hcl.Body, schema *configschema.Block) ([]*addrs.Reference, tfdiags.Diagnostics)

ReferencesInBlock is a helper wrapper around References that first searches the given body for traversals, before converting those traversals to references.

A block schema must be provided so that this function can determine where in the body variables are expected.

func ReferencesInExpr

func ReferencesInExpr(parseRef ParseRef, expr hcl.Expression) ([]*addrs.Reference, tfdiags.Diagnostics)

ReferencesInExpr is a helper wrapper around References that first searches the given expression for traversals, before converting those traversals to references.

Types

type Data

Data is an interface whose implementations can provide cty.Value representations of objects identified by referenceable addresses from the addrs package.

This interface will grow each time a new type of reference is added, and so implementations outside of the Bogform codebases are not advised.

Each method returns a suitable value and optionally some diagnostics. If the returned diagnostics contains errors then the type of the returned value is used to construct an unknown value of the same type which is then used in place of the requested object so that type checking can still proceed. In cases where it's not possible to even determine a suitable result type, cty.DynamicVal is returned along with errors describing the problem.

type ParseRef

type ParseRef func(traversal hcl.Traversal) (*addrs.Reference, tfdiags.Diagnostics)

type Scope

type Scope struct {
	// Data is used to resolve references in expressions.
	Data Data

	// ParseRef is a function that the scope uses to extract references from
	// a hcl.Traversal. This controls the type of references the scope currently
	// supports. As an example, the testing scope can reference outputs directly
	// while the main Bogform context scope can not. This means that this
	// function for the testing scope will happily return outputs, while the
	// main context scope would fail if a user attempts to reference an output.
	ParseRef ParseRef

	// SelfAddr is the address that the "self" object should be an alias of,
	// or nil if the "self" object should not be available at all.
	SelfAddr addrs.Referenceable

	// SourceAddr is the address of the source item for the scope. This will
	// affect any scoped resources that can be accessed from within this scope.
	//
	// If nil, access is assumed to be at the module level. So, in practice this
	// only needs to be set for items that should be able to access something
	// hidden in their own scope.
	SourceAddr addrs.Referenceable

	// BaseDir is the base directory used by any interpolation functions that
	// accept filesystem paths as arguments.
	BaseDir string

	// PureOnly can be set to true to request that any non-pure functions
	// produce unknown value results rather than actually executing. This is
	// important during a plan phase to avoid generating results that could
	// then differ during apply.
	PureOnly bool

	// ConsoleMode can be set to true to request any console-only functions are
	// included in this scope.
	ConsoleMode bool

	// PlanTimestamp is a timestamp representing when the plan was made. It will
	// either have been generated during this operation or read from the plan.
	PlanTimestamp time.Time

	ProviderFunctions ProviderFunction

	SymbolTable symlib.Table
	// contains filtered or unexported fields
}

Scope is the main type in this package, allowing dynamic evaluation of blocks and expressions based on some contextual information that informs which variables and functions will be available.

func (*Scope) EvalBlock

func (s *Scope) EvalBlock(ctx context.Context, body hcl.Body, schema *configschema.Block) (cty.Value, tfdiags.Diagnostics)

EvalBlock evaluates the given body using the given block schema and returns a cty object value representing its contents. The type of the result conforms to the implied type of the given schema.

This function does not automatically expand "dynamic" blocks within the body. If that is desired, first call the ExpandBlock method to obtain an expanded body to pass to this method.

If the returned diagnostics contains errors then the result may be incomplete or invalid.

func (*Scope) EvalContext

func (s *Scope) EvalContext(ctx context.Context, refs []*addrs.Reference) (*hcl.EvalContext, tfdiags.Diagnostics)

EvalContext constructs a HCL expression evaluation context whose variable scope contains sufficient values to satisfy the given set of references.

Most callers should prefer to use the evaluation helper methods that this type offers, but this is here for less common situations where the caller will handle the evaluation calls itself.

The context.Context passed to this function is the one that will be used when making requests to providers if any of the references are to provider-defined functions, and so callers should typically use the resulting evaluation context immediately after the call and not share it with other parts of the system where a different context.Context would be more appropriate to use.

func (*Scope) EvalContextWithParent

func (s *Scope) EvalContextWithParent(ctx context.Context, p *hcl.EvalContext, refs []*addrs.Reference) (*hcl.EvalContext, tfdiags.Diagnostics)

EvalContextWithParent is exactly the same as EvalContext except the resulting hcl.EvalContext will be derived from the given parental hcl.EvalContext. It will enable different hcl mechanisms to iteratively lookup target functions and variables in EvalContext's parent. See Traversal.TraverseAbs (hcl) or FunctionCallExpr.Value (hcl/hclsyntax) for more details.

func (*Scope) EvalExpr

func (s *Scope) EvalExpr(ctx context.Context, expr hcl.Expression, wantType cty.Type) (cty.Value, tfdiags.Diagnostics)

EvalExpr evaluates a single expression in the receiving context and returns the resulting value. The value will be converted to the given type before it is returned if possible, or else an error diagnostic will be produced describing the conversion error.

Pass an expected type of cty.DynamicPseudoType to skip automatic conversion and just obtain the returned value directly.

If the returned diagnostics contains errors then the result may be incomplete, but will always be of the requested type.

func (*Scope) EvalReference

func (s *Scope) EvalReference(ctx context.Context, ref *addrs.Reference, wantType cty.Type) (cty.Value, tfdiags.Diagnostics)

EvalReference evaluates the given reference in the receiving scope and returns the resulting value. The value will be converted to the given type before it is returned if possible, or else an error diagnostic will be produced describing the conversion error.

Pass an expected type of cty.DynamicPseudoType to skip automatic conversion and just obtain the returned value directly.

If the returned diagnostics contains errors then the result may be incomplete, but will always be of the requested type.

func (*Scope) EvalSelfBlock

func (s *Scope) EvalSelfBlock(ctx context.Context, body hcl.Body, self cty.Value, schema *configschema.Block, keyData instances.RepetitionData) (cty.Value, tfdiags.Diagnostics)

EvalSelfBlock evaluates the given body only within the scope of the provided object and instance key data. References to the object must use self, and the key data will only contain count.index or each.key. The static values for terraform and path will also be available in this context.

func (*Scope) ExpandBlock

func (s *Scope) ExpandBlock(ctx context.Context, body hcl.Body, schema *configschema.Block) (hcl.Body, tfdiags.Diagnostics)

ExpandBlock expands any "dynamic" blocks present in the given body. The result is a body with those blocks expanded, ready to be evaluated with EvalBlock.

If the returned diagnostics contains errors then the result may be incomplete or invalid.

func (*Scope) Functions

func (s *Scope) Functions() map[string]function.Function

Functions returns the set of functions that should be used to when evaluating expressions in the receiving scope.

func (*Scope) SetActiveExperiments

func (s *Scope) SetActiveExperiments(active experiments.Set)

SetActiveExperiments allows a caller to declare that a set of experiments is active for the module that the receiving Scope belongs to, which might then cause the scope to activate some additional experimental behaviors.

type TypeConversionConstraint

type TypeConversionConstraint struct {
	// ConvertTarget is the conversion target type to pass to cty's
	// [convert.Convert] for the main type conversion step.
	ConvertTarget cty.Type

	// DefaultAttrVals represents any default values provided for optional
	// attributes in ConvertTarget, to be applied using
	// [typeexpr.Defaults.Apply] as part of the overall conversion process.
	//
	// This can be nil for a conversion target that does not include any
	// optional attributes.
	DefaultAttrVals *typeexpr.Defaults
}

TypeConversionConstraint describes the intended result of a type conversion, typically specified by an author using the Bogform language's type constraint syntax.

To accept an object of this type from a parameter to a built-in function in the Bogform language, declare the parameter as expecting [TypeConversionType]. That capsule type has a custom decode implementation that expects the expression syntax implemented by ParseTypeConversionConstraint.

func NewTypeConversionConstraint

func NewTypeConversionConstraint(convertTarget cty.Type, defaultAttrVals *typeexpr.Defaults) TypeConversionConstraint

NewTypeConversionConstraint constructs a TypeConversionConstraint directly from its component parts.

This is here only to accommodate some historical constraints of the config loader in "package configs", which prefers to store the two component parts separately in its representation of an input variable instead of directly storing a TypeConversionConstraint.

func ParseTypeConversionConstraint

func ParseTypeConversionConstraint(expr hcl.Expression, typeCtx *typeexpr.TypeContext) (TypeConversionConstraint, tfdiags.Diagnostics)

ParseTypeConversionConstraint attempts to analyze the given expression to interpret it as the target type constraint for a type conversion.

This function implements the language used in the "type" argument of a "variable" block in the Bogform language, and any other language feature that performs type conversion to an author-specified type.

func (TypeConversionConstraint) ConvertValue

func (c TypeConversionConstraint) ConvertValue(val cty.Value) (cty.Value, error)

ConvertValue attempts to convert the given value to conform to the constraint represented by the receiver.

This function just encapsulates the required interaction between convert.Convert and typeexpr.Defaults.Apply to ensure that type conversion always treats both target type and default attribute values consistently across all language features that perform conversion to an author-specified type constraint.

If this function returns an error then it may be a cty.PathError describing a problem nested somewhere inside the given complex value. If presenting the error as part of a diagnostic message, use tfdiags.FormatError to include a user-friendly version of the relevant path, if any.

Directories

Path Synopsis
Package blocktoattr includes some helper functions that can perform preprocessing on a HCL body where a configschema.Block schema is available in order to allow list and set attributes defined in the schema to be optionally written by the user as block syntax.
Package blocktoattr includes some helper functions that can perform preprocessing on a HCL body where a configschema.Block schema is available in order to allow list and set attributes defined in the schema to be optionally written by the user as block syntax.
Package eval aims to encapsulate the details of evaluating the objects in an overall configuration, including all of the expressions written inside their declarations, in a way that can be reused across various different phases of execution.
Package eval aims to encapsulate the details of evaluating the objects in an overall configuration, including all of the expressions written inside their declarations, in a way that can be reused across various different phases of execution.
internal/tofu2024
Package tofu2024 contains the "module compiler" implementation for the first edition of the Bogform language, established with OpenTofu v1.6 in 2024 and then gradually evolved in backward-compatible ways.
Package tofu2024 contains the "module compiler" implementation for the first edition of the Bogform language, established with OpenTofu v1.6 in 2024 and then gradually evolved in backward-compatible ways.
Package exprs contains supporting code for expression evaluation.
Package exprs contains supporting code for expression evaluation.
Package globalref is home to some analysis algorithms that aim to answer questions about references between objects and object attributes across an entire configuration.
Package globalref is home to some analysis algorithms that aim to answer questions about references between objects and object attributes across an entire configuration.
Package grapheval contains some low-level helpers for coordinating interdependent work happening across different parts of the system, including detection and reporting of self-dependency problems that would otherwise cause a deadlock.
Package grapheval contains some low-level helpers for coordinating interdependent work happening across different parts of the system, including detection and reporting of self-dependency problems that would otherwise cause a deadlock.
Package lint contains a collection of helpers for performing "lint-like" checks to try to detect configuration constructs that are valid but nonetheless very likely to be a mistake.
Package lint contains a collection of helpers for performing "lint-like" checks to try to detect configuration constructs that are valid but nonetheless very likely to be a mistake.
Package types contains non-standard cty types used only within Bogform.
Package types contains non-standard cty types used only within Bogform.

Jump to

Keyboard shortcuts

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