Documentation
¶
Overview ¶
Package component provides types for representing discovered Terragrunt components.
These include units and stacks.
This package contains only data types and their associated methods, with no discovery logic. It exists separately from the discovery package to allow other packages (like filter) to depend on these types without creating circular dependencies.
Index ¶
- func FlushOutput(u *Unit) error
- type Component
- type Components
- type DiscoveryContext
- type Kind
- type Origin
- type Stack
- func (s *Stack) AddDependency(dependency Component)
- func (s *Stack) AddDependent(dependent Component)
- func (s *Stack) Config() *config.StackConfig
- func (s *Stack) Dependencies() Components
- func (s *Stack) Dependents() Components
- func (s *Stack) DiscoveryContext() *DiscoveryContext
- func (s *Stack) DisplayPath() string
- func (s *Stack) External() bool
- func (s *Stack) FindUnitByPath(path string) *Unit
- func (s *Stack) Kind() Kind
- func (s *Stack) Origin() Origin
- func (s *Stack) Path() string
- func (s *Stack) Reading() []string
- func (s *Stack) SetDiscoveryContext(ctx *DiscoveryContext)
- func (s *Stack) SetExternal()
- func (s *Stack) SetPath(path string)
- func (s *Stack) SetReading(files ...string)
- func (s *Stack) Sources() []string
- func (s *Stack) StoreConfig(cfg *config.StackConfig)
- func (s *Stack) String() string
- func (s *Stack) WithDiscoveryContext(ctx *DiscoveryContext) *Stack
- type StackExecution
- type ThreadSafeComponents
- type Unit
- func (u *Unit) AbsolutePath() string
- func (u *Unit) AddDependency(dependency Component)
- func (u *Unit) AddDependent(dependent Component)
- func (u *Unit) Config() *config.TerragruntConfig
- func (u *Unit) ConfigFile() string
- func (u *Unit) Dependencies() Components
- func (u *Unit) Dependents() Components
- func (u *Unit) DiscoveryContext() *DiscoveryContext
- func (u *Unit) DisplayPath() string
- func (u *Unit) Excluded() bool
- func (u *Unit) External() bool
- func (u *Unit) FindInPaths(targetDirs []string) bool
- func (u *Unit) Kind() Kind
- func (u *Unit) Origin() Origin
- func (u *Unit) OutputFile(opts *options.TerragruntOptions) string
- func (u *Unit) OutputJSONFile(opts *options.TerragruntOptions) string
- func (u *Unit) Path() string
- func (u *Unit) PlanFile(opts *options.TerragruntOptions) string
- func (u *Unit) Reading() []string
- func (u *Unit) SetConfigFile(filename string)
- func (u *Unit) SetDiscoveryContext(ctx *DiscoveryContext)
- func (u *Unit) SetExcluded(excluded bool)
- func (u *Unit) SetExternal()
- func (u *Unit) SetPath(path string)
- func (u *Unit) SetReading(files ...string)
- func (u *Unit) Sources() []string
- func (u *Unit) StoreConfig(cfg *config.TerragruntConfig)
- func (u *Unit) String() string
- func (u *Unit) WithConfig(cfg *config.TerragruntConfig) *Unit
- func (u *Unit) WithDiscoveryContext(ctx *DiscoveryContext) *Unit
- func (u *Unit) WithReading(files ...string) *Unit
- type UnitExecution
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FlushOutput ¶ added in v0.94.0
FlushOutput flushes buffer data to the output writer for this unit, if the writer supports it. This is safe to call even if Execution or the Writer is nil.
Types ¶
type Component ¶
type Component interface {
Kind() Kind
Path() string
SetPath(string)
DisplayPath() string
External() bool
SetExternal()
Reading() []string
SetReading(...string)
Sources() []string
DiscoveryContext() *DiscoveryContext
SetDiscoveryContext(*DiscoveryContext)
Origin() Origin
AddDependency(Component)
AddDependent(Component)
Dependencies() Components
Dependents() Components
// contains filtered or unexported methods
}
Component represents a discovered Terragrunt configuration. This interface is implemented by Unit and Stack.
type Components ¶
type Components []Component
Components is a list of discovered Terragrunt components.
func (Components) CycleCheck ¶
func (c Components) CycleCheck() (Component, error)
CycleCheck checks for cycles in the dependency graph. If a cycle is detected, it returns the first Component that is part of the cycle, and an error. If no cycle is detected, it returns nil and nil.
func (Components) Filter ¶
func (c Components) Filter(kind Kind) Components
Filter filters the Components by config type.
func (Components) FilterByPath ¶
func (c Components) FilterByPath(path string) Components
FilterByPath filters the Components by path.
func (Components) Paths ¶
func (c Components) Paths() []string
Paths returns the paths of the Components.
func (Components) RemoveByPath ¶
func (c Components) RemoveByPath(path string) Components
RemoveByPath removes the Component with the given path from the Components.
type DiscoveryContext ¶
type DiscoveryContext struct {
WorkingDir string
Ref string
Cmd string
Args []string
// contains filtered or unexported fields
}
DiscoveryContext is the context in which a Component was discovered.
It's useful to know this information, because it can help us determine how the Component should be run or enqueued later.
func (*DiscoveryContext) Copy ¶ added in v0.98.0
func (dc *DiscoveryContext) Copy() *DiscoveryContext
Copy returns a copy of the DiscoveryContext.
func (*DiscoveryContext) CopyWithNewOrigin ¶ added in v0.98.0
func (dc *DiscoveryContext) CopyWithNewOrigin(origin Origin) *DiscoveryContext
CopyWithNewOrigin returns a copy of the DiscoveryContext with the origin set to the given origin.
Discovered components should never have their origin overridden by subsequent phases of discovery. Only use this method if you are discovering a new component that was originally discovered by a different discovery phase.
e.g. A component discovered as a dependency/dependent of a component discovered via Git discovery should be considered discovered via graph discovery, not Git discovery.
func (*DiscoveryContext) Origin ¶ added in v0.98.0
func (dc *DiscoveryContext) Origin() Origin
Origin returns the origin of the DiscoveryContext.
func (*DiscoveryContext) SuggestOrigin ¶ added in v0.98.0
func (dc *DiscoveryContext) SuggestOrigin(origin Origin)
SuggestOrigin suggests an origin for the DiscoveryContext.
Only actually updates the origin if it is empty. This is to ensure that the origin of a component is always considered the first origin discovered for that component, and that it can't be overridden by subsequent phases of discovery that might re-discover the same component.
type Kind ¶
type Kind string
Kind is the type of Terragrunt component.
const (
StackKind Kind = "stack"
)
const (
UnitKind Kind = "unit"
)
type Origin ¶ added in v0.98.0
type Origin string
Origin determines the discovery origin of a component. This is important if there are multiple different reasons that a component might have been discovered.
e.g. A component might be discovered in a Git worktree due to graph discovery from the results of a Git-based filter.
type Stack ¶
type Stack struct {
Execution *StackExecution
Units []*Unit
// contains filtered or unexported fields
}
Stack represents a discovered Terragrunt stack configuration.
func (*Stack) AddDependency ¶ added in v0.92.1
AddDependency adds a dependency to the Stack and vice versa.
Using this method ensure that the dependency graph is properly maintained, making it easier to look up dependents and dependencies on a given component without the entire graph available.
func (*Stack) AddDependent ¶ added in v0.92.1
AddDependent adds a dependent to the Stack and vice versa.
Using this method ensure that the dependency graph is properly maintained, making it easier to look up dependents and dependencies on a given component without the entire graph available.
func (*Stack) Config ¶ added in v0.92.1
func (s *Stack) Config() *config.StackConfig
Config returns the parsed Stack configuration for this stack.
func (*Stack) Dependencies ¶ added in v0.92.1
func (s *Stack) Dependencies() Components
Dependencies returns the dependencies of the Stack.
func (*Stack) Dependents ¶ added in v0.92.1
func (s *Stack) Dependents() Components
Dependents returns the dependents of the Stack.
func (*Stack) DiscoveryContext ¶ added in v0.92.1
func (s *Stack) DiscoveryContext() *DiscoveryContext
DiscoveryContext returns the discovery context for this component.
func (*Stack) DisplayPath ¶ added in v0.95.0
DisplayPath returns the path relative to DiscoveryContext.WorkingDir for display purposes. Falls back to the original path if relative path calculation fails or WorkingDir is empty.
func (*Stack) FindUnitByPath ¶ added in v0.94.0
FindUnitByPath finds a unit in the stack by its path.
func (*Stack) Origin ¶ added in v0.98.0
Origin returns the origin of the discovery context for this component.
func (*Stack) Reading ¶ added in v0.92.1
Reading returns the list of files being read by this component.
func (*Stack) SetDiscoveryContext ¶ added in v0.92.1
func (s *Stack) SetDiscoveryContext(ctx *DiscoveryContext)
SetDiscoveryContext sets the discovery context for this component.
func (*Stack) SetExternal ¶ added in v0.92.1
func (s *Stack) SetExternal()
SetExternal marks the component as external.
func (*Stack) SetReading ¶ added in v0.92.1
SetReading sets the list of files being read by this component.
func (*Stack) Sources ¶ added in v0.93.6
Sources returns the list of sources for this component.
Stacks don't support leveraging sources right now, so we just return an empty list.
func (*Stack) StoreConfig ¶ added in v0.92.1
func (s *Stack) StoreConfig(cfg *config.StackConfig)
StoreConfig stores the parsed Stack configuration for this stack.
func (*Stack) String ¶ added in v0.94.0
String renders this stack as a human-readable string.
Example output:
Stack at /path/to/stack: => Unit /path/to/unit1 (excluded: false, assume applied: false, dependencies: [/dep1]) => Unit /path/to/unit2 (excluded: true, assume applied: false, dependencies: [])
func (*Stack) WithDiscoveryContext ¶ added in v0.95.0
func (s *Stack) WithDiscoveryContext(ctx *DiscoveryContext) *Stack
WithDiscoveryContext sets the discovery context for this stack.
type StackExecution ¶ added in v0.94.0
type StackExecution struct {
Report *report.Report
TerragruntOptions *options.TerragruntOptions
}
StackExecution holds execution-specific fields for running a stack. This is nil during discovery phase and populated when preparing for execution.
type ThreadSafeComponents ¶ added in v0.93.4
type ThreadSafeComponents struct {
// contains filtered or unexported fields
}
ThreadSafeComponents provides thread-safe access to a Components slice. It uses an RWMutex to allow concurrent reads and serialized writes. Resolved paths are cached to avoid repeated filepath.EvalSymlinks syscalls and ensure consistent symlink-aware comparisons across all methods.
func NewThreadSafeComponents ¶ added in v0.93.4
func NewThreadSafeComponents(components Components) *ThreadSafeComponents
NewThreadSafeComponents creates a new ThreadSafeComponents instance with the given components.
func (*ThreadSafeComponents) EnsureComponent ¶ added in v0.93.4
func (tsc *ThreadSafeComponents) EnsureComponent(c Component) (Component, bool)
EnsureComponent adds a component to the components list if it's not already present. This method is TOCTOU-safe (Time-Of-Check-Time-Of-Use) by using a double-check pattern. Path comparison uses resolved symlink paths for consistency.
It returns the component if it was added, and a boolean indicating if it was added.
func (*ThreadSafeComponents) FindByPath ¶ added in v0.93.4
func (tsc *ThreadSafeComponents) FindByPath(path string) Component
FindByPath searches for a component by its path and returns it if found, otherwise returns nil. Paths are resolved to handle symlinks consistently across platforms (e.g., macOS /var -> /private/var). Uses cached resolved paths to avoid repeated syscalls.
func (*ThreadSafeComponents) Len ¶ added in v0.93.4
func (tsc *ThreadSafeComponents) Len() int
Len returns the number of components in the components slice.
func (*ThreadSafeComponents) ToComponents ¶ added in v0.93.4
func (tsc *ThreadSafeComponents) ToComponents() Components
ToComponents returns a copy of the components slice.
type Unit ¶
type Unit struct {
Execution *UnitExecution
// contains filtered or unexported fields
}
Unit represents a discovered Terragrunt unit configuration.
func (*Unit) AbsolutePath ¶ added in v0.94.0
AbsolutePath returns the absolute path of the unit. If path conversion fails, returns the original path and logs a warning if a logger is available.
func (*Unit) AddDependency ¶ added in v0.92.1
AddDependency adds a dependency to the Unit and vice versa.
Using this method ensure that the dependency graph is properly maintained, making it easier to look up dependents and dependencies on a given component without the entire graph available.
func (*Unit) AddDependent ¶ added in v0.92.1
AddDependent adds a dependent to the Unit and vice versa.
Using this method ensure that the dependency graph is properly maintained, making it easier to look up dependents and dependencies on a given component without the entire graph available.
func (*Unit) Config ¶ added in v0.92.1
func (u *Unit) Config() *config.TerragruntConfig
Config returns the parsed Terragrunt configuration for this unit.
func (*Unit) ConfigFile ¶ added in v0.97.0
ConfigFile returns the discovered config filename for this unit.
func (*Unit) Dependencies ¶ added in v0.92.1
func (u *Unit) Dependencies() Components
Dependencies returns the dependencies of the Unit.
func (*Unit) Dependents ¶ added in v0.92.1
func (u *Unit) Dependents() Components
Dependents returns the dependents of the Unit.
func (*Unit) DiscoveryContext ¶ added in v0.92.1
func (u *Unit) DiscoveryContext() *DiscoveryContext
DiscoveryContext returns the discovery context for this component.
func (*Unit) DisplayPath ¶ added in v0.95.0
DisplayPath returns the path relative to DiscoveryContext.WorkingDir for display purposes. Falls back to the original path if relative path calculation fails or WorkingDir is empty.
func (*Unit) Excluded ¶ added in v0.94.0
Excluded returns whether the unit was excluded during discovery/filtering.
func (*Unit) FindInPaths ¶ added in v0.94.0
FindInPaths returns true if the unit is located in one of the target directories. Paths are normalized before comparison to handle absolute/relative path mismatches.
func (*Unit) Origin ¶ added in v0.98.0
Origin returns the origin of the discovery context for this component.
func (*Unit) OutputFile ¶ added in v0.94.0
func (u *Unit) OutputFile(opts *options.TerragruntOptions) string
OutputFile returns plan file location if output folder is set.
func (*Unit) OutputJSONFile ¶ added in v0.94.0
func (u *Unit) OutputJSONFile(opts *options.TerragruntOptions) string
OutputJSONFile returns plan JSON file location if JSON output folder is set.
func (*Unit) PlanFile ¶ added in v0.94.0
func (u *Unit) PlanFile(opts *options.TerragruntOptions) string
PlanFile returns plan file location if output folder is set. Requires Execution to be populated.
func (*Unit) Reading ¶ added in v0.92.1
Reading returns the list of files being read by this component.
func (*Unit) SetConfigFile ¶ added in v0.97.0
SetConfigFile sets the discovered config filename for this unit.
func (*Unit) SetDiscoveryContext ¶ added in v0.92.1
func (u *Unit) SetDiscoveryContext(ctx *DiscoveryContext)
SetDiscoveryContext sets the discovery context for this component.
func (*Unit) SetExcluded ¶ added in v0.94.0
SetExcluded marks the unit as excluded during discovery/filtering.
func (*Unit) SetExternal ¶ added in v0.92.1
func (u *Unit) SetExternal()
SetExternal marks the component as external.
func (*Unit) SetReading ¶ added in v0.92.1
SetReading sets the list of files being read by this component.
func (*Unit) StoreConfig ¶ added in v0.92.1
func (u *Unit) StoreConfig(cfg *config.TerragruntConfig)
StoreConfig stores the parsed Terragrunt configuration for this unit.
func (*Unit) String ¶ added in v0.94.0
String renders this unit as a human-readable string for debugging.
Example output:
Unit /path/to/unit (excluded: false, assume applied: false, dependencies: [/dep1, /dep2])
func (*Unit) WithConfig ¶ added in v0.92.1
func (u *Unit) WithConfig(cfg *config.TerragruntConfig) *Unit
WithConfig adds configuration to a Unit component.
func (*Unit) WithDiscoveryContext ¶ added in v0.95.0
func (u *Unit) WithDiscoveryContext(ctx *DiscoveryContext) *Unit
WithDiscoveryContext sets the discovery context for this unit.
func (*Unit) WithReading ¶ added in v0.92.1
WithReading appends a file to the list of files being read by this component. Useful for constructing components with all files read at once.
type UnitExecution ¶ added in v0.94.0
type UnitExecution struct {
TerragruntOptions *options.TerragruntOptions
Logger log.Logger
FlagExcluded bool
AssumeAlreadyApplied bool
}
UnitExecution holds execution-specific fields for running a unit. This is nil during discovery phase and populated when preparing for execution.
func NewUnitExecution ¶ added in v0.99.0
func NewUnitExecution(l log.Logger, opts *options.TerragruntOptions, excluded bool) *UnitExecution
NewUnitExecution creates a new UnitExecution with the given options.