Documentation
¶
Index ¶
- Variables
- func ConstraintsAllowVersionOrAbove(constraints version.Constraints, requiredVersion *version.Version) bool
- func ExpFunctions(baseDir string, logger zerolog.Logger) map[string]function.Function
- func IsAutoVarFile(file string) bool
- func ParseVariable(val interface{}) (cty.Value, error)
- func SetUUIDAttributes(b *Block)
- type Attribute
- func (attr *Attribute) AllReferences() []*Reference
- func (attr *Attribute) AsInt() int64
- func (attr *Attribute) AsString() string
- func (attr *Attribute) DecodeProviders() map[string]string
- func (attr *Attribute) Equals(val interface{}) bool
- func (attr *Attribute) HasChanged() (change bool)
- func (attr *Attribute) IsIterable() bool
- func (attr *Attribute) Name() string
- func (attr *Attribute) ProvidersValue() cty.Value
- func (attr *Attribute) Reference() (*Reference, error)
- func (attr *Attribute) ReferencesCausingUnknownKeys() []string
- func (attr *Attribute) Value() cty.Value
- func (attr *Attribute) VerticesReferenced(b *Block) []VertexReference
- type AttributeWithUnknownKeys
- type Block
- func (b *Block) AttributesAsMap() map[string]*Attribute
- func (b *Block) AttributesWithUnknownKeys() []AttributeWithUnknownKeys
- func (b *Block) CallDetails() []ModuleMetadata
- func (b *Block) Children() Blocks
- func (b *Block) Context() *Context
- func (b *Block) FullName() string
- func (b *Block) GetAttribute(name string) *Attribute
- func (b *Block) GetAttributes() []*Attribute
- func (b *Block) GetChildBlock(name string) *Block
- func (b *Block) GetChildBlocks(name string) []*Block
- func (b *Block) HasChild(childElement string) bool
- func (b *Block) HasDynamicBlock() bool
- func (b *Block) HasModuleBlock() bool
- func (b *Block) Index() *int64
- func (b *Block) IsCountExpanded() bool
- func (b *Block) IsForEachReferencedExpanded(moduleBlocks Blocks) bool
- func (b *Block) Key() *string
- func (b *Block) Label() string
- func (b *Block) Labels() []string
- func (b *Block) LocalName() string
- func (b *Block) ModuleAddress() string
- func (b *Block) ModuleName() string
- func (b *Block) ModuleSource() string
- func (b *Block) NameLabel() string
- func (b *Block) Provider() string
- func (b *Block) ProviderConfigKey() string
- func (b *Block) Reference() *Reference
- func (b *Block) SetContext(ctx *Context)
- func (b *Block) SetLabels(labels []string)
- func (b *Block) SetType(t string)
- func (b *Block) ShouldExpand() bool
- func (b *Block) Type() string
- func (b *Block) TypeLabel() string
- func (b *Block) Values() cty.Value
- func (b *Block) VerticesReferenced() []VertexReference
- type BlockBuilder
- type BlockMatcher
- type BlockValueFunc
- type Blocks
- func (blocks Blocks) FindLocalName(name string) *Block
- func (blocks Blocks) Matching(pattern BlockMatcher) *Block
- func (blocks Blocks) ModuleBlocks() Blocks
- func (blocks Blocks) OfType(t string) Blocks
- func (blocks Blocks) Outputs(suppressNil bool) cty.Value
- func (blocks Blocks) SortedByCaller() Blocks
- type Context
- func (c *Context) Get(parts ...string) (val cty.Value)
- func (c *Context) Inner() *hcl.EvalContext
- func (c *Context) NewChild() *Context
- func (c *Context) Parent() *Context
- func (c *Context) Root() *Context
- func (c *Context) Set(val cty.Value, parts ...string)
- func (c *Context) SetByDot(val cty.Value, path string)
- type DetectedProject
- type EnvFileMatcher
- type Evaluator
- type Graph
- type GraphVisitor
- type LiteralBoolValueExpression
- type LiteralValueCollectionExpression
- type LiteralValueIndexExpression
- type Module
- type ModuleCall
- type ModuleConfig
- type ModuleConfigs
- type ModuleMetadata
- type Option
- func OptionGraphEvaluator() Option
- func OptionWithBlockBuilder(blockBuilder BlockBuilder) Option
- func OptionWithInputVars(vars map[string]interface{}) Option
- func OptionWithModuleSuffix(rootPath, suffix string) Option
- func OptionWithPlanFlagVars(vs []string) Option
- func OptionWithProjectName(name string) Option
- func OptionWithRawCtyInput(input cty.Value) (op Option)
- func OptionWithSpaceliftRemoteVarLoader(ctx *config.ProjectContext) Option
- func OptionWithTFCRemoteVarLoader(host, token, localWorkspace string, ...) Option
- func OptionWithTFEnvVars(projectEnv map[string]string) Option
- func OptionWithTFVarsPaths(paths []string, autoDetected bool) Option
- func OptionWithTerraformWorkspace(name string) Option
- type Parser
- func (p *Parser) DependencyPaths() []string
- func (p *Parser) EnvName() string
- func (p *Parser) ParseDirectory() (m *Module, err error)
- func (p *Parser) Path() string
- func (p *Parser) ProjectName() string
- func (p *Parser) RelativePath() string
- func (p *Parser) VarFiles() []string
- func (p *Parser) YAML() string
- type PathOverrideConfig
- type ProjectLocator
- type ProjectLocatorConfig
- type ProviderConstraints
- type Reference
- type RemoteVarLoaderOptions
- type RemoteVariableLoader
- type RootPath
- type RootPathVarFile
- type RootPathVarFiles
- type SetAttributesFunc
- type SpaceliftRemoteVariableLoader
- type TFCRemoteConfig
- type TFCRemoteVariablesLoader
- type TFCRemoteVariablesLoaderOption
- type TreeNode
- func (t *TreeNode) AddPath(path RootPath)
- func (t *TreeNode) AddTerraformVarFiles(basePath, dir string, files []RootPathVarFile)
- func (t *TreeNode) AssociateAuntVarFiles()
- func (t *TreeNode) AssociateChildVarFiles()
- func (t *TreeNode) AssociateParentVarFiles()
- func (t *TreeNode) AssociateSiblingVarFiles()
- func (t *TreeNode) ChildNodes() []*TreeNode
- func (t *TreeNode) ChildNodesExcluding(root *TreeNode) []*TreeNode
- func (t *TreeNode) ChildTerraformVarFiles() []*TreeNode
- func (t *TreeNode) CollectRootPaths(e *EnvFileMatcher) []RootPath
- func (t *TreeNode) FindTfvarsCommonParent() *TreeNode
- func (t *TreeNode) ParentNode() *TreeNode
- func (t *TreeNode) Parents() []*TreeNode
- func (t *TreeNode) PostOrder(visit func(t *TreeNode))
- func (t *TreeNode) UnusedParentVarFiles() []*VarFiles
- func (t *TreeNode) Visit(f func(t *TreeNode))
- type Type
- type VarFileGrouping
- type VarFiles
- type Vertex
- type VertexData
- type VertexLocal
- type VertexModuleCall
- type VertexModuleExit
- type VertexOutput
- type VertexProvider
- type VertexReference
- type VertexResource
- type VertexRoot
- type VertexVariable
Constants ¶
This section is empty.
Variables ¶
var ( // AWSVersionConstraintVolumeTags is the version constraint for the Terraform aws // provider that supports propagating default tags to volume tags. See // https://github.com/hashicorp/terraform-provider-aws/issues/19890 for more // information. AWSVersionConstraintVolumeTags = version.Must(version.NewVersion("5.39.0")) )
var TypeData = Type{ // contains filtered or unexported fields }
var TypeLocal = Type{ // contains filtered or unexported fields }
var TypeModule = Type{ // contains filtered or unexported fields }
var TypeOutput = Type{ // contains filtered or unexported fields }
var TypeProvider = Type{ // contains filtered or unexported fields }
var TypeResource = Type{ // contains filtered or unexported fields }
var TypeTerraform = Type{ // contains filtered or unexported fields }
var TypeVariable = Type{ // contains filtered or unexported fields }
var ValidTypes = []Type{ TypeData, TypeLocal, TypeModule, TypeOutput, TypeProvider, TypeResource, TypeTerraform, TypeVariable, }
Functions ¶
func ConstraintsAllowVersionOrAbove ¶
func ConstraintsAllowVersionOrAbove(constraints version.Constraints, requiredVersion *version.Version) bool
ConstraintsAllowVersionOrAbove checks if the given constraints enforce at least the given minVersion.
func ExpFunctions ¶
ExpFunctions returns the set of functions that should be used to when evaluating expressions in the receiving scope.
func IsAutoVarFile ¶
IsAutoVarFile checks if the var file is an auto.tfvars or terraform.tfvars. These are special Terraform var files that are applied to every project automatically.
func ParseVariable ¶
func SetUUIDAttributes ¶
func SetUUIDAttributes(b *Block)
SetUUIDAttributes adds commonly used identifiers to the block so that it can be referenced by other blocks in context evaluation. The identifiers are only set if they don't already exist as attributes on the block.
Types ¶
type Attribute ¶
type Attribute struct { // HCLAttr is the underlying hcl.Attribute that the Attribute references. HCLAttr *hcl.Attribute // Ctx is the context that the Attribute should be evaluated against. This propagates // any references from variables into the attribute. Ctx *Context // Verbose defines if the attribute should log verbose diagnostics messages to debug. Verbose bool Logger zerolog.Logger // contains filtered or unexported fields }
Attribute provides a wrapper struct around hcl.Attribute it provides helper methods and functionality for common interactions with hcl.Attribute.
Attributes are key/value pairs that are part of a Block. For example take the following Block:
resource "aws_instance" "t3_standard" { ami = "fake_ami" instance_type = "t3.medium" credit_specification { cpu_credits = "standard" } }
"ami" & "instance_type" are the Attributes of this Block, "credit_specification" is a child Block see Block.Children for more info.
func (*Attribute) AllReferences ¶
AllReferences returns a list of References for the given Attribute. This can include the main Value Reference (see Reference method) and also a list of references used in conditional evaluation and templating.
func (*Attribute) AsInt ¶
AsInt returns the Attribute value as a int64. If the cty.Value is not a type that can be converted to integer, this method returns 0.
func (*Attribute) AsString ¶
AsString returns the Attribute value as a string. If the cty.Value is not a type that can be converted to string, this method returns an empty string.
func (*Attribute) DecodeProviders ¶
DecodeProviders decodes the providers block into a map of provider names to provider aliases. This is used by the graph evaluator to make sure the correct edges are created when providers are inherited from parent modules.
func (*Attribute) HasChanged ¶
HasChanged returns if the Attribute Value has changed since Value was last called.
func (*Attribute) IsIterable ¶
IsIterable returns if the attribute can be ranged over.
func (*Attribute) ProvidersValue ¶
ProvidersValue retrieves the value of the attribute with special handling need for module.providers blocks: Keys in the providers block are converted to literal values, then the attr.Value() is returned.
func (*Attribute) Reference ¶
Reference returns the pointer to a Reference struct that holds information about the Attributes referenced block. Reference achieves this by traversing the Attribute Expression in order to find the parent block. E.g. with the following HCL
resource "aws_launch_template" "foo2" { name = "foo2" } resource "some_resource" "example_with_launch_template_3" { ... name = aws_launch_template.foo2.name }
The Attribute some_resource.name would have a reference of
Reference { blockType: Type{ name: "resource", removeTypeInReference: true, } typeLabel: "aws_launch_template" nameLabel: "foo2" }
Reference is used to build up a Terraform JSON configuration file that holds information about the expressions and their parents. Diginfra uses these references in resource evaluation to lookup connecting resource information.
func (*Attribute) ReferencesCausingUnknownKeys ¶
ReferencesCausingUnknownKeys returns a list of missing references if the attribute is an object without fully known keys. For example, this will return []string{"var.default_tags"} if a value is set to the result of `merge({"x": "y"}, var.default_tags)` where the value of `var.default_tags` is not known at evaluation time.
func (*Attribute) Value ¶
Value returns the Attribute with the underlying hcl.Expression of the hcl.Attribute evaluated with the Attribute Context. This returns a cty.Value with the values filled from any variables or references that the Context carries.
func (*Attribute) VerticesReferenced ¶
func (attr *Attribute) VerticesReferenced(b *Block) []VertexReference
VerticesReferenced traverses all the Expressions used by the attribute to build a list of all the Blocks referenced by the Attribute.
type Block ¶
type Block struct { // HCLBlock is the underlying hcl.Block that has been parsed from a hcl.File HCLBlock *hcl.Block // UniqueAttrs specifies diginfra specific unique attributes that will be appended to the block values. UniqueAttrs map[string]*hcl.Attribute Filename string StartLine int EndLine int // contains filtered or unexported fields }
Block wraps a hcl.Block type with additional methods and context. A Block is a core piece of HCL schema and represents a set of data. Most importantly a Block directly corresponds to a schema.Resource.
Blocks can represent a number of different types - see terraformSchemaV012 for a list of potential HCL blocks available.
e.g. a type resource block could look like this in HCL:
resource "aws_lb" "lb1" { load_balancer_type = "application" }
A Block can also have a set number of child Blocks, these child Blocks in turn can also have children. Blocks are recursive. The following example is represents a resource Block with child Blocks:
resource "aws_instance" "t3_standard_cpuCredits" { ami = "fake_ami" instance_type = "t3.medium" # child Block starts here credit_specification { cpu_credits = "standard" } }
See Attribute for more info about how the values of Blocks are evaluated with their Context and returned.
func (*Block) AttributesAsMap ¶
AttributesAsMap returns the Attributes of this block as a map with the attribute name as the key and the value as the Attribute.
func (*Block) AttributesWithUnknownKeys ¶
func (b *Block) AttributesWithUnknownKeys() []AttributeWithUnknownKeys
func (*Block) CallDetails ¶
func (b *Block) CallDetails() []ModuleMetadata
CallDetails returns the tree of module calls that were used to create this resource. Each step of the tree contains a full file path and block name that were used to create the resource.
CallDetails returns a list of ModuleMetadata that are ordered by appearance in the Terraform config tree.
func (*Block) FullName ¶
FullName returns the fully qualified Reference name as it relates to the Blocks position in the entire Terraform config tree. This includes module name. e.g.
The following resource residing in a module named "web_app":
resource "aws_instance" "t3_standard" { ami = "fake_ami" instance_type = var.instance_type }
Would have its FullName as module.web_app.aws_instance.t3_standard FullName is what Terraform uses in its JSON output file.
func (*Block) GetAttribute ¶
GetAttribute returns the given attribute with the provided name. It will return nil if the attribute is not found. If we take the following Block example:
resource "aws_instance" "t3_standard_cpuCredits" { ami = "fake_ami" instance_type = "t3.medium" credit_specification { cpu_credits = "standard" } }
ami & instance_type are both valid Attribute names that can be used to lookup Block Attributes.
func (*Block) GetAttributes ¶
GetAttributes returns a list of Attribute for this Block. Attributes are key value specification on a given Block. For example take the following hcl:
resource "aws_instance" "t3_standard_cpuCredits" { ami = "fake_ami" instance_type = "t3.medium" credit_specification { cpu_credits = "standard" } }
ami & instance_type are the Attributes of this Block and credit_specification is a child Block.
func (*Block) GetChildBlock ¶
GetChildBlock is a helper method around GetChildBlocks. It returns the first non nil child block matching name.
func (*Block) GetChildBlocks ¶
GetChildBlocks returns all the child Block that match the name provided. e.g: If the current Block looks like such:
resource "aws_instance" "t3_standard_cpuCredits" { ami = "fake_ami" instance_type = "t3.medium" credit_specification { cpu_credits = "standard" } ebs_block_device { device_name = "xvdj" } }
Then "credit_specification" & "ebs_block_device" would be valid names that could be used to retrieve child Blocks.
func (*Block) HasDynamicBlock ¶
HasDynamicBlock searches all the nested children of the given block to see if any are type "dynamic". This is used before embarking on dynamic expansion logic.
func (*Block) HasModuleBlock ¶
HasModuleBlock returns is the Block as a module associated with it. If it doesn't this means that this Block is part of the root Module.
func (*Block) Index ¶
Index returns the count index of the block using the name label. Index returns nil if the block has no count.
func (*Block) IsCountExpanded ¶
IsCountExpanded returns if the Block has been expanded as part of a for_each or count evaluation.
func (*Block) IsForEachReferencedExpanded ¶
IsForEachReferencedExpanded checks if the block referenced under the for_each has already been expanded. This is used to check is we can safely expand this block, expanding block prematurely can lead to output inconsistencies. It is advised to always check if that the block has any references that are yet to be expanded before expanding itself.
func (*Block) Key ¶
Key returns the foreach key of the block using the name label. Key returns nil if the block has no each key.
func (*Block) ModuleAddress ¶
ModuleAddress returns the address of the module associated with this Block or "" if it is part of the root Module
func (*Block) ModuleName ¶
ModuleName returns the name of the module associated with this Block or "" if it is part of the root Module
func (*Block) ModuleSource ¶
ModuleSource returns the "source" attribute from the associated Module or "" if it is part of the root Module
func (*Block) Provider ¶
Provider returns the provider by first checking if it is explicitly set as an attribute, if it is not the first word in the snake_case name of the type is returned. E.g. the type 'aws_instance' would return provider 'aws'
func (*Block) ProviderConfigKey ¶
ProviderConfigKey looks up the key used to reference the provider in the "configuration.providers" section of the terraform plan json. This should be used to set the "provider_config_key " of the resource in the "configuration.resources" section of plan json.
func (*Block) Reference ¶
Reference returns a Reference to the given Block this can be used to when printing out full names of Blocks to stdout or a file.
func (*Block) SetContext ¶
SetContext sets the Block.context to the provided ctx. This ctx is also set on the child Blocks as a child Context. Meaning that it can be used in traversal evaluation when looking up Context variables.
func (*Block) ShouldExpand ¶
func (*Block) Values ¶
Values returns the Block as a cty.Value with all the Attributes evaluated with the Block Context. This means that any variables or references will be replaced by their actual value. For example:
variable "instance_type" { default = "t3.medium" } resource "aws_instance" "t3_standard_cpucredits" { ami = "fake_ami" instance_type = var.instance_type }
Would evaluate to a cty.Value of type Object with the instance_type Attribute holding the value "t3.medium".
func (*Block) VerticesReferenced ¶
func (b *Block) VerticesReferenced() []VertexReference
VerticesReferenced traverses the block attributes and child blocks to build a complete list of all the vertices referenced by the Block. We build a special VertexReference if the block uses a provider but doesn't have one referenced. This is because blocks will depend on the default provider to get the correct region data, even if not explicitly referenced as a reference.
type BlockBuilder ¶
type BlockBuilder struct { MockFunc func(a *Attribute) cty.Value SetAttributes []SetAttributesFunc Logger zerolog.Logger HCLParser *modules.SharedHCLParser // contains filtered or unexported fields }
BlockBuilder handles generating new Blocks as part of the parsing and evaluation process.
func (BlockBuilder) BuildModuleBlocks ¶
func (b BlockBuilder) BuildModuleBlocks(block *Block, modulePath string, rootPath string) (Blocks, error)
BuildModuleBlocks loads all the Blocks for the module at the given path
func (BlockBuilder) CloneBlock ¶
func (b BlockBuilder) CloneBlock(block *Block, index cty.Value) *Block
CloneBlock creates a duplicate of the block and sets the returned Block's Context to include the index provided. This is primarily used when Blocks are expanded as part of a count evaluation.
type BlockMatcher ¶
BlockMatcher defines a struct that can be used to filter a list of blocks to a single Block.
type BlockValueFunc ¶
BlockValueFunc defines a type that returns a set of fake/mocked values for a given block type.
type Blocks ¶
type Blocks []*Block
Blocks is a helper type around a slice of blocks to provide easy access finding blocks of type.
func (Blocks) FindLocalName ¶
func (Blocks) Matching ¶
func (blocks Blocks) Matching(pattern BlockMatcher) *Block
Matching returns a single block filtered from the given pattern. If more than one Block is filtered by the pattern, Matching returns the first Block found.
func (Blocks) ModuleBlocks ¶
ModuleBlocks is a wrapper around SortedByCaller that selects just Modules to be sorted.
func (Blocks) OfType ¶
OfType returns Blocks of the given type t. See terraformSchemaV012 for a list of possible types to lookup.
func (Blocks) SortedByCaller ¶
SortedByCaller returns all the Blocks of type module. The returned Blocks are sorted in order of reference. Blocks that are referenced by others are the first in this list.
So if we start with a list of [A,B,C] and A references B the returned list will be [B,A,C].
This makes the list returned safe for context evaluation, as we evaluate modules that have outputs that other modules rely on first.
type DetectedProject ¶
type EnvFileMatcher ¶
type EnvFileMatcher struct {
// contains filtered or unexported fields
}
EnvFileMatcher is used to match environment specific var files.
func CreateEnvFileMatcher ¶
func CreateEnvFileMatcher(names []string, extensions []string) *EnvFileMatcher
func (*EnvFileMatcher) EnvName ¶
func (e *EnvFileMatcher) EnvName(file string) string
EnvName returns the environment name for the given var file.
func (*EnvFileMatcher) IsEnvName ¶
func (e *EnvFileMatcher) IsEnvName(file string) bool
IsEnvName checks if the var file is an environment specific var file.
func (*EnvFileMatcher) IsGlobalVarFile ¶
func (e *EnvFileMatcher) IsGlobalVarFile(file string) bool
IsGlobalVarFile checks if the var file is a global var file.
func (*EnvFileMatcher) PathEnv ¶
func (e *EnvFileMatcher) PathEnv(file string) string
PathEnv returns the env name detected in file path when it matches defined envs. Otherwise returns an empty string.
type Evaluator ¶
type Evaluator struct {
// contains filtered or unexported fields
}
Evaluator provides a set of given Blocks with contextual information. Evaluator is an important step in retrieving Block values that can be used in the schema.Resource cost retrieval. Without Evaluator the Blocks provided only have shallow information within attributes and won't contain any evaluated variables or references.
func NewEvaluator ¶
func NewEvaluator( module Module, workingDir string, inputVars map[string]cty.Value, moduleMetadata *modules.Manifest, visitedModules map[string]map[string]cty.Value, workspace string, blockBuilder BlockBuilder, logger zerolog.Logger, isGraph bool, ) *Evaluator
NewEvaluator returns an Evaluator with Context initialised with top level variables. This Context is then passed to all Blocks as child Context so that variables built in Evaluation are propagated to the Block Attributes.
func (*Evaluator) AddFilteredBlocks ¶
func (*Evaluator) MissingVars ¶
MissingVars returns a list of names of the variable blocks with missing input values.
func (*Evaluator) Run ¶
Run builds the Evaluator Context using all the provided Blocks. It will build up the Context to hold variable and reference information so that this can be used by Attribute evaluation. Run will also parse and build up and child modules that are referenced in the Blocks and runs child Evaluator on this Module.
type Graph ¶
type Graph struct {
// contains filtered or unexported fields
}
func NewGraphWithRoot ¶
func (*Graph) ReduceTransitively ¶
func (g *Graph) ReduceTransitively()
type GraphVisitor ¶
type GraphVisitor struct {
// contains filtered or unexported fields
}
func NewGraphVisitor ¶
func NewGraphVisitor(logger zerolog.Logger, vertexMutex *sync.Mutex) *GraphVisitor
func (*GraphVisitor) Visit ¶
func (v *GraphVisitor) Visit(id string, vertex interface{})
type LiteralBoolValueExpression ¶
type LiteralBoolValueExpression struct { // we embed the hclsyntax.LiteralValueExpr as the hcl.Expression interface // has an unexported method that we need to implement. *hclsyntax.LiteralValueExpr Expression hcl.Expression }
LiteralBoolValueExpression is a wrapper around any hcl.Expression that returns a literal bool value. This is use to evaluate mocked expressions that are used in conditional expressions. It turns any non bool literal value into a bool false value.
func (*LiteralBoolValueExpression) Value ¶
func (e *LiteralBoolValueExpression) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics)
Value returns the value of the expression. If the expression is not a literal bool value, this returns false.
type LiteralValueCollectionExpression ¶
type LiteralValueCollectionExpression struct { // we embed the hclsyntax.LiteralValueExpr as the hcl.Expression interface // has an unexported method that we need to implement. *hclsyntax.LiteralValueExpr Expression hcl.Expression MockedValue cty.Value }
func (*LiteralValueCollectionExpression) Value ¶
func (e *LiteralValueCollectionExpression) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics)
type LiteralValueIndexExpression ¶
type LiteralValueIndexExpression struct { // we embed the hclsyntax.LiteralValueExpr as the hcl.Expression interface // has an unexported method that we need to implement. *hclsyntax.LiteralValueExpr Expression *hclsyntax.IndexExpr MockedValue cty.Value }
func (*LiteralValueIndexExpression) Value ¶
func (e *LiteralValueIndexExpression) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics)
type Module ¶
type Module struct { Name string Source string Blocks Blocks // RawBlocks are the Blocks that were built when the module was loaded from the filesystem. // These are safe to pass to the child module calls as they are yet to be expanded. RawBlocks Blocks RootPath string ModulePath string Modules []*Module Parent *Module Warnings []*schema.ProjectDiag HasChanges bool TerraformVarsPaths []string // ModuleSuffix is a unique name that can be optionally appended to the Module's // project name. This is only applicable to root modules. ModuleSuffix string // SourceURL is the discovered remote url for the module. This will only be // filled if the module is a remote module. SourceURL string // ProviderReferences is a map of provider names (relative to the module) to // the provider block that defines that provider. We keep track of this so we // can re-evaluate the provider blocks when we need to. ProviderReferences map[string]*Block TerraformVersion string ProviderConstraints *ProviderConstraints }
Module encapsulates all the Blocks that are part of a Module in a Terraform project.
type ModuleCall ¶
type ModuleCall struct { // Name the name of the module as specified a the point of definition. Name string // Path is the path to the local directory containing the HCL for the Module. Path string // Definition is the actual Block where the ModuleCall happens in a hcl.File Definition *Block // Module contains the parsed root module that represents this ModuleCall. Module *Module }
ModuleCall represents a call to a defined Module by a parent Module.
type ModuleConfig ¶
type ModuleConfig struct {
// contains filtered or unexported fields
}
type ModuleConfigs ¶
type ModuleConfigs struct {
// contains filtered or unexported fields
}
func NewModuleConfigs ¶
func NewModuleConfigs() *ModuleConfigs
func (*ModuleConfigs) Add ¶
func (m *ModuleConfigs) Add(moduleAddress string, moduleConfig ModuleConfig)
func (*ModuleConfigs) Get ¶
func (m *ModuleConfigs) Get(moduleAddress string) []ModuleConfig
type ModuleMetadata ¶
type Option ¶
type Option func(p *Parser)
func OptionGraphEvaluator ¶
func OptionGraphEvaluator() Option
OptionGraphEvaluator sets the Parser to use the experimental graph evaluator.
func OptionWithBlockBuilder ¶
func OptionWithBlockBuilder(blockBuilder BlockBuilder) Option
func OptionWithInputVars ¶
OptionWithInputVars takes cmd line var input values and converts them to cty.Value It sets these as the Parser starting inputVars which are used at the root module evaluation.
func OptionWithModuleSuffix ¶
OptionWithModuleSuffix sets an optional module suffix which will be added to the Module after it has finished parsing this can be used to augment auto-detected project path names and metadata. If the suffix is already part of the project name - ignore it.
func OptionWithPlanFlagVars ¶
OptionWithPlanFlagVars takes TF var inputs specified in a command line string and converts them to cty.Value It sets these as the Parser starting inputVars which are used at the root module evaluation.
func OptionWithProjectName ¶
OptionWithProjectName sets the project name for the parser. This is used if the project name has been explicitly set by the user or the autodetection
func OptionWithRawCtyInput ¶
OptionWithRawCtyInput sets the input variables for the parser using a cty.Value. OptionWithRawCtyInput expects that this input is a ObjectValue that can be transformed to a map.
func OptionWithSpaceliftRemoteVarLoader ¶
func OptionWithSpaceliftRemoteVarLoader(ctx *config.ProjectContext) Option
OptionWithSpaceliftRemoteVarLoader attempts to build a SpaceLift remote variable loader and set this on the parser. If the required environment variables are not set, the loader is skipped.
func OptionWithTFCRemoteVarLoader ¶
func OptionWithTFCRemoteVarLoader(host, token, localWorkspace string, loaderOpts ...TFCRemoteVariablesLoaderOption) Option
OptionWithTFCRemoteVarLoader accepts Terraform Cloud/Enterprise host and token values to load remote execution variables.
func OptionWithTFEnvVars ¶
OptionWithTFEnvVars takes any TF_ENV_xxx=yyy from the environment and converts them to cty.Value It then sets these as the Parser starting tfEnvVars which are used at the root module evaluation.
func OptionWithTFVarsPaths ¶
OptionWithTFVarsPaths takes a slice of paths adds them to the parser tfvar files relative to the Parser detectedProjectPath. It sorts tfvar paths for precedence before adding them to the parser. Paths that don't exist will be ignored.
func OptionWithTerraformWorkspace ¶
OptionWithTerraformWorkspace informs the Parser to use the provided name as the workspace for context evaluation. The Parser exposes this workspace in the evaluation context under the variable named `terraform.workspace`. This is commonly used by users to specify different capacity/configuration in their Terraform, e.g:
terraform.workspace == "prod" ? "m5.8xlarge" : "m5.4xlarge"
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser is a tool for parsing terraform templates at a given file system location.
func NewParser ¶
func NewParser(projectRoot RootPath, envMatcher *EnvFileMatcher, moduleLoader *modules.ModuleLoader, logger zerolog.Logger, options ...Option) *Parser
NewParser creates a new parser for the given RootPath.
func (*Parser) DependencyPaths ¶
DependencyPaths returns the list of module calls that the project depends on. These are usually local module calls that have been detected in the project.
func (*Parser) EnvName ¶
EnvName returns the module suffix of the parser (normally the environment name).
func (*Parser) ParseDirectory ¶
ParseDirectory parses all the terraform files in the detectedProjectPath into Blocks and then passes them to an Evaluator to fill these Blocks with additional Context information. Parser does not parse any blocks outside the root Module. It instead leaves ModuleLoader to fetch these Modules on demand. See ModuleLoader.Load for more information.
ParseDirectory returns the root Module that represents the top of the Terraform Config tree.
func (*Parser) ProjectName ¶
ProjectName generates a name for the project that can be used in the Diginfra config file.
func (*Parser) RelativePath ¶
RelativePath returns the path of the parser relative to the repo path
type PathOverrideConfig ¶
type ProjectLocator ¶
type ProjectLocator struct {
// contains filtered or unexported fields
}
ProjectLocator finds Terraform projects for given paths. It naively excludes folders that are imported as modules in other projects.
func NewProjectLocator ¶
func NewProjectLocator(logger zerolog.Logger, config *ProjectLocatorConfig) *ProjectLocator
NewProjectLocator returns safely initialized ProjectLocator.
func (*ProjectLocator) FindRootModules ¶
func (p *ProjectLocator) FindRootModules(startingPath string) []RootPath
FindRootModules returns a list of all directories that contain a full Terraform project under the given fullPath. This list excludes any Terraform modules that have been found (if they have been called by a Module source).
type ProjectLocatorConfig ¶
type ProjectLocatorConfig struct { ExcludedDirs []string ChangedObjects []string UseAllPaths bool SkipAutoDetection bool IncludedDirs []string EnvNames []string PathOverrides []PathOverrideConfig FallbackToIncludePaths bool MaxSearchDepth int ForceProjectType string TerraformVarFileExtensions []string WorkingDirectory string }
ProjectLocatorConfig provides configuration options on how the locator functions.
type ProviderConstraints ¶
type ProviderConstraints struct { AWS version.Constraints Google version.Constraints }
ProviderConstraints represents the constraints for a providers within a module. This can be used to check if Diginfra functionality is applicable to a given run.
func NewProviderConstraints ¶
func NewProviderConstraints(blocks Blocks) *ProviderConstraints
NewProviderConstraints parses the provider blocks for any Terraform configuration blocks if found it will attempt to return a ProviderConstraints struct from the required_providers configuration. Currently, we only support AWS provider constraints.
func (*ProviderConstraints) MarshalJSON ¶
func (p *ProviderConstraints) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON representation of the ProviderConstraints. This is used to serialize the constraints for the sub providers.
func (*ProviderConstraints) UnmarshalJSON ¶
func (p *ProviderConstraints) UnmarshalJSON(b []byte) error
UnmarshalJSON parses the JSON representation of the ProviderConstraints and sets the constraints for the sub providers.
type Reference ¶
type Reference struct {
// contains filtered or unexported fields
}
func (*Reference) JSONString ¶
JSONString returns the reference so that it's possible to use in the plan JSON file. This strips any count keys from the reference.
type RemoteVarLoaderOptions ¶
type RemoteVariableLoader ¶
type RemoteVariableLoader interface { // Load fetches remote variables from a remote service. Load(options RemoteVarLoaderOptions) (map[string]cty.Value, error) }
RemoteVariableLoader is an interface for loading remote variables from a remote service.
type RootPath ¶
type RootPath struct { Matcher *EnvFileMatcher // StartingPath is the path to the directory where the search started. StartingPath string // DetectedPath is the path to the root of the project. DetectedPath string // HasChanges contains information about whether the project has git changes associated with it. // This will show as true if one or more files/directories have changed in the Path, and also if // and local modules that are used by this project have changes. HasChanges bool // TerraformVarFiles are a list of any .tfvars or .tfvars.json files found at the root level. TerraformVarFiles RootPathVarFiles HasChildVarFiles bool IsTerragrunt bool IsParentTerragruntConfig bool ModuleCalls []string }
RootPath holds information about the root directory of a project, this is normally the top level Terraform containing provider blocks.
func (*RootPath) AddVarFiles ¶
func (*RootPath) AutoFiles ¶
func (r *RootPath) AutoFiles() RootPathVarFiles
AutoFiles returns a list of any auto.tfvars or terraform.tfvars files defined in the project.
func (*RootPath) EnvFiles ¶
func (r *RootPath) EnvFiles() RootPathVarFiles
EnvFiles returns a list of any environment specific var files defined in the project.
func (*RootPath) EnvGroupings ¶
func (r *RootPath) EnvGroupings() []VarFileGrouping
EnvGroupings returns a list of var file groupings by environment. This is used to group and dedup var files that would otherwise create new projects.
func (*RootPath) GlobalFiles ¶
func (r *RootPath) GlobalFiles() RootPathVarFiles
GlobalFiles returns a list of any global var files defined in the project.
type RootPathVarFile ¶
type RootPathVarFile struct { Name string // RelPath is the path relative to the root of the project. RelPath string IsGlobal bool EnvName string FullPath string }
func (RootPathVarFile) IsChildVarFile ¶
func (r RootPathVarFile) IsChildVarFile() bool
type RootPathVarFiles ¶
type RootPathVarFiles []RootPathVarFile
func (RootPathVarFiles) ToPaths ¶
func (r RootPathVarFiles) ToPaths() []string
type SetAttributesFunc ¶
type SetAttributesFunc func(b *Block)
SetAttributesFunc defines a function that sets required attributes on a hcl.Block. This is done so that identifiers that are normally propagated from a Terraform state/apply are set on the Block. This means they can be used properly in references and outputs.
type SpaceliftRemoteVariableLoader ¶
type SpaceliftRemoteVariableLoader struct { Client client.Client Metadata vcs.Metadata // contains filtered or unexported fields }
SpaceliftRemoteVariableLoader orchestrates communicating with the Spacelift API to fetch remote variables.
func NewSpaceliftRemoteVariableLoader ¶
func NewSpaceliftRemoteVariableLoader(metadata vcs.Metadata, apiKeyEndpoint, apiKeyId, apiKeySecret string) (*SpaceliftRemoteVariableLoader, error)
NewSpaceliftRemoteVariableLoader creates a new SpaceliftRemoteVariableLoader, this function expects that the required environment variables are set.
func (*SpaceliftRemoteVariableLoader) Load ¶
func (s *SpaceliftRemoteVariableLoader) Load(options RemoteVarLoaderOptions) (map[string]cty.Value, error)
Load fetches remote variables from Spacelift by querying the stacks for the provided environment name and remote name.
type TFCRemoteConfig ¶
type TFCRemoteVariablesLoader ¶
type TFCRemoteVariablesLoader struct {
// contains filtered or unexported fields
}
TFCRemoteVariablesLoader handles loading remote variables from Terraform Cloud.
func NewTFCRemoteVariablesLoader ¶
func NewTFCRemoteVariablesLoader(client *extclient.AuthedAPIClient, localWorkspace string, logger zerolog.Logger, opts ...TFCRemoteVariablesLoaderOption) *TFCRemoteVariablesLoader
NewTFCRemoteVariablesLoader constructs a new loader for fetching remote variables.
func (*TFCRemoteVariablesLoader) Load ¶
func (r *TFCRemoteVariablesLoader) Load(options RemoteVarLoaderOptions) (map[string]cty.Value, error)
Load fetches remote variables if terraform block contains organization and workspace name.
type TFCRemoteVariablesLoaderOption ¶
type TFCRemoteVariablesLoaderOption func(r *TFCRemoteVariablesLoader)
TFCRemoteVariablesLoaderOption defines a function that can set properties on an TFCRemoteVariablesLoader.
func RemoteVariablesLoaderWithRemoteConfig ¶
func RemoteVariablesLoaderWithRemoteConfig(config TFCRemoteConfig) TFCRemoteVariablesLoaderOption
RemoteVariablesLoaderWithRemoteConfig sets a user defined configuration for the TFCRemoteVariablesLoader. This is normally done to override the configuration detected from the HCL blocks.
type TreeNode ¶
type TreeNode struct { Name string Level int RootPath *RootPath TerraformVarFiles *VarFiles Children []*TreeNode Parent *TreeNode }
TreeNode represents a node in the tree of Terraform projects. A TreeNode can either be a Terraform project, a directory containing Terraform var files, or just a filler node to represent a directory. Callers should check the RootPath and TerraformVarFiles fields to determine what type of node this is.
func CreateTreeNode ¶
func CreateTreeNode(basePath string, paths []RootPath, varFiles map[string][]RootPathVarFile, e *EnvFileMatcher) *TreeNode
CreateTreeNode creates a tree of Terraform projects and directories that contain var files.
func (*TreeNode) AddPath ¶
AddPath adds a path to the tree, this will create any missing nodes in the tree.
func (*TreeNode) AddTerraformVarFiles ¶
func (t *TreeNode) AddTerraformVarFiles(basePath, dir string, files []RootPathVarFile)
AddTerraformVarFiles adds a directory that contains Terraform var files to the tree.
func (*TreeNode) AssociateAuntVarFiles ¶
func (t *TreeNode) AssociateAuntVarFiles()
AssociateAuntVarFiles returns a list of any aunt directories that contain var files that have not been used by a project.
func (*TreeNode) AssociateChildVarFiles ¶
func (t *TreeNode) AssociateChildVarFiles()
AssociateChildVarFiles make sure that any projects have directories which contain var files are associated with the project. These are only associated if they are within 2 levels of the project and not if the child directory is a valid sibling directory.
func (*TreeNode) AssociateParentVarFiles ¶
func (t *TreeNode) AssociateParentVarFiles()
AssociateParentVarFiles returns a list of any parent directories that contain var files that have not been used by a project.
func (*TreeNode) AssociateSiblingVarFiles ¶
func (t *TreeNode) AssociateSiblingVarFiles()
AssociateSiblingVarFiles makes sure that any sibling directories that contain var files are associated with their corresponding projects.
func (*TreeNode) ChildNodes ¶
ChildNodes returns the first set of child nodes that are Terraform projects or directories that contain var files.
func (*TreeNode) ChildNodesExcluding ¶
ChildNodesExcluding collects all the child nodes of the current node, excluding the given root node.
func (*TreeNode) ChildTerraformVarFiles ¶
ChildTerraformVarFiles returns the first set of child nodes that contain just terraform var files.
func (*TreeNode) CollectRootPaths ¶
func (t *TreeNode) CollectRootPaths(e *EnvFileMatcher) []RootPath
CollectRootPaths returns a list of all the Terraform projects found in the tree.
func (*TreeNode) FindTfvarsCommonParent ¶
FindTfvarsCommonParent returns the first parent directory that has a child directory with a root Terraform project.
func (*TreeNode) ParentNode ¶
ParentNode returns the parent node of the current node, this will skip any nodes that are not Terraform projects or directories that contain var files.
func (*TreeNode) PostOrder ¶
PostOrder traverses the tree in post order, calling the given function on each node. This will skip any nodes that are not Terraform projects or directories that contain var files.
func (*TreeNode) UnusedParentVarFiles ¶
UnusedParentVarFiles returns a list of any parent directories that contain var files that have not been used by a project.
type VarFileGrouping ¶
type VarFileGrouping struct { Name string TerraformVarFiles RootPathVarFiles }
VarFileGrouping defines a grouping of var files by environment.
type VarFiles ¶
type VarFiles struct { Path string Files []RootPathVarFile // HasSiblings is true if the directory is within a directory that contains other // root Terraform projects. HasSiblings bool // Used is true if the var files have been used by a project. Used bool }
VarFiles represents a directory that contains Terraform var files. HasSiblings is true if the directory is within a directory that contains other directories that are root Terraform projects.
type VertexData ¶
type VertexData struct {
// contains filtered or unexported fields
}
func (*VertexData) ID ¶
func (v *VertexData) ID() string
func (*VertexData) ModuleAddress ¶
func (v *VertexData) ModuleAddress() string
func (*VertexData) References ¶
func (v *VertexData) References() []VertexReference
type VertexLocal ¶
type VertexLocal struct {
// contains filtered or unexported fields
}
func (*VertexLocal) ID ¶
func (v *VertexLocal) ID() string
func (*VertexLocal) ModuleAddress ¶
func (v *VertexLocal) ModuleAddress() string
func (*VertexLocal) References ¶
func (v *VertexLocal) References() []VertexReference
type VertexModuleCall ¶
type VertexModuleCall struct {
// contains filtered or unexported fields
}
func (*VertexModuleCall) ID ¶
func (v *VertexModuleCall) ID() string
func (*VertexModuleCall) ModuleAddress ¶
func (v *VertexModuleCall) ModuleAddress() string
func (*VertexModuleCall) References ¶
func (v *VertexModuleCall) References() []VertexReference
type VertexModuleExit ¶
type VertexModuleExit struct {
// contains filtered or unexported fields
}
func (*VertexModuleExit) ID ¶
func (v *VertexModuleExit) ID() string
func (*VertexModuleExit) ModuleAddress ¶
func (v *VertexModuleExit) ModuleAddress() string
func (*VertexModuleExit) References ¶
func (v *VertexModuleExit) References() []VertexReference
type VertexOutput ¶
type VertexOutput struct {
// contains filtered or unexported fields
}
func (*VertexOutput) ID ¶
func (v *VertexOutput) ID() string
func (*VertexOutput) ModuleAddress ¶
func (v *VertexOutput) ModuleAddress() string
func (*VertexOutput) References ¶
func (v *VertexOutput) References() []VertexReference
type VertexProvider ¶
type VertexProvider struct {
// contains filtered or unexported fields
}
func (*VertexProvider) ID ¶
func (v *VertexProvider) ID() string
func (*VertexProvider) ModuleAddress ¶
func (v *VertexProvider) ModuleAddress() string
func (*VertexProvider) References ¶
func (v *VertexProvider) References() []VertexReference
type VertexReference ¶
type VertexResource ¶
type VertexResource struct {
// contains filtered or unexported fields
}
func (*VertexResource) ID ¶
func (v *VertexResource) ID() string
func (*VertexResource) ModuleAddress ¶
func (v *VertexResource) ModuleAddress() string
func (*VertexResource) References ¶
func (v *VertexResource) References() []VertexReference
type VertexRoot ¶
type VertexRoot struct{}
func (*VertexRoot) ID ¶
func (v *VertexRoot) ID() string
func (*VertexRoot) ModuleAddress ¶
func (v *VertexRoot) ModuleAddress() string
func (*VertexRoot) References ¶
func (v *VertexRoot) References() []VertexReference
type VertexVariable ¶
type VertexVariable struct {
// contains filtered or unexported fields
}
func (*VertexVariable) ID ¶
func (v *VertexVariable) ID() string
func (*VertexVariable) ModuleAddress ¶
func (v *VertexVariable) ModuleAddress() string
func (*VertexVariable) References ¶
func (v *VertexVariable) References() []VertexReference
Source Files
¶
- attribute.go
- block.go
- constraints.go
- context.go
- evaluator.go
- graph.go
- graph_vertex_data.go
- graph_vertex_local.go
- graph_vertex_module_call.go
- graph_vertex_module_exit.go
- graph_vertex_output.go
- graph_vertex_provider.go
- graph_vertex_resource.go
- graph_vertex_root.go
- graph_vertex_variable.go
- module.go
- parser.go
- project_locator.go
- reference.go
- remote_variables_loader.go
- var.go
- zones_aws.go
- zones_gcp.go