Documentation ¶
Overview ¶
Package configs is a slimmed down terraform/internal/configs. The reason we have this "fork" is because Terraform moved this dependency into internal/ package.
Current version is v1.2.8
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsIgnoredFile ¶
IsIgnoredFile returns true if the given filename (which must not have a directory path ahead of it) should be ignored as e.g. an editor swap file.
Types ¶
type CheckRule ¶
type CheckRule struct { // Condition is an expression that must evaluate to true if the condition // holds or false if it does not. If the expression produces an error then // that's considered to be a bug in the module defining the check. // // The available variables in a condition expression vary depending on what // a check is attached to. For example, validation rules attached to // input variables can only refer to the variable that is being validated. Condition hcl.Expression // ErrorMessage should be one or more full sentences, which should be in // English for consistency with the rest of the error message output but // can in practice be in any language. The message should describe what is // required for the condition to return true in a way that would make sense // to a caller of the module. // // The error message expression has the same variables available for // interpolation as the corresponding condition. ErrorMessage hcl.Expression DeclRange hcl.Range }
CheckRule represents a configuration-defined validation rule, precondition, or postcondition. Blocks of this sort can appear in a few different places in configuration, including "validation" blocks for variables, and "precondition" and "postcondition" blocks for resources.
type File ¶
type File struct {
Variables []*Variable
}
File describes the contents of a single configuration file.
Individual files are not usually used alone, but rather combined together with other files (conventionally, those in the same directory) to produce a *Module, using NewModule.
At the level of an individual file we represent directly the structural elements present in the file, without any attempt to detect conflicting declarations. A File object can therefore be used for some basic static analysis of individual elements, but must be built into a Module to detect duplicate declarations.
type Module ¶
Module is a container for a set of configuration constructs that are evaluated within a common namespace.
func NewModule ¶
NewModule takes a list of primary files and a list of override files and produces a *Module by combining the files together.
If there are any conflicting declarations in the given files -- for example, if the same variable name is defined twice -- then the resulting module will be incomplete and error diagnostics will be returned. Careful static analysis of the returned Module is still possible in this case, but the module will probably not be semantically valid.
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) LoadConfigDir ¶
LoadConfigDir reads the .tf and .tf.json files in the given directory as config files (using LoadConfigFile) 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) LoadConfigFile ¶
LoadConfigFile reads the file at the given path and parses it as a config file.
If the file cannot be read -- for example, if it does not exist -- then a nil *File 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.
func (*Parser) LoadConfigFileOverride ¶
LoadConfigFileOverride is the same as LoadConfigFile except that it relaxes certain required attribute constraints in order to interpret the given file as an overrides file.
func (*Parser) LoadHCLFile ¶
LoadHCLFile is a low-level method that reads the file at the given path, parses it, and returns the hcl.Body representing its root. In many cases it is better to use one of the other Load*File methods on this type, which additionally decode the root body in some way and return a higher-level construct.
If the file cannot be read at all -- e.g. because it does not exist -- then this method will return a nil body and error diagnostics. In this case callers may wish to ignore the provided error diagnostics and produce a more context-sensitive error instead.
The file will be parsed using the HCL native syntax unless the filename ends with ".json", in which case the HCL JSON syntax will be used.
type Variable ¶
type Variable struct { Name string Description string Default cty.Value // Type is the concrete type of the variable value. Type cty.Type // ConstraintType is used for decoding and type conversions, and may // contain nested ObjectWithOptionalAttr types. ConstraintType cty.Type TypeDefaults *typeexpr.Defaults ParsingMode VariableParsingMode Sensitive bool DescriptionSet bool SensitiveSet bool // Nullable indicates that null is a valid value for this variable. Setting // Nullable to false means that the module can expect this variable to // never be null. Nullable bool NullableSet bool DeclRange hcl.Range }
Variable represents a "variable" block in a module or file.
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.