Documentation ¶
Overview ¶
Package hcl provides parsing functionality for Terramate HCL configuration. It also provides printing and formatting for Terramate configuration.
Index ¶
- Constants
- func IsRootConfig(rootdir string) (bool, error)
- func MatchAnyGlob(globs []glob.Glob, s string) bool
- func PrintConfig(w io.Writer, cfg Config) error
- func PrintImports(w io.Writer, imports []string) error
- func ValueAsStringList(val cty.Value) ([]string, error)
- type AssertConfig
- type ChangeDetectionConfig
- type CloudConfig
- type Command
- type Commands
- type Config
- type Evaluator
- type GenFileBlock
- type GenHCLBlock
- type GenerateConfig
- type GenerateRootConfig
- type GitConfig
- type Input
- type Inputs
- type ManifestConfig
- type ManifestDesc
- type OptionalCheck
- type Output
- type Outputs
- type RawConfig
- type RootConfig
- type RunConfig
- type RunEnv
- type Script
- type ScriptJob
- type SharingBackend
- type SharingBackendType
- type SharingBackends
- type Stack
- type StackFilterConfig
- type TargetsConfig
- type TerragruntChangeDetectionEnabledOption
- type TerragruntConfig
- type Terramate
- type TerramateParser
- func (p *TerramateParser) AddDir(dir string) error
- func (p *TerramateParser) AddFile(path string) error
- func (p *TerramateParser) AddFileContent(name string, data []byte) error
- func (p *TerramateParser) Imports() (ast.Blocks, error)
- func (p *TerramateParser) Parse() error
- func (p *TerramateParser) ParseConfig() (Config, error)
- func (p *TerramateParser) ParsedBodies() map[string]*hclsyntax.Body
- type VendorConfig
Constants ¶
const ( ErrHCLSyntax errors.Kind = "HCL syntax error" ErrTerramateSchema errors.Kind = "terramate schema error" ErrUnrecognizedBlock errors.Kind = "terramate schema error: unrecognized block" ErrImport errors.Kind = "import error" )
Errors returned during the HCL parsing.
const ( ErrScriptNoLabels errors.Kind = "terramate schema error: (script): must provide at least one label" ErrScriptRedeclared errors.Kind = "terramate schema error: (script): multiple script blocks with same labels in the same directory" ErrScriptUnrecognizedAttr errors.Kind = "terramate schema error: (script): unrecognized attribute" ErrScriptJobUnrecognizedAttr errors.Kind = "terramate schema error: (script.job): unrecognized attribute" ErrScriptUnrecognizedBlock errors.Kind = "terramate schema error: (script): unrecognized block" ErrScriptNoCmds errors.Kind = "terramate schema error: (script): missing command or commands" ErrScriptMissingOrInvalidJob errors.Kind = "terramate schema error: (script): missing or invalid job" ErrScriptCmdConflict errors.Kind = "terramate schema error: (script): conflicting attribute already set" )
Errors returned during the HCL parsing of script block
const SharingIsCaringExperimentName = "outputs-sharing"
SharingIsCaringExperimentName is the name of the outputs-sharing experiment.
const (
// StackBlockType name of the stack block type
StackBlockType = "stack"
)
Variables ¶
This section is empty.
Functions ¶
func IsRootConfig ¶ added in v0.4.4
IsRootConfig parses rootdir and tells if it contains a root config or not.
func MatchAnyGlob ¶ added in v0.4.5
MatchAnyGlob is a helper function to test if s matches any of the given patterns.
func PrintConfig ¶
PrintConfig will print the given config as HCL on the given writer.
func PrintImports ¶
PrintImports will print the given imports list as import blocks.
Types ¶
type AssertConfig ¶
type AssertConfig struct { Range info.Range Warning hcl.Expression Assertion hcl.Expression Message hcl.Expression }
AssertConfig represents Terramate assert configuration block.
type ChangeDetectionConfig ¶ added in v0.6.5
type ChangeDetectionConfig struct {
Terragrunt *TerragruntConfig
}
ChangeDetectionConfig is the `terramate.config.change_detection` config.
type CloudConfig ¶ added in v0.4.3
type CloudConfig struct { // Organization is the name of the cloud organization Organization string Targets *TargetsConfig }
CloudConfig represents Terramate cloud configuration.
type Command ¶ added in v0.4.4
Command represents an executable command
func NewScriptCommand ¶ added in v0.4.4
NewScriptCommand returns a *Command encapsulating an ast.Attribute
type Commands ¶ added in v0.4.4
Commands represents a list of executable commands
func NewScriptCommands ¶ added in v0.4.4
NewScriptCommands returns *Commands encapsulating an ast.Attribute
type Config ¶
type Config struct { Terramate *Terramate Stack *Stack Globals ast.MergedLabelBlocks Vendor *VendorConfig Asserts []AssertConfig Generate GenerateConfig Scripts []*Script SharingBackends SharingBackends Inputs Inputs Outputs Outputs Imported RawConfig // contains filtered or unexported fields }
Config represents a Terramate configuration.
func ParseDir ¶
ParseDir will parse Terramate configuration from a given directory, using root as project workspace, parsing all files with the suffixes .tm and .tm.hcl. It parses in non-strict mode for compatibility with older versions. Note: it does not recurse into child directories.
func (Config) Experiments ¶ added in v0.4.4
Experiments returns the config enabled experiments, if any.
func (Config) HasGlobals ¶
HasGlobals tells if the configuration has any globals defined.
func (Config) HasRunEnv ¶
HasRunEnv returns true if the config has a terramate.config.run.env block defined
func (Config) IsRootConfig ¶ added in v0.9.1
IsRootConfig tells if the Config is a root configuration.
type Evaluator ¶
type Evaluator interface { // Eval evaluates the given expression returning a value. Eval(hcl.Expression) (cty.Value, error) // PartialEval partially evaluates the given expression returning the // tokens that form the result of the partial evaluation. Any unknown // namespace access are ignored and left as is, while known namespaces // are substituted by its value. // If any unknowns are found, the method returns hasUnknowns as true. PartialEval(hcl.Expression) (expr hcl.Expression, hasUnknowns bool, err error) // SetNamespace adds a new namespace, replacing any with the same name. SetNamespace(name string, values map[string]cty.Value) // DeleteNamespace deletes a namespace. DeleteNamespace(name string) }
Evaluator represents a Terramate evaluator
type GenFileBlock ¶
type GenFileBlock struct { // Dir where the block is declared. Dir project.Path // Range is the range of the entire block definition. Range info.Range // Label of the block Label string // Lets is a block of local variables. Lets *ast.MergedBlock // Condition attribute of the block, if any. Condition *hclsyntax.Attribute // Represents all stack_filter blocks StackFilters []StackFilterConfig // Content attribute of the block Content *hclsyntax.Attribute // Context of the generation (stack by default). Context string // Asserts represents all assert blocks Asserts []AssertConfig // Inherit tells if the block is inherited in child directories. Inherit *hclsyntax.Attribute }
GenFileBlock represents a parsed generate_file block
type GenHCLBlock ¶
type GenHCLBlock struct { // Dir where the block is declared. Dir project.Path // Range is the range of the entire block definition. Range info.Range // Label of the block. Label string // Lets is a block of local variables. Lets *ast.MergedBlock // Condition attribute of the block, if any. Condition *hclsyntax.Attribute // Represents all stack_filter blocks StackFilters []StackFilterConfig // Content block. Content *hcl.Block // Asserts represents all assert blocks Asserts []AssertConfig // Inherit tells if the block is inherited in child directories. Inherit *hclsyntax.Attribute // IsImplicitBlock tells if the block is implicit (does not have a real generate_hcl block). // This is the case for the "tmgen" feature. IsImplicitBlock bool }
GenHCLBlock represents a parsed generate_hcl block.
type GenerateConfig ¶
type GenerateConfig struct { Files []GenFileBlock HCLs []GenHCLBlock }
GenerateConfig includes code generation related configurations, like generate_file and generate_hcl.
type GenerateRootConfig ¶ added in v0.5.0
type GenerateRootConfig struct {
HCLMagicHeaderCommentStyle *string
}
GenerateRootConfig represents the AST node for the `terramate.config.generate` block.
type GitConfig ¶
type GitConfig struct { // DefaultBranch is the default branch. DefaultBranch string // DefaultRemote is the default remote. DefaultRemote string // CheckUntracked enables untracked files checking. CheckUntracked bool // CheckUncommitted enables uncommitted files checking. CheckUncommitted bool // CheckRemote enables checking if local default branch is updated with remote. CheckRemote OptionalCheck }
GitConfig represents Terramate Git configuration.
func NewGitConfig ¶
func NewGitConfig() *GitConfig
NewGitConfig creates a git configuration with proper default values.
type Input ¶ added in v0.10.1
type Input struct { info.Range Name string Backend hcl.Expression FromStackID hcl.Expression Value hcl.Expression Sensitive hcl.Expression Mock hcl.Expression }
Input holds the parsed values for the `input` block.
type ManifestConfig ¶
type ManifestConfig struct {
Default *ManifestDesc
}
ManifestConfig represents the manifest config block of a Terramate configuration.
type ManifestDesc ¶
type ManifestDesc struct { // Files is a list of patterns that specify which files the manifest wants to include. Files []string // Excludes is a list of patterns that specify which files the manifest wants to exclude. Excludes []string }
ManifestDesc represents a parsed manifest description.
type OptionalCheck ¶ added in v0.4.4
type OptionalCheck int
OptionalCheck is a bool that can also have no configured value.
const ( // CheckIsUnset means no value was specified. CheckIsUnset OptionalCheck = iota // CheckIsFalse means the check is disabled. CheckIsFalse // CheckIsTrue means the check is enabled. CheckIsTrue )
func ToOptionalCheck ¶ added in v0.4.4
func ToOptionalCheck(v bool) OptionalCheck
ToOptionalCheck creates an OptionalCheck value from a bool.
func (OptionalCheck) ValueOr ¶ added in v0.4.4
func (v OptionalCheck) ValueOr(def bool) bool
ValueOr returns if an OptionalCheck is enabled, or the given default if its unset.
type Output ¶ added in v0.10.1
type Output struct { info.Range Name string Backend hcl.Expression Description hcl.Expression Value hcl.Expression Sensitive hcl.Expression }
Output holds the parsed value for the `output` block.
type RawConfig ¶
type RawConfig struct { // MergedAttributes are the top-level attributes of all files. // This will be available after calling Parse or ParseConfig MergedAttributes ast.Attributes // MergedBlocks are the merged blocks from all files. // This will be available after calling Parse or ParseConfig MergedBlocks ast.MergedBlocks // MergedLabelBlocks are the labelled merged blocks. // This will be available after calling Parse or ParseConfig MergedLabelBlocks ast.MergedLabelBlocks // UnmergedBlocks are the unmerged blocks from all files. // This will be available after calling Parse or ParseConfig UnmergedBlocks ast.Blocks // contains filtered or unexported fields }
RawConfig is the configuration (attributes and blocks) without schema validations.
func NewCustomRawConfig ¶
NewCustomRawConfig returns a new customized RawConfig.
func NewTopLevelRawConfig ¶
func NewTopLevelRawConfig() RawConfig
NewTopLevelRawConfig returns a new RawConfig object tailored for the Terramate top-level attributes and blocks.
type RootConfig ¶
type RootConfig struct { Git *GitConfig Generate *GenerateRootConfig ChangeDetection *ChangeDetectionConfig Run *RunConfig Cloud *CloudConfig Experiments []string DisableSafeguards safeguard.Keywords }
RootConfig represents the root config block of a Terramate configuration.
func (*RootConfig) HasSafeguardDisabled ¶ added in v0.4.5
func (r *RootConfig) HasSafeguardDisabled(keyword safeguard.Keyword) bool
HasSafeguardDisabled checks if the configuration (including the deprecated) has the given keyword disabled.
type RunConfig ¶
type RunConfig struct { // CheckGenCode enables generated code is up-to-date check on run. CheckGenCode bool // Env contains environment definitions for run. Env *RunEnv }
RunConfig represents Terramate run configuration.
func NewRunConfig ¶ added in v0.4.5
func NewRunConfig() *RunConfig
NewRunConfig creates a new run configuration.
type RunEnv ¶
type RunEnv struct { // Attributes is the collection of attribute definitions within the env block. Attributes ast.Attributes }
RunEnv represents Terramate run environment.
type Script ¶ added in v0.4.4
type Script struct { Range info.Range Labels []string // Labels of the script block used for grouping scripts Name *ast.Attribute // Name of the script Description *ast.Attribute // Description is a human readable description of a script Jobs []*ScriptJob // Job represents the command(s) part of this script Lets *ast.MergedBlock // Lets are script local variables. }
Script represents a parsed script block
func (*Script) AccessorName ¶ added in v0.5.0
AccessorName returns the name traversal for accessing the script.
type ScriptJob ¶ added in v0.4.4
type ScriptJob struct { Name *ast.Attribute Description *ast.Attribute Command *Command // Command is a single executable command Commands *Commands // Commands is a list of executable commands }
ScriptJob represent a Job within a Script
type SharingBackend ¶ added in v0.10.1
type SharingBackend struct { Name string Type SharingBackendType Command []string Filename string }
SharingBackend holds the parsed values for the `sharing_backend` block.
type SharingBackendType ¶ added in v0.10.1
type SharingBackendType int
SharingBackendType is the type of the sharing backend.
const (
TerraformSharingBackend SharingBackendType = iota + 1
)
These are the valid sharing_backend types.
func (SharingBackendType) String ¶ added in v0.10.1
func (st SharingBackendType) String() string
type SharingBackends ¶ added in v0.10.1
type SharingBackends []SharingBackend
SharingBackends is a list of SharingBackend blocks.
type Stack ¶
type Stack struct { // ID of the stack. If the ID is empty it indicates this stack has no ID. ID string // Name of the stack Name string // Description of the stack Description string // Tags is a list of non-duplicated list of tags Tags []string // After is a list of non-duplicated stack entries that must run before the // current stack runs. After []string // Before is a list of non-duplicated stack entries that must run after the // current stack runs. Before []string // Wants is a list of non-duplicated stack entries that must be selected // whenever the current stack is selected. Wants []string // WantedBy is a list of non-duplicated stack entries that must select // this stack whenever they are selected. WantedBy []string // Watch is a list of files to be watched for changes. Watch []string }
Stack is the parsed "stack" HCL block.
type StackFilterConfig ¶ added in v0.4.4
StackFilterConfig represents Terramate stack_filter configuration block.
type TargetsConfig ¶ added in v0.9.0
type TargetsConfig struct {
Enabled bool
}
TargetsConfig represents Terramate targets configuration.
type TerragruntChangeDetectionEnabledOption ¶ added in v0.6.5
type TerragruntChangeDetectionEnabledOption int
TerragruntChangeDetectionEnabledOption is the change detection options for enabling Terragrunt.
const ( TerragruntAutoOption TerragruntChangeDetectionEnabledOption = iota TerragruntOffOption TerragruntForceOption )
Terragrunt Enabling options.
type TerragruntConfig ¶ added in v0.6.5
type TerragruntConfig struct {
Enabled TerragruntChangeDetectionEnabledOption
}
TerragruntConfig is the `terramate.config.change_detection.terragrunt` config.
type Terramate ¶
type Terramate struct { // RequiredVersion contains the terramate version required by the stack. RequiredVersion string // RequiredVersionAllowPreReleases allows pre-release to be matched if true. RequiredVersionAllowPreReleases bool // Config is the parsed config blocks. Config *RootConfig }
Terramate is the parsed "terramate" HCL block.
type TerramateParser ¶
type TerramateParser struct { Config RawConfig Experiments []string Imported RawConfig // contains filtered or unexported fields }
TerramateParser is an HCL parser tailored for Terramate configuration schema. As the Terramate configuration can span multiple files in the same directory, this API allows you to define the exact set of files (and contents) that are going to be included in the final configuration.
func NewStrictTerramateParser ¶
func NewStrictTerramateParser(rootdir string, dir string, experiments ...string) (*TerramateParser, error)
NewStrictTerramateParser is like NewTerramateParser but will fail instead of warn for harmless configuration mistakes.
func NewTerramateParser ¶
func NewTerramateParser(rootdir string, dir string, experiments ...string) (*TerramateParser, error)
NewTerramateParser creates a Terramate parser for the directory dir inside the root directory. The parser creates sub-parsers for parsing imports but keeps a list of all parsed files of all sub-parsers for detecting cycles and import duplications. Calling Parse() or MinimalParse() multiple times is an error.
func (*TerramateParser) AddDir ¶
func (p *TerramateParser) AddDir(dir string) error
AddDir walks over all the files in the directory dir and add all .tm and .tm.hcl files to the parser.
func (*TerramateParser) AddFile ¶
func (p *TerramateParser) AddFile(path string) error
AddFile adds a file path to be parsed.
func (*TerramateParser) AddFileContent ¶
func (p *TerramateParser) AddFileContent(name string, data []byte) error
AddFileContent adds a file to the set of files to be parsed.
func (*TerramateParser) Imports ¶
func (p *TerramateParser) Imports() (ast.Blocks, error)
Imports returns all import blocks.
func (*TerramateParser) Parse ¶
func (p *TerramateParser) Parse() error
Parse does the syntax parsing and merging of configurations but do not validate if the HCL schema is a valid Terramate configuration.
func (*TerramateParser) ParseConfig ¶
func (p *TerramateParser) ParseConfig() (Config, error)
ParseConfig parses and checks the schema of previously added files and return either a Config or an error.
func (*TerramateParser) ParsedBodies ¶
func (p *TerramateParser) ParsedBodies() map[string]*hclsyntax.Body
ParsedBodies returns a map of filename to the parsed hclsyntax.Body.
type VendorConfig ¶
type VendorConfig struct { // Manifest is the parsed manifest block, if any. Manifest *ManifestConfig // Dir is the path where vendored projects will be stored. Dir string }
VendorConfig is the parsed "vendor" HCL block.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package ast provides low level parsing facilities for HCL configuration.
|
Package ast provides low level parsing facilities for HCL configuration. |
Package eval provides both full and partial evaluation of HCL.
|
Package eval provides both full and partial evaluation of HCL. |
Package fmt contains functions for formatting hcl config.
|
Package fmt contains functions for formatting hcl config. |
Package info provides informational types related to hcl.
|
Package info provides informational types related to hcl. |