config

package
v0.8.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 10, 2024 License: MPL-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package config provides high level Terramate configuration facilities.

Index

Constants

View Source
const (
	// DefaultFilename is the name of the default Terramate configuration file.
	DefaultFilename = "terramate.tm.hcl"

	// SkipFilename is the name of Terramate skip file.
	SkipFilename = ".tmskip"
)
View Source
const (
	ErrScriptSchema              errors.Kind = "script config has an invalid schema"
	ErrScriptInvalidType         errors.Kind = "invalid type for script field"
	ErrScriptInvalidTypeCommand  errors.Kind = "invalid type for script.command"
	ErrScriptInvalidTypeCommands errors.Kind = "invalid type for script.commands"
	ErrScriptEmptyCmds           errors.Kind = "job command or commands evaluated to empty list"
	ErrScriptInvalidCmdOptions   errors.Kind = "invalid options for script command"
)

Errors for indicating invalid script schema

View Source
const (
	// ErrStackValidation indicates an error when validating the stack fields.
	ErrStackValidation errors.Kind = "validating stack fields"

	// ErrStackDuplicatedID indicates that two or more stacks have the same ID.
	ErrStackDuplicatedID errors.Kind = "duplicated ID found on stacks"

	// ErrStackInvalidWatch indicates the stack.watch attribute contains invalid values.
	ErrStackInvalidWatch errors.Kind = "invalid stack.watch attribute"

	// ErrStackInvalidTag indicates the stack.tags is invalid.
	ErrStackInvalidTag errors.Kind = "invalid stack.tags entry"

	// ErrStackInvalidWants indicates the stack.wants is invalid.
	ErrStackInvalidWants errors.Kind = "invalid stack.wants entry"

	// ErrStackInvalidWantedBy indicates the stack.wanted_by is invalid.
	ErrStackInvalidWantedBy errors.Kind = "invalid stack.wanted_by entry"
)
View Source
const (
	// ErrSchema indicates that the configuration has an invalid schema.
	ErrSchema errors.Kind = "config has an invalid schema"
)
View Source
const MaxScriptDescRunes = 1000

MaxScriptDescRunes defines the maximum number of runes allowed for a script description.

View Source
const MaxScriptNameRunes = 128

MaxScriptNameRunes defines the maximum number of runes allowed for a script name.

Variables

This section is empty.

Functions

func IsStack

func IsStack(root *Root, dir string) bool

IsStack returns true if the given directory is a stack, false otherwise.

func ReverseStacks

func ReverseStacks(stacks List[*SortableStack])

ReverseStacks reverses the given stacks slice.

func Skip

func Skip(name string) bool

Skip returns true if the given file/dir name should be ignored by Terramate.

func ValidateWatchPaths added in v0.6.1

func ValidateWatchPaths(rootdir string, stackpath string, paths []string) (project.Paths, error)

ValidateWatchPaths validates if the provided watch paths points to regular files inside the project repository.

Types

type Assert

type Assert struct {
	Assertion bool
	Warning   bool
	Message   string
	Range     hhcl.Range
}

Assert represents evaluated assert block configuration.

func EvalAssert

func EvalAssert(evalctx *eval.Context, cfg hcl.AssertConfig) (Assert, error)

EvalAssert evaluates a given assert configuration and returns its evaluated form.

type DirElem

type DirElem interface {
	Dir() project.Path
}

DirElem represents a node which is represented by a directory. Eg.: stack, config, etc.

type List

type List[T DirElem] []T

List of directory based elements which implements the sorting interface by the directory path.

func LoadAllStacks

func LoadAllStacks(root *Root, cfg *Tree) (List[*SortableStack], error)

LoadAllStacks loads all stacks inside the given rootdir.

func StacksFromTrees

func StacksFromTrees(trees List[*Tree]) (List[*SortableStack], error)

StacksFromTrees converts a List[*Tree] into a List[*Stack].

func (List[T]) Len

func (l List[T]) Len() int

func (List[T]) Less

func (l List[T]) Less(i, j int) bool

func (List[T]) Paths

func (l List[T]) Paths() project.Paths

Paths returns the project paths from the list.

func (List[T]) Swap

func (l List[T]) Swap(i, j int)

type Root

type Root struct {
	// contains filtered or unexported fields
}

Root is the root configuration tree. This type is just for ensure better type checking for the cases where a configuration for the root directory is expected and not from anywhere else.

func LoadRoot

func LoadRoot(rootdir string) (*Root, error)

LoadRoot loads the root configuration tree.

func NewRoot

func NewRoot(tree *Tree) *Root

NewRoot creates a new Root tree for the cfg tree.

func TryLoadConfig

func TryLoadConfig(fromdir string) (tree *Root, configpath string, found bool, err error)

TryLoadConfig try to load the Terramate configuration tree. It looks for the the config in fromdir and all parent directories until / is reached. If the configuration is found, it returns the whole configuration tree, configpath != "" and found as true.

func (*Root) HasExperiment added in v0.4.4

func (root *Root) HasExperiment(name string) bool

HasExperiment returns true if the given experiment name is set.

func (*Root) HasTerragruntStacks added in v0.6.5

func (root *Root) HasTerragruntStacks() bool

HasTerragruntStacks returns true if the stack loading has detected Terragrunt files.

func (*Root) HostDir

func (root *Root) HostDir() string

HostDir returns the root directory.

func (*Root) IsTerragruntChangeDetectionEnabled added in v0.6.5

func (root *Root) IsTerragruntChangeDetectionEnabled() bool

IsTerragruntChangeDetectionEnabled returns true if Terragrunt change detection integration must be executed.

func (*Root) LoadSubTree

func (root *Root) LoadSubTree(cfgdir project.Path) error

LoadSubTree loads a subtree located at cfgdir into the current tree.

func (*Root) Lookup

func (root *Root) Lookup(path project.Path) (*Tree, bool)

Lookup a node from the root using a filesystem query path.

func (*Root) Runtime

func (root *Root) Runtime() project.Runtime

Runtime returns a copy the runtime for the root terramate namespace as a cty.Value map.

func (*Root) Stacks

func (root *Root) Stacks() project.Paths

Stacks return the stacks paths.

func (*Root) StacksByPaths

func (root *Root) StacksByPaths(base project.Path, relpaths ...string) List[*Tree]

StacksByPaths returns the stacks from the provided relative paths.

func (*Root) StacksByTagsFilters

func (root *Root) StacksByTagsFilters(filters []string) (project.Paths, error)

StacksByTagsFilters returns the paths of all stacks matching the filters.

func (*Root) TerragruntEnabledOption added in v0.6.5

func (root *Root) TerragruntEnabledOption() hcl.TerragruntChangeDetectionEnabledOption

TerragruntEnabledOption returns the configured `terramate.config.change_detection.terragrunt.enabled` option.

func (*Root) Tree

func (root *Root) Tree() *Tree

Tree returns the root configuration tree.

type Script added in v0.4.4

type Script struct {
	Range       info.Range
	Labels      []string
	Name        string
	Description string
	Jobs        []ScriptJob
}

Script represents an evaluated script block

func EvalScript added in v0.4.4

func EvalScript(evalctx *eval.Context, script hcl.Script) (Script, error)

EvalScript evaluates a script block using the provided evaluation context

type ScriptCmd added in v0.4.4

type ScriptCmd struct {
	Args    []string
	Options *ScriptCmdOptions
}

ScriptCmd represents an evaluated script command

type ScriptCmdOptions added in v0.4.4

type ScriptCmdOptions struct {
	CloudSyncDeployment    bool
	CloudSyncDriftStatus   bool
	CloudSyncPreview       bool
	CloudSyncLayer         preview.Layer
	CloudTerraformPlanFile string
	CloudTofuPlanFile      string
	UseTerragrunt          bool
}

ScriptCmdOptions represents optional parameters for a script command

type ScriptJob added in v0.4.4

type ScriptJob struct {
	Name        string
	Description string
	Cmd         *ScriptCmd
	Cmds        []*ScriptCmd
}

ScriptJob represents an evaluated job block

func (ScriptJob) Commands added in v0.4.4

func (es ScriptJob) Commands() []*ScriptCmd

Commands is a convenience method for callers who don't specifically care about which command attr was set e.g. command or commands. This method returns a list of commands irrespective of whether they were set through job.command or job.commands

type SortableStack

type SortableStack struct {
	*Stack
}

SortableStack is a wrapper for the Stack which implements the DirElem type.

func (SortableStack) Dir

func (s SortableStack) Dir() project.Path

Dir implements the List type.

type Stack

type Stack struct {
	// Dir is project's stack directory.
	Dir project.Path

	// ID of the stack.
	ID string

	// Name of the stack.
	Name string

	// Description is the description of the stack.
	Description string

	// Tags is the list of tags of the stack.
	// A tag
	Tags []string

	// After is a list of stack paths that must run before this stack.
	After []string

	// Before is a list of stack paths that must run after this stack.
	Before []string

	// Wants is the list of stacks that must be selected whenever this stack
	// is selected.
	Wants []string

	// wantedBy is the list of stacks that must select this stack
	// whenever they are selected.
	WantedBy []string

	// Watch is the list of files to be watched for changes.
	Watch project.Paths

	// IsChanged tells if this is a changed stack.
	IsChanged bool
}

Stack represents an evaluated stack.

func LoadStack

func LoadStack(root *Root, dir project.Path) (*Stack, error)

LoadStack a single stack from dir.

func NewStackFromHCL

func NewStackFromHCL(root string, cfg hcl.Config) (*Stack, error)

NewStackFromHCL creates a new stack from raw configuration cfg.

func TryLoadStack

func TryLoadStack(root *Root, cfgdir project.Path) (stack *Stack, found bool, err error)

TryLoadStack tries to load a single stack from dir. It sets found as true in case the stack was successfully loaded.

func (*Stack) AppendBefore

func (s *Stack) AppendBefore(path string)

AppendBefore appends the path to the list of stacks that must run after this stack.

func (*Stack) HostDir

func (s *Stack) HostDir(root *Root) string

HostDir returns the file system absolute path of stack.

func (*Stack) PathBase

func (s *Stack) PathBase() string

PathBase returns the base name of the stack path.

func (*Stack) RelPath

func (s *Stack) RelPath() string

RelPath returns the project's relative path of stack.

func (*Stack) RelPathToRoot

func (s *Stack) RelPathToRoot(root *Root) string

RelPathToRoot returns the relative path from the stack to root.

func (*Stack) RuntimeValues

func (s *Stack) RuntimeValues(root *Root) map[string]cty.Value

RuntimeValues returns the runtime "terramate" namespace for the stack.

func (*Stack) Sortable

func (s *Stack) Sortable() *SortableStack

Sortable returns an implementation of stack which can be sorted by config.List.

func (*Stack) String

func (s *Stack) String() string

String representation of the stack.

func (Stack) Validate

func (s Stack) Validate() error

Validate if all stack fields are correct.

func (Stack) ValidateSets

func (s Stack) ValidateSets() error

ValidateSets validate all stack set fields.

func (Stack) ValidateTags

func (s Stack) ValidateTags() error

ValidateTags validates if tags are correctly used in all stack fields.

type Tree

type Tree struct {
	// Node is the configuration of this tree node.
	Node hcl.Config

	// Children is a map of configuration dir names to tree nodes.
	Children map[string]*Tree

	// Parent is the parent node or nil if none.
	Parent *Tree
	// contains filtered or unexported fields
}

Tree is the configuration tree. The tree maps the filesystem directories, which means each directory in the project has a tree instance even if it's empty (ie no .tm files in it).

func LoadTree

func LoadTree(rootdir string, cfgdir string) (*Tree, error)

LoadTree loads the whole hierarchical configuration from cfgdir downwards using rootdir as project root.

func NewTree

func NewTree(cfgdir string) *Tree

NewTree creates a new tree node.

func (*Tree) AsList

func (tree *Tree) AsList() List[*Tree]

AsList returns a list with this node and all its children.

func (*Tree) Dir

func (tree *Tree) Dir() project.Path

Dir returns the directory as a project dir.

func (*Tree) HostDir

func (tree *Tree) HostDir() string

HostDir is the node absolute directory in the host.

func (*Tree) IsEmptyConfig

func (tree *Tree) IsEmptyConfig() bool

IsEmptyConfig tells if the configuration is empty.

func (*Tree) IsStack

func (tree *Tree) IsStack() bool

IsStack tells if the node is a stack.

func (*Tree) NonEmptyGlobalsParent

func (tree *Tree) NonEmptyGlobalsParent() *Tree

NonEmptyGlobalsParent returns a parent configuration which has globals defined, if any.

func (*Tree) Root

func (tree *Tree) Root() *Root

Root returns the root of the configuration tree.

func (*Tree) RootDir

func (tree *Tree) RootDir() string

RootDir returns the tree root directory..

func (*Tree) RootTree added in v0.6.5

func (tree *Tree) RootTree() *Tree

RootTree returns the tree at the project root.

func (*Tree) Stack added in v0.5.0

func (tree *Tree) Stack() (*Stack, error)

Stack returns the stack object.

func (*Tree) Stacks

func (tree *Tree) Stacks() List[*Tree]

Stacks returns the stack nodes from the tree. The search algorithm is a Deep-First-Search (DFS).

Directories

Path Synopsis
Package filter provides helpers for filtering objects.
Package filter provides helpers for filtering objects.
Package tag provides helpers for dealing with Terramate tags.
Package tag provides helpers for dealing with Terramate tags.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL