lang

package
v0.54.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2024 License: MPL-2.0, MPL-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMockFunction added in v0.51.0

func NewMockFunction(call *FunctionCall) function.Function

NewMockFunction creates a mock function that returns a dynamic value. This is primarily used to replace provider-defined functions.

func References

func References(traversals []hcl.Traversal) ([]*addrs.Reference, hcl.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 occurence.

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 ReferencesInExpr

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

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

Types

type CallStack added in v0.53.0

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

func NewCallStack added in v0.53.0

func NewCallStack() *CallStack

func (*CallStack) Clear added in v0.53.0

func (g *CallStack) Clear()

func (*CallStack) Empty added in v0.53.0

func (g *CallStack) Empty() bool

func (*CallStack) Pop added in v0.53.0

func (g *CallStack) Pop()

func (*CallStack) Push added in v0.53.0

func (g *CallStack) Push(addr addrs.Reference) hcl.Diagnostics

func (*CallStack) String added in v0.53.0

func (g *CallStack) String() string

type Data

type Data interface {
	GetCountAttr(addrs.CountAttr, hcl.Range) (cty.Value, hcl.Diagnostics)
	GetForEachAttr(addrs.ForEachAttr, hcl.Range) (cty.Value, hcl.Diagnostics)
	GetLocalValue(addrs.LocalValue, hcl.Range) (cty.Value, hcl.Diagnostics)
	GetPathAttr(addrs.PathAttr, hcl.Range) (cty.Value, hcl.Diagnostics)
	GetTerraformAttr(addrs.TerraformAttr, hcl.Range) (cty.Value, hcl.Diagnostics)
	GetInputVariable(addrs.InputVariable, hcl.Range) (cty.Value, hcl.Diagnostics)
}

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 Terraform 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 FunctionCall added in v0.51.0

type FunctionCall struct {
	Name      string
	ArgsCount int
}

FunctionCall represents a function call in an HCL expression. The difference with hclsyntax.FunctionCallExpr is that function calls are also available in JSON syntax.

func FunctionCallsInExpr added in v0.51.0

func FunctionCallsInExpr(expr hcl.Expression) ([]*FunctionCall, hcl.Diagnostics)

FunctionCallsInExpr finds all of the function calls in the given expression.

func (*FunctionCall) IsProviderDefined added in v0.51.0

func (f *FunctionCall) IsProviderDefined() bool

IsProviderDefined returns true if the function is provider-defined.

type Scope

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

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

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

	// CallStack is a stack for recording local value references to detect
	// circular references.
	CallStack *CallStack
	// 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) EvalContext

func (s *Scope) EvalContext(refs []*addrs.Reference, funcCalls []*FunctionCall) (*hcl.EvalContext, hcl.Diagnostics)

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

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.

func (*Scope) EvalExpr

func (s *Scope) EvalExpr(expr hcl.Expression, wantType cty.Type) (cty.Value, hcl.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) ExpandBlock

func (s *Scope) ExpandBlock(body hcl.Body, schema *hclext.BodySchema) (hcl.Body, hcl.Diagnostics)

ExpandBlock expands "dynamic" blocks and resources/modules with count/for_each. Note that Terraform only expands dynamic blocks, but TFLint also expands count/for_each here.

Expressions in expanded blocks are evaluated immediately, so all variables and function calls contained in attributes specified in the body schema are gathered.

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.

Directories

Path Synopsis
Package types contains non-standard cty types used only within Terraform.
Package types contains non-standard cty types used only within Terraform.

Jump to

Keyboard shortcuts

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