tfeval

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package tfeval evaluates local Terraform modules: bind inputs, resolve locals, recurse into nested modules, emit resources with concrete cty values where possible. Anything still unresolvable (e.g. data sources) stays cty.UnknownVal, not sentinels.

Index

Constants

View Source
const UnknownAttributePlaceholder = "__DD_TFEVAL_UNKNOWN__"

UnknownAttributePlaceholder is stored for cty unknown values when converting to the document shape rules consume, so keys stay present and MissingAttribute checks do not treat unresolved expressions as absent (which would false-positive).

Variables

This section is empty.

Functions

func AttributesToDocument

func AttributesToDocument(r *ResolvedResource) map[string]interface{}

AttributesToDocument converts a resolved resource's attributes into the map[string]interface{} shape the rule pipeline consumes. Every attribute is always included: unknown or unsupported values use UnknownAttributePlaceholder so presence-based rules do not fire false positives on unresolved expressions.

func CalledLocalDirs

func CalledLocalDirs(dir string) []string

CalledLocalDirs returns the resolved directories of every local module called from dir. Remote/registry sources are ignored.

func CalledModuleDirs added in v1.8.0

func CalledModuleDirs(dir string, resolver RemoteResolver) []string

func LoadRootVars

func LoadRootVars(dir string) map[string]cty.Value

LoadRootVars reads terraform.tfvars and *.auto.tfvars from dir and returns a variable map for use as root-module inputs. Terraform loads terraform.tfvars first, then *.auto.tfvars in lexicographic order; later files override earlier ones. Files that fail to read or parse are silently skipped.

func ResourceBaseName

func ResourceBaseName(name string) string

ResourceBaseName strips any count/for_each instance suffix from a resource Name (e.g. "k[0]" → "k", `k["dev"]` → "k"). Used by callers that need the bare label for rule matching or source-line lookups.

func StripGetterPrefix

func StripGetterPrefix(source string) string

StripGetterPrefix removes go-getter scheme prefixes so the source can be treated as a path. Compound prefixes like "git::file://./path" are fully stripped in two passes.

Types

type CallSite

type CallSite struct {
	ModuleName string
	Source     string
	CalledFrom string
	CalledLine int
}

CallSite records one hop in a module call chain.

type Evaluator

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

Evaluator evaluates local Terraform modules.

func New

func New() *Evaluator

func (*Evaluator) CalledModuleDirs added in v1.8.0

func (e *Evaluator) CalledModuleDirs(dir string) []string

func (*Evaluator) EvaluateModule

func (e *Evaluator) EvaluateModule(
	ctx context.Context,
	dir string,
	inputs map[string]cty.Value,
) (resources []ResolvedResource, outputs map[string]cty.Value, visitedChildDirs map[string]bool, err error)

EvaluateModule evaluates the module rooted at dir with the given inputs and returns all resources materialized by this module and its nested modules. visitedChildDirs contains every child directory that was successfully evaluated as a module (i.e. dirs that should be suppressed from standalone scanning).

func (*Evaluator) SetRemoteResolver added in v1.8.0

func (e *Evaluator) SetRemoteResolver(r RemoteResolver)

type RemoteResolver added in v1.8.0

type RemoteResolver func(source, version, callerFile, moduleName string) (dir string, ok bool)

RemoteResolver maps a non-local module call to its materialized directory on disk.

type ResolvedResource

type ResolvedResource struct {
	Type       string
	Name       string
	Attributes map[string]cty.Value

	// Source location and module address for finding attribution.
	DefinedIn     string
	DefLine       int
	ModuleAddress string // "" for root module resources
	CallChain     []CallSite
}

ResolvedResource is a resource block after evaluation with attributes resolved to concrete cty values where possible, unknown otherwise.

Jump to

Keyboard shortcuts

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