Documentation
¶
Overview ¶
Package run provides facilities to run commands inside Terramate context and ordering.
Index ¶
- Constants
- func BuildDAG(d *dag.DAG[*config.Stack], root *config.Root, s *config.Stack, ...) error
- func BuildDAGFromStacks[S ~[]E, E any](root *config.Root, items S, getStack func(E) *config.Stack) (*dag.DAG[E], string, error)
- func Getenv(key string, environ []string) (val string, found bool)
- func LookPath(file string, environ []string) (string, error)
- func ResetVersionCache()
- func ResolveVersion(ctx context.Context, environ []string, binary string) string
- func ResolveVersionFor(ctx context.Context, environ []string, binary, resolvedPath string) string
- func ResolveVersionForResolvedPath(ctx context.Context, resolvedPath string) string
- func SeedVersionForResolvedPath(resolvedPath, version string)
- func SetTestVersionOverride(binary, version string)
- func Sort[S ~[]E, E any](root *config.Root, items S, getStack func(E) *config.Stack) (string, error)
- type CLIRunner
- type EnvVars
- type OnceMap
Constants ¶
const ( // ErrLoadingGlobals indicates that an error happened while loading globals. ErrLoadingGlobals errors.Kind = "loading globals to evaluate terramate.config.run.env configuration" // ErrEval indicates that an error happened while evaluating one of the // terramate.config.run.env attributes. ErrEval errors.Kind = "evaluating terramate.config.run.env attribute" // ErrInvalidEnvVarType indicates the env var attribute // has an invalid type. ErrInvalidEnvVarType errors.Kind = "invalid environment variable type" )
const ErrNotFound errors.Kind = "executable file not found in $PATH"
ErrNotFound is the error resulting if a path search failed to find an executable file.
Variables ¶
This section is empty.
Functions ¶
func BuildDAG ¶
func BuildDAG( d *dag.DAG[*config.Stack], root *config.Root, s *config.Stack, descendantsName string, getDescendants func(config.Stack) []string, ancestorsName string, getAncestors func(config.Stack) []string, visited dag.Visited, ) error
BuildDAG builds a run order DAG for the given stack.
func BuildDAGFromStacks ¶ added in v0.5.0
func BuildDAGFromStacks[S ~[]E, E any](root *config.Root, items S, getStack func(E) *config.Stack) (*dag.DAG[E], string, error)
BuildDAGFromStacks computes the final, reduced dag for the given list of stacks.
func Getenv ¶ added in v0.12.0
Getenv returns the value of the environment variable named by the key, which is assumed to be case-insensitive, from the given environment. If the variable is not present in the environment, found is false.
func LookPath ¶ added in v0.4.2
LookPath searches for an executable named file in the directories named by the PATH environment variable. If file contains a slash, it is tried directly and the PATH is not consulted. Otherwise, on success, the result is an absolute path.
In older versions of Go, LookPath could return a path relative to the current directory. As of Go 1.19, LookPath will instead return that path along with an error satisfying errors.Is(err, ErrDot). See the package documentation for more details.
func ResetVersionCache ¶ added in v0.14.7
func ResetVersionCache()
ResetVersionCache clears the shared version cache. Intended for tests.
func ResolveVersion ¶ added in v0.14.7
ResolveVersion returns the semantic version of the given binary by executing "<binary> --version", parsed with a generic semver regex. The shell-out is performed at most once per resolved binary path across the process.
func ResolveVersionFor ¶ added in v0.14.7
ResolveVersionFor returns the semantic version for a given binary. If a test override is configured for the binary name it is returned immediately. If a non-empty resolvedPath is provided, it will be used to avoid any additional path lookups. Otherwise it falls back to ResolveVersion which may look up the binary in PATH.
func ResolveVersionForResolvedPath ¶ added in v0.14.7
ResolveVersionForResolvedPath returns the semantic version of the given binary at the provided resolved path by executing "<resolvedPath> --version". The shell-out is performed at most once per resolved binary path across the process.
func SeedVersionForResolvedPath ¶ added in v0.14.7
func SeedVersionForResolvedPath(resolvedPath, version string)
SeedVersionForResolvedPath sets the version for a given resolved binary path. Useful for tests to avoid shelling out.
func SetTestVersionOverride ¶ added in v0.14.7
func SetTestVersionOverride(binary, version string)
SetTestVersionOverride sets a version override by binary name for tests. When set, ResolveVersion will return this value without shelling out.
Types ¶
type CLIRunner ¶ added in v0.14.7
type CLIRunner interface {
// Name returns the CLI runner name (e.g. "terraform", "terragrunt", "tofu").
Name() string
// Version returns the cached semantic version string of the underlying CLI.
// Must use the shared version cache to avoid repeated shell-outs.
Version(ctx context.Context) string
ShowCommand(ctx context.Context, planfile string, flags ...string) (*exec.Cmd, error)
}
CLIRunner abstracts common CLI operations used by terraform, terragrunt and tofu runners. Implementations should be thin wrappers around the actual binaries and must not mutate provided arguments. Methods that execute commands return a prepared *exec.Cmd ready to run.
type EnvVars ¶
type EnvVars []string
EnvVars represents a set of environment variables to be used when running commands. Each string follows the same format used on os.Environ and can be used to set env on exec.Cmd.
func LoadEnv ¶
LoadEnv will load environment variables to be exported when running any command inside the given stack. The order of the env vars is guaranteed to be the same and is ordered lexicographically. All defined `terramate.config.run.env` definitions from the provided stack dir up to the root of the project are collected, and env definitions closer to the stack have precedence over parent definitions.
type OnceMap ¶ added in v0.11.6
OnceMap contains map of key/value pairs that is safe for concurrent initialization.
func NewOnceMap ¶ added in v0.11.6
NewOnceMap returns a new empty OnceMap.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package dag provides the Directed-Acyclic-Graph (DAG) primitives required by Terramate.
|
Package dag provides the Directed-Acyclic-Graph (DAG) primitives required by Terramate. |
|
Package terraform provides utilities for executing terraform commands with configurable arguments.
|
Package terraform provides utilities for executing terraform commands with configurable arguments. |
|
Package terragrunt provides utilities for executing terragrunt commands with configurable arguments.
|
Package terragrunt provides utilities for executing terragrunt commands with configurable arguments. |
|
Package tofu provides utilities for executing OpenTofu commands with configurable arguments.
|
Package tofu provides utilities for executing OpenTofu commands with configurable arguments. |