Documentation ¶
Overview ¶
Implements the `Data` interface. Doesn't really do anything.
Utilities for working with expressions.
Look in `/pkg/hcl_interpreter/README.md` for an explanation of how this works.
This module contains utilities for parsing and traversing everything in a configuration tree.
cty.Value utilities
Index ¶
- Variables
- func ExprToLiteralString(expr hcl.Expression) *string
- func LocalNameToString(name LocalName) string
- func ModuleNameToString(moduleName ModuleName) string
- func PopulateTags(resource interface{})
- func PrettyValTree(tree ValTree) string
- func TfFilePathJoin(leading, trailing string) string
- func TraversalToString(traversal hcl.Traversal) string
- func ValTreeToValue(tree ValTree) cty.Value
- func ValTreeToVariables(tree ValTree) map[string]cty.Value
- func ValueToInt(val cty.Value) *int
- func ValueToInterface(val cty.Value) (interface{}, []error)
- func ValueToString(val cty.Value) *string
- type Analysis
- type Data
- func (c *Data) GetCountAttr(addrs.CountAttr, tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics)
- func (c *Data) GetForEachAttr(addrs.ForEachAttr, tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics)
- func (c *Data) GetInputVariable(v addrs.InputVariable, s tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics)
- func (c *Data) GetLocalValue(addrs.LocalValue, tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics)
- func (c *Data) GetModule(addrs.ModuleCall, tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics)
- func (c *Data) GetPathAttr(attr addrs.PathAttr, diags tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics)
- func (c *Data) GetResource(addrs.Resource, tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics)
- func (c *Data) GetTerraformAttr(addrs.TerraformAttr, tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics)
- func (c *Data) StaticValidateReferences(refs []*addrs.Reference, self addrs.Referenceable) tfdiags.Diagnostics
- type Evaluation
- type Fragment
- type FullName
- func (name FullName) AddIndex(i int) FullName
- func (name FullName) AddKey(k string) FullName
- func (name FullName) AddLocalName(after LocalName) FullName
- func (name FullName) AsModuleInput() *FullName
- func (name FullName) AsModuleOutput() *FullName
- func (name FullName) AsResourceName() (*FullName, int, LocalName)
- func (name FullName) AsVariable() (*FullName, *FullName, LocalName)
- func (name FullName) IsBuiltin() bool
- func (name FullName) ToString() string
- type LocalName
- type ModuleMeta
- type ModuleName
- type ModuleTree
- type ResourceMeta
- type TerraformModuleRegister
- type UnsupportedOperationDiag
- type ValTree
- func BuildValTree(name LocalName, sub ValTree) ValTree
- func EmptyObjectValTree() ValTree
- func LookupValTree(tree ValTree, name LocalName) ValTree
- func MergeValTree(left ValTree, right ValTree) ValTree
- func SingletonValTree(name LocalName, leaf cty.Value) ValTree
- func SparseValTree(original ValTree, name LocalName) ValTree
- type Visitor
Constants ¶
This section is empty.
Variables ¶
var EmptyModuleName = []string{}
Functions ¶
func ExprToLiteralString ¶
func ExprToLiteralString(expr hcl.Expression) *string
func LocalNameToString ¶
func ModuleNameToString ¶
func ModuleNameToString(moduleName ModuleName) string
func PopulateTags ¶
func PopulateTags(resource interface{})
func TfFilePathJoin ¶
TfFilePathJoin is like `filepath.Join` but avoids cleaning the path. This allows to get unique paths for submodules including a parent module, e.g.:
. examples/mssql/../../ examples/complete/../../
func TraversalToString ¶
func TraversalToString(traversal hcl.Traversal) string
func ValTreeToValue ¶
Convert a ValTree to an immutable cty.Value. Since this is expensive, it should only be used for relatively sparse trees, if possible.
func ValTreeToVariables ¶
Some HCL functions require it to be a map. Returns an empty map if we have anything but an object at the root.
func ValueToInt ¶
func ValueToInterface ¶
func ValueToString ¶
Types ¶
type Analysis ¶
type Analysis struct { Fs afero.Fs // Module metadata Modules map[string]*ModuleMeta // Resource metadata Resources map[string]*ResourceMeta // Holds all keys to expressions within resources. This is necessary if // we want to do dependency analysis and something depends on "all of // a resource". ResourceExpressions map[string][]FullName // All known expressions Expressions map[string]hcl.Expression // All known blocks Blocks []FullName // contains filtered or unexported fields }
func AnalyzeModuleTree ¶
func AnalyzeModuleTree(mtree *ModuleTree) *Analysis
func (*Analysis) EnterResource ¶
func (v *Analysis) EnterResource(name FullName, resource *ResourceMeta)
func (*Analysis) LeaveResource ¶
func (v *Analysis) LeaveResource()
func (*Analysis) VisitBlock ¶
func (*Analysis) VisitModule ¶
func (v *Analysis) VisitModule(name ModuleName, meta *ModuleMeta)
type Data ¶
type Data struct { }
func (*Data) GetCountAttr ¶
func (c *Data) GetCountAttr(addrs.CountAttr, tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics)
func (*Data) GetForEachAttr ¶
func (c *Data) GetForEachAttr(addrs.ForEachAttr, tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics)
func (*Data) GetInputVariable ¶
func (c *Data) GetInputVariable(v addrs.InputVariable, s tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics)
func (*Data) GetLocalValue ¶
func (c *Data) GetLocalValue(addrs.LocalValue, tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics)
func (*Data) GetModule ¶
func (c *Data) GetModule(addrs.ModuleCall, tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics)
func (*Data) GetPathAttr ¶
func (c *Data) GetPathAttr(attr addrs.PathAttr, diags tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics)
func (*Data) GetResource ¶
func (c *Data) GetResource(addrs.Resource, tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics)
func (*Data) GetTerraformAttr ¶
func (c *Data) GetTerraformAttr(addrs.TerraformAttr, tfdiags.SourceRange) (cty.Value, tfdiags.Diagnostics)
func (*Data) StaticValidateReferences ¶
func (c *Data) StaticValidateReferences(refs []*addrs.Reference, self addrs.Referenceable) tfdiags.Diagnostics
type Evaluation ¶
type Evaluation struct { Analysis *Analysis Modules map[string]ValTree // contains filtered or unexported fields }
func EvaluateAnalysis ¶
func EvaluateAnalysis(analysis *Analysis) (*Evaluation, error)
func (*Evaluation) Errors ¶
func (e *Evaluation) Errors() []error
Errors returns the non-fatal errors encountered during evaluation
func (*Evaluation) Location ¶
func (v *Evaluation) Location( resourceId string, path []interface{}, ) []hcl.Range
func (*Evaluation) Resources ¶
func (v *Evaluation) Resources() []models.ResourceState
type FullName ¶
type FullName struct { Module ModuleName Local LocalName }
func ArrayToFullName ¶
func EmptyFullName ¶
func EmptyFullName(module ModuleName) FullName
func ProviderConfigName ¶
func ProviderConfigName(module ModuleName, providerName string) FullName
func StringToFullName ¶
func (FullName) AddLocalName ¶
func (FullName) AsModuleInput ¶
Parses "module.child.var.foo" into "input.child.foo"
func (FullName) AsModuleOutput ¶
Parses the use of an output (e.g. "module.child.x") to the fully expanded output name (e.g. module.child.output.x")
func (FullName) AsResourceName ¶
Parses "aws_s3_bucket.my_bucket[3].bucket_prefix" into: - The resource name "aws_s3_bucket.my_bucket". - The count index "3", or -1 if not present. - The remainder, "bucket_prefix".
func (FullName) AsVariable ¶
Parses "var.my_var.key" into "variable.my_var", "var.my_var" and "key".
type LocalName ¶
type LocalName = []Fragment
func ExprAttributes ¶
func ExprAttributes(expr hcl.Expression) []LocalName
ExprAttributes tries to gather all attributes that are being used in a given expression. For example, for:
aws_s3_bucket.bucket[count.index].acl
It would return [acl].
func TraversalToLocalName ¶
TODO: Refactor to TraversalToName?
type ModuleMeta ¶
type ModuleName ¶
type ModuleName = []string
type ModuleTree ¶
type ModuleTree struct {
// contains filtered or unexported fields
}
We load the entire tree of submodules in one pass.
func ParseDirectory ¶
func ParseDirectory( moduleRegister *TerraformModuleRegister, parserFs afero.Fs, dir string, varFiles []string, ) (*ModuleTree, error)
func ParseFiles ¶
func ParseFiles( moduleRegister *TerraformModuleRegister, parserFs afero.Fs, recurse bool, dir string, filepaths []string, varfiles []string, ) (*ModuleTree, error)
func (*ModuleTree) Errors ¶
func (mtree *ModuleTree) Errors() []error
func (*ModuleTree) FilePath ¶
func (mtree *ModuleTree) FilePath() string
func (*ModuleTree) LoadedFiles ¶
func (mtree *ModuleTree) LoadedFiles() []string
func (*ModuleTree) Walk ¶
func (mtree *ModuleTree) Walk(v Visitor)
type ResourceMeta ¶
type TerraformModuleRegister ¶
type TerraformModuleRegister struct {
// contains filtered or unexported fields
}
func NewTerraformRegister ¶
func NewTerraformRegister(fsys afero.Fs, dir string) *TerraformModuleRegister
func (*TerraformModuleRegister) GetDir ¶
func (r *TerraformModuleRegister) GetDir(source string) *string
type UnsupportedOperationDiag ¶
type UnsupportedOperationDiag struct { }
func (UnsupportedOperationDiag) Description ¶
func (d UnsupportedOperationDiag) Description() tfdiags.Description
func (UnsupportedOperationDiag) FromExpr ¶
func (d UnsupportedOperationDiag) FromExpr() *tfdiags.FromExpr
func (UnsupportedOperationDiag) Severity ¶
func (d UnsupportedOperationDiag) Severity() tfdiags.Severity
func (UnsupportedOperationDiag) Source ¶
func (d UnsupportedOperationDiag) Source() tfdiags.Source
type ValTree ¶
type ValTree = interface{}
A ValTree is a mutable, dynamic tree. Values will be either of these three things:
- a map with int keys (which represents a sparse array)
- a map with string keys
- a cty.Value (at the leafs only)
func BuildValTree ¶
Build a val tree consisting of a subtree nested under a given name.
func EmptyObjectValTree ¶
func EmptyObjectValTree() ValTree
func LookupValTree ¶
Look up a given subtree, returns nil if not found
func MergeValTree ¶
Merge all values from the right valtree into the left.
func SingletonValTree ¶
Create a nested ValTree consisting of a single value
func SparseValTree ¶
Create a sparse tree, only containing the value with the given name. Returns nil if this does not exist.
type Visitor ¶
type Visitor interface { VisitModule(name ModuleName, meta *ModuleMeta) EnterResource(name FullName, resource *ResourceMeta) LeaveResource() VisitBlock(name FullName) VisitExpr(name FullName, expr hcl.Expression) }