common

package
v0.83.2 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2025 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package common provide base components for implementing runners.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoUnitsFound = errors.New("could not find any subfolders with Terragrunt configuration files")

Functions

This section is empty.

Types

type DependencyCycleError

type DependencyCycleError []string

func (DependencyCycleError) Error

func (err DependencyCycleError) Error() string

type DependencyNotFoundWhileCrossLinkingError

type DependencyNotFoundWhileCrossLinkingError struct {
	Unit       *Unit
	Dependency *Unit
}

func (DependencyNotFoundWhileCrossLinkingError) Error

type ForceLogLevelHook

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

ForceLogLevelHook is a log hook which can change log level for messages which contains specific substrings

func NewForceLogLevelHook

func NewForceLogLevelHook(forcedLevel log.Level) *ForceLogLevelHook

NewForceLogLevelHook creates default log reduction hook

func (*ForceLogLevelHook) Fire

func (hook *ForceLogLevelHook) Fire(entry *logrus.Entry) error

Fire implements logrus.Hook.Fire()

func (*ForceLogLevelHook) Levels

func (hook *ForceLogLevelHook) Levels() []logrus.Level

Levels implements logrus.Hook.Levels()

type InfiniteRecursionError

type InfiniteRecursionError struct {
	Units          map[string]*Unit
	RecursionLevel int
}

func (InfiniteRecursionError) Error

func (err InfiniteRecursionError) Error() string

type LogEntriesDropperFormatter

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

LogEntriesDropperFormatter is a custom formatter which will ignore log entries which has lower level than preconfigured in logger

func (*LogEntriesDropperFormatter) Format

func (formatter *LogEntriesDropperFormatter) Format(entry *logrus.Entry) ([]byte, error)

Format implements logrus.Formatter

type Option

type Option func(StackRunner)

Option is a function that modifies a Stack.

func WithChildTerragruntConfig

func WithChildTerragruntConfig(config *config.TerragruntConfig) Option

WithChildTerragruntConfig sets the TerragruntConfig on any Stack implementation.

func WithParseOptions

func WithParseOptions(parserOptions []hclparse.Option) Option

WithParseOptions sets the parserOptions on any Stack implementation.

func WithReport

func WithReport(report *report.Report) Option

type ProcessingUnitDependencyError

type ProcessingUnitDependencyError struct {
	Unit       *Unit
	Dependency *Unit
	Err        error
}

func (ProcessingUnitDependencyError) Error

func (ProcessingUnitDependencyError) ExitStatus

func (err ProcessingUnitDependencyError) ExitStatus() (int, error)

func (ProcessingUnitDependencyError) Unwrap

func (err ProcessingUnitDependencyError) Unwrap() error

type ProcessingUnitError

type ProcessingUnitError struct {
	UnderlyingError     error
	UnitPath            string
	HowThisUnitWasFound string
}

func (ProcessingUnitError) Error

func (err ProcessingUnitError) Error() string

func (ProcessingUnitError) Unwrap

func (err ProcessingUnitError) Unwrap() error

type Stack

type Stack struct {
	Report                *report.Report
	TerragruntOptions     *options.TerragruntOptions
	ChildTerragruntConfig *config.TerragruntConfig
	Units                 Units
	ParserOptions         []hclparse.Option
}

Stack represents a stack of units that you can "spin up" or "spin down"

func (*Stack) FindUnitByPath

func (stack *Stack) FindUnitByPath(path string) *Unit

FindUnitByPath finds a unit in the stack by its path

func (*Stack) String

func (stack *Stack) String() string

String renders this stack as a human-readable string

type StackRunner

type StackRunner interface {
	// Run - Execute all units in the stack according to the specified Terraform command and options.
	Run(ctx context.Context, l log.Logger, opts *options.TerragruntOptions) error
	// LogUnitDeployOrder Log the order in which units will be deployed for the given Terraform command.
	LogUnitDeployOrder(l log.Logger, terraformCommand string) error
	// JSONUnitDeployOrder Return the deployment order of units as a JSON string for the specified Terraform command.
	JSONUnitDeployOrder(terraformCommand string) (string, error)
	// ListStackDependentUnits Build and return a map of each unit to the list of units that depend on it.
	ListStackDependentUnits() map[string][]string
	// GetStack Retrieve the underlying Stack object managed by this runner.
	GetStack() *Stack
	// SetTerragruntConfig Set the child Terragrunt configuration for the stack.
	SetTerragruntConfig(config *config.TerragruntConfig)
	// SetParseOptions Set the parser options used for HCL parsing in the stack.
	SetParseOptions(parserOptions []hclparse.Option)
	// SetReport Attach a report object to the stack for collecting run data and summaries.
	SetReport(report *report.Report)
}

StackRunner is the abstraction for running stack of units.

type Unit

type Unit struct {
	TerragruntOptions    *options.TerragruntOptions
	Logger               log.Logger
	Path                 string
	Dependencies         Units
	Config               config.TerragruntConfig
	AssumeAlreadyApplied bool
	FlagExcluded         bool
}

Unit represents a single module (i.e. folder with Terraform templates), including the Terragrunt configuration for that module and the list of other modules that this module depends on

func (*Unit) FindUnitInPath

func (unit *Unit) FindUnitInPath(targetDirs []string) bool

FindUnitInPath returns true if a unit is located under one of the target directories

func (*Unit) FlushOutput

func (unit *Unit) FlushOutput() error

FlushOutput flushes buffer data to the output writer.

func (*Unit) OutputFile

func (unit *Unit) OutputFile(l log.Logger, opts *options.TerragruntOptions) string

OutputFile - return plan file location, if output folder is set

func (*Unit) OutputJSONFile

func (unit *Unit) OutputJSONFile(l log.Logger, opts *options.TerragruntOptions) string

OutputJSONFile - return plan JSON file location, if JSON output folder is set

func (*Unit) PlanFile

func (unit *Unit) PlanFile(l log.Logger, opts *options.TerragruntOptions) string

PlanFile - return plan file location, if output folder is set

func (*Unit) String

func (unit *Unit) String() string

String renders this unit as a human-readable string

type UnitRunner

type UnitRunner struct {
	Err    error
	Unit   *Unit
	Status UnitStatus
}

UnitRunner handles the logic for running a single unit.

func NewUnitRunner

func NewUnitRunner(unit *Unit) *UnitRunner

func (*UnitRunner) Run

func (runner *UnitRunner) Run(ctx context.Context, opts *options.TerragruntOptions, r *report.Report) error

Run a unit right now by executing the runTerragrunt command of its TerragruntOptions field.

type UnitStatus

type UnitStatus int

UnitStatus represents the status of a unit that we are trying to apply or destroy as part of the run --all apply or run --all destroy command

const (
	Waiting UnitStatus = iota
	Running
	Finished
)

type UnitWriter

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

UnitWriter represents a Writer with data buffering. We should avoid outputting data directly to the output out, since when units run in parallel, the output data may be mixed with each other, thereby spoiling each other's results.

func NewUnitWriter

func NewUnitWriter(out io.Writer) *UnitWriter

NewUnitWriter returns a new UnitWriter instance.

func (*UnitWriter) Flush

func (writer *UnitWriter) Flush() error

Flush flushes buffer data to the `out` writer.

func (*UnitWriter) Write

func (writer *UnitWriter) Write(p []byte) (int, error)

Write appends the contents of p to the buffer.

type Units

type Units []*Unit

func (Units) CheckForCycles

func (units Units) CheckForCycles() error

CheckForCycles checks for dependency cycles in the given list of units and return an error if one is found.

func (Units) WriteDot

func (units Units) WriteDot(l log.Logger, w io.Writer, opts *options.TerragruntOptions) error

WriteDot is used to emit a GraphViz compatible definition for a directed graph. It can be used to dump a .dot file. This is a similar implementation to terraform's digraph https://github.com/hashicorp/terraform/blob/v1.5.7/internal/dag/dag.go adding some styling to units that are excluded from the execution in *-all commands

type UnitsMap

type UnitsMap map[string]*Unit

func (UnitsMap) CrossLinkDependencies

func (unitsMap UnitsMap) CrossLinkDependencies(canonicalTerragruntConfigPaths []string) (Units, error)

CrossLinkDependencies Go through each unit in the given map and cross-link its dependencies to the other units in that same map. If a dependency is referenced that is not in the given map, return an error.

func (UnitsMap) FindByPath

func (unitsMap UnitsMap) FindByPath(path string) *Unit

FindByPath returns the unit that matches the given path, or nil if no such unit exists in the map.

func (UnitsMap) MergeMaps

func (unitsMap UnitsMap) MergeMaps(externalDependencies UnitsMap) UnitsMap

MergeMaps the given external dependencies into the given map of units if those dependencies aren't already in the units map

func (UnitsMap) SortedKeys

func (unitsMap UnitsMap) SortedKeys() []string

SortedKeys Return the keys for the given map in sorted order. This is used to ensure we always iterate over maps of units in a consistent order (Go does not guarantee iteration order for maps, and usually makes it random)

type UnrecognizedDependencyError

type UnrecognizedDependencyError struct {
	UnitPath              string
	DependencyPath        string
	TerragruntConfigPaths []string
}

func (UnrecognizedDependencyError) Error

func (err UnrecognizedDependencyError) Error() string

Jump to

Keyboard shortcuts

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