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
- func AttributesToDocument(r *ResolvedResource) map[string]interface{}
- func CalledLocalDirs(dir string) []string
- func CalledModuleDirs(dir string, resolver RemoteResolver) []string
- func LoadRootVars(dir string) map[string]cty.Value
- func ResourceBaseName(name string) string
- func StripGetterPrefix(source string) string
- type CallSite
- type Evaluator
- type RemoteResolver
- type ResolvedResource
Constants ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 Evaluator ¶
type Evaluator struct {
// contains filtered or unexported fields
}
Evaluator evaluates local Terraform modules.
func (*Evaluator) CalledModuleDirs ¶ added in v1.8.0
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
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.