Documentation
¶
Index ¶
- type Config
- type ContextMeta
- type Evaluator
- type InputValue
- type InputValues
- type Module
- type ModuleCall
- type ModuleRequest
- type ModuleWalker
- type ModuleWalkerFunc
- type Parser
- func (p Parser) ConfigDirFiles(dir string) (primary, override []string, diags hcl.Diagnostics)
- func (p *Parser) IsConfigDir(path string) bool
- func (p *Parser) LoadConfigDir(dir string) (*Module, hcl.Diagnostics)
- func (p *Parser) LoadValuesFile(path string) (map[string]cty.Value, hcl.Diagnostics)
- func (p *Parser) Sources() map[string][]byte
- type Variable
- type VariableParsingMode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // RootModule points to the Config for the root module within the same // module tree as this module. If this module _is_ the root module then // this is self-referential. Root *Config // Path is a sequence of module logical names that traverse from the root // module to this config. Path is empty for the root module. Path addrs.Module // ChildModules points to the Config for each of the direct child modules // called from this module. The keys in this map match the keys in // Module.ModuleCalls. Children map[string]*Config // Module points to the object describing the configuration for the // various elements (variables, resources, etc) defined by this module. Module *Module }
A Config is a node in the tree of modules within a configuration.
The module tree is constructed by following ModuleCall instances recursively through the root module transitively into descendent modules.
func BuildConfig ¶
func BuildConfig(root *Module, walker ModuleWalker) (*Config, hcl.Diagnostics)
BuildConfig constructs a Config from a root module by loading all of its descendent modules via the given ModuleWalker.
The result is a module tree that has so far only had basic module- and file-level invariants validated. If the returned diagnostics contains errors, the returned module tree may be incomplete but can still be used carefully for static analysis.
func NewEmptyConfig ¶
func NewEmptyConfig() *Config
NewEmptyConfig constructs a single-node configuration tree with an empty root module. This is generally a pretty useless thing to do, so most callers should instead use BuildConfig.
func (*Config) DescendentForInstance ¶
func (c *Config) DescendentForInstance(path addrs.ModuleInstance) *Config
DescendentForInstance returns the descendent config that has the given instance path beneath the receiver, or nil if there is no such module.
type ContextMeta ¶
type Evaluator ¶
type Evaluator struct { Meta *ContextMeta ModulePath addrs.ModuleInstance Config *Config VariableValues map[string]map[string]cty.Value }
type InputValue ¶
type InputValues ¶
type InputValues map[string]*InputValue
func (InputValues) Override ¶
func (vv InputValues) Override(others ...InputValues) InputValues
type Module ¶
type Module struct { Resources hclext.Blocks Variables map[string]*Variable ModuleCalls map[string]*ModuleCall SourceDir string Sources map[string][]byte Files map[string]*hcl.File // contains filtered or unexported fields }
func NewEmptyModule ¶
func NewEmptyModule() *Module
func (*Module) PartialContent ¶
func (m *Module) PartialContent(schema *hclext.BodySchema) (*hclext.BodyContent, hcl.Diagnostics)
type ModuleCall ¶
type ModuleRequest ¶
type ModuleRequest struct { // Name is the "logical name" of the module call within configuration. // This is provided in case the name is used as part of a storage key // for the module, but implementations must otherwise treat it as an // opaque string. Name string // Path is a list of logical names that traverse from the root module to // this module. This can be used, for example, to form a lookup key for // each distinct module call in a configuration, allowing for multiple // calls with the same name at different points in the tree. Path addrs.Module // CallRange is the source range for the header of the "module" block // in configuration that prompted this request. This can be used as the // subject of an error diagnostic that relates to the module call itself. CallRange hcl.Range }
ModuleRequest is used with the ModuleWalker interface to describe a child module that must be loaded.
type ModuleWalker ¶
type ModuleWalker interface { // LoadModule finds and loads a requested child module. // // If errors are detected during loading, implementations should return them // in the diagnostics object. If the diagnostics object contains any errors // then the caller will tolerate the returned module being nil or incomplete. // If no errors are returned, it should be non-nil and complete. // // Full validation need not have been performed but an implementation should // ensure that the basic file- and module-validations performed by the // LoadConfigDir function (valid syntax, no namespace collisions, etc) have // been performed before returning a module. LoadModule(req *ModuleRequest) (*Module, *version.Version, hcl.Diagnostics) }
A ModuleWalker knows how to find and load a child module given details about the module to be loaded and a reference to its partially-loaded parent Config.
type ModuleWalkerFunc ¶
type ModuleWalkerFunc func(req *ModuleRequest) (*Module, *version.Version, hcl.Diagnostics)
ModuleWalkerFunc is an implementation of ModuleWalker that directly wraps a callback function, for more convenient use of that interface.
func (ModuleWalkerFunc) LoadModule ¶
func (f ModuleWalkerFunc) LoadModule(req *ModuleRequest) (*Module, *version.Version, hcl.Diagnostics)
LoadModule implements ModuleWalker.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser is the main interface to read configuration files and other related files from disk.
It retains a cache of all files that are loaded so that they can be used to create source code snippets in diagnostics, etc.
func NewParser ¶
NewParser creates and returns a new Parser that reads files from the given filesystem. If a nil filesystem is passed then the system's "real" filesystem will be used, via afero.OsFs.
func (Parser) ConfigDirFiles ¶
ConfigDirFiles returns lists of the primary and override files configuration files in the given directory.
If the given directory does not exist or cannot be read, error diagnostics are returned. If errors are returned, the resulting lists may be incomplete.
func (*Parser) IsConfigDir ¶
IsConfigDir determines whether the given path refers to a directory that exists and contains at least one Terraform config file (with a .tf or .tf.json extension.)
func (*Parser) LoadConfigDir ¶
LoadConfigDir reads the .tf and .tf.json files in the given directory and then combines these files into a single Module.
If this method returns nil, that indicates that the given directory does not exist at all or could not be opened for some reason. Callers may wish to detect this case and ignore the returned diagnostics so that they can produce a more context-aware error message in that case.
If this method returns a non-nil module while error diagnostics are returned then the module may be incomplete but can be used carefully for static analysis.
This file does not consider a directory with no files to be an error, and will simply return an empty module in that case. Callers should first call Parser.IsConfigDir if they wish to recognize that situation.
.tf files are parsed using the HCL native syntax while .tf.json files are parsed using the HCL JSON syntax.
func (*Parser) LoadValuesFile ¶
LoadValuesFile reads the file at the given path and parses it as a "values file", which is an HCL config file whose top-level attributes are treated as arbitrary key.value pairs.
If the file cannot be read -- for example, if it does not exist -- then a nil map will be returned along with error diagnostics. Callers may wish to disregard the returned diagnostics in this case and instead generate their own error message(s) with additional context.
If the returned diagnostics has errors when a non-nil map is returned then the map may be incomplete but should be valid enough for careful static analysis.
This method wraps LoadHCLFile, and so it inherits the syntax selection behaviors documented for that method.
type VariableParsingMode ¶
type VariableParsingMode rune
VariableParsingMode defines how values of a particular variable given by text-only mechanisms (command line arguments and environment variables) should be parsed to produce the final value.
const VariableParseHCL VariableParsingMode = 'H'
VariableParseHCL is a variable parsing mode that attempts to parse the given string as an HCL expression and returns the result.
const VariableParseLiteral VariableParsingMode = 'L'
VariableParseLiteral is a variable parsing mode that just takes the given string directly as a cty.String value.
func (VariableParsingMode) Parse ¶
func (m VariableParsingMode) Parse(name, value string) (cty.Value, hcl.Diagnostics)
Parse uses the receiving parsing mode to process the given variable value string, returning the result along with any diagnostics.
A VariableParsingMode does not know the expected type of the corresponding variable, so it's the caller's responsibility to attempt to convert the result to the appropriate type and return to the user any diagnostics that conversion may produce.
The given name is used to create a synthetic filename in case any diagnostics must be generated about the given string value. This should be the name of the root module variable whose value will be populated from the given string.
If the returned diagnostics has errors, the returned value may not be valid.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package ipaddr is a fork of a subset of the Go standard "net" package which retains parsing behaviors from Go 1.16 or earlier.
|
Package ipaddr is a fork of a subset of the Go standard "net" package which retains parsing behaviors from Go 1.16 or earlier. |
types
Package types contains non-standard cty types used only within Terraform.
|
Package types contains non-standard cty types used only within Terraform. |