configstack

package
v0.82.4 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2025 License: MIT Imports: 33 Imported by: 0

Documentation

Overview

Package configstack contains the logic for managing a stack of Terraform modules (i.e. folders with Terraform templates) that you can "spin up" or "spin down" in a single command.

Index

Constants

This section is empty.

Variables

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

Functions

This section is empty.

Types

type DefaultStack added in v0.81.1

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

DefaultStack implements the Stack interface and represents a stack of Terraform modules (i.e. folders with Terraform templates) that you can "spin up" or "spin down" in a single command (formerly Stack)

func NewDefaultStack added in v0.81.1

func NewDefaultStack(l log.Logger, terragruntOptions *options.TerragruntOptions, opts ...Option) *DefaultStack

NewDefaultStack creates a new DefaultStack.

func (*DefaultStack) FindModuleByPath added in v0.81.1

func (stack *DefaultStack) FindModuleByPath(path string) *TerraformModule

FindModuleByPath finds a module by its path.

func (*DefaultStack) GetModuleRunGraph added in v0.81.1

func (stack *DefaultStack) GetModuleRunGraph(terraformCommand string) ([]TerraformModules, error)

GetModuleRunGraph converts the module list to a graph that shows the order in which the modules will be applied/destroyed. The return structure is a list of lists, where the nested list represents modules that can be deployed concurrently, and the outer list indicates the order. This will only include those modules that do NOT have the exclude flag set.

func (*DefaultStack) GetParseOptions added in v0.81.1

func (stack *DefaultStack) GetParseOptions() []hclparse.Option

GetParseOptions returns the parser options for the stack.

func (*DefaultStack) GetReport added in v0.81.1

func (stack *DefaultStack) GetReport() *report.Report

GetReport returns the report for the stack.

func (*DefaultStack) GetTerragruntConfig added in v0.81.1

func (stack *DefaultStack) GetTerragruntConfig() *config.TerragruntConfig

GetTerragruntConfig returns the child Terragrunt config for the stack.

func (*DefaultStack) Graph added in v0.81.1

func (stack *DefaultStack) Graph(l log.Logger, opts *options.TerragruntOptions)

Graph creates a graphviz representation of the modules

func (*DefaultStack) JSONModuleDeployOrder added in v0.81.1

func (stack *DefaultStack) JSONModuleDeployOrder(terraformCommand string) (string, error)

JSONModuleDeployOrder will return the modules that will be deployed by a plan/apply operation, in the order that the operations happen.

func (*DefaultStack) ListStackDependentModules added in v0.81.1

func (stack *DefaultStack) ListStackDependentModules() map[string][]string

ListStackDependentModules - build a map with each module and its dependent modules

func (*DefaultStack) Lock added in v0.81.1

func (stack *DefaultStack) Lock()

Lock locks the stack for concurrency control.

func (*DefaultStack) LogModuleDeployOrder added in v0.81.1

func (stack *DefaultStack) LogModuleDeployOrder(l log.Logger, terraformCommand string) error

LogModuleDeployOrder will log the modules that will be deployed by this operation, in the order that the operations happen. For plan and apply, the order will be bottom to top (dependencies first), while for destroy the order will be in reverse.

func (*DefaultStack) Modules added in v0.81.1

func (stack *DefaultStack) Modules() TerraformModules

Modules returns the Terraform modules in the stack.

func (*DefaultStack) ResolveTerraformModules added in v0.81.1

func (stack *DefaultStack) ResolveTerraformModules(ctx context.Context, l log.Logger, terragruntConfigPaths []string) (TerraformModules, error)

ResolveTerraformModules goes through each of the given Terragrunt configuration files and resolve the module that configuration file represents into a TerraformModule struct. Return the list of these TerraformModule structs.

func (*DefaultStack) Run added in v0.81.1

func (*DefaultStack) SetModules added in v0.81.1

func (stack *DefaultStack) SetModules(modules TerraformModules)

SetModules sets the Terraform modules for the stack.

func (*DefaultStack) SetParseOptions added in v0.81.1

func (stack *DefaultStack) SetParseOptions(parserOptions []hclparse.Option)

SetParseOptions sets the parser options for the stack.

func (*DefaultStack) SetReport added in v0.81.1

func (stack *DefaultStack) SetReport(report *report.Report)

SetReport sets the report for the stack.

func (*DefaultStack) SetTerragruntConfig added in v0.81.1

func (stack *DefaultStack) SetTerragruntConfig(config *config.TerragruntConfig)

SetTerragruntConfig sets the child Terragrunt config for the stack.

func (*DefaultStack) String added in v0.81.1

func (stack *DefaultStack) String() string

String renders this stack as a human-readable string

func (*DefaultStack) Unlock added in v0.81.1

func (stack *DefaultStack) Unlock()

Unlock unlocks the stack for concurrency control.

func (*DefaultStack) WithOptions added in v0.81.1

func (stack *DefaultStack) WithOptions(opts ...Option) *DefaultStack

WithOptions updates the stack with the provided options.

type DefaultStackBuilder added in v0.81.1

type DefaultStackBuilder struct{}

DefaultStackBuilder implements StackBuilder for DefaultStack

func (*DefaultStackBuilder) BuildStack added in v0.81.1

func (b *DefaultStackBuilder) BuildStack(ctx context.Context, l log.Logger, terragruntOptions *options.TerragruntOptions, opts ...Option) (Stack, error)

BuildStack builds a new DefaultStack.

type DependencyCycleError added in v0.61.0

type DependencyCycleError []string

func (DependencyCycleError) Error added in v0.61.0

func (err DependencyCycleError) Error() string

type DependencyNotFoundWhileCrossLinkingError added in v0.61.0

type DependencyNotFoundWhileCrossLinkingError struct {
	Module     *RunningModule
	Dependency *TerraformModule
}

func (DependencyNotFoundWhileCrossLinkingError) Error added in v0.61.0

type DependencyOrder

type DependencyOrder int

DependencyOrder controls in what order dependencies should be enforced between modules.

const (
	NormalOrder DependencyOrder = iota
	ReverseOrder
	IgnoreOrder
)

type ForceLogLevelHook added in v0.35.5

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 added in v0.35.5

func NewForceLogLevelHook(forcedLevel log.Level) *ForceLogLevelHook

NewForceLogLevelHook creates default log reduction hook

func (*ForceLogLevelHook) Fire added in v0.35.5

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

Fire implements logrus.Hook.Fire()

func (*ForceLogLevelHook) Levels added in v0.35.5

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

Levels implements logrus.Hook.Levels()

type InfiniteRecursionError added in v0.61.0

type InfiniteRecursionError struct {
	Modules        map[string]*TerraformModule
	RecursionLevel int
}

func (InfiniteRecursionError) Error added in v0.61.0

func (err InfiniteRecursionError) Error() string

type LogEntriesDropperFormatter added in v0.35.5

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 added in v0.35.5

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

Format implements logrus.Formatter

type ModuleStatus

type ModuleStatus int

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

const (
	Waiting ModuleStatus = iota
	Running
	Finished
)

type ModuleWriter added in v0.68.2

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

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

func NewModuleWriter added in v0.68.2

func NewModuleWriter(out io.Writer) *ModuleWriter

NewModuleWriter returns a new ModuleWriter instance.

func (*ModuleWriter) Flush added in v0.68.2

func (writer *ModuleWriter) Flush() error

Flush flushes buffer data to the `out` writer.

func (*ModuleWriter) Write added in v0.68.2

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

Write appends the contents of p to the buffer.

type Option added in v0.61.0

type Option func(Stack)

Option is a function that modifies a Stack.

func WithChildTerragruntConfig added in v0.61.0

func WithChildTerragruntConfig(config *config.TerragruntConfig) Option

WithChildTerragruntConfig sets the TerragruntConfig on any Stack implementation.

func WithParseOptions added in v0.61.0

func WithParseOptions(parserOptions []hclparse.Option) Option

WithParseOptions sets the parserOptions on any Stack implementation.

func WithReport added in v0.81.1

func WithReport(report *report.Report) Option

type ProcessingModuleDependencyError added in v0.61.0

type ProcessingModuleDependencyError struct {
	Module     *TerraformModule
	Dependency *TerraformModule
	Err        error
}

func (ProcessingModuleDependencyError) Error added in v0.61.0

func (ProcessingModuleDependencyError) ExitStatus added in v0.61.0

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

func (ProcessingModuleDependencyError) Unwrap added in v0.61.0

type ProcessingModuleError added in v0.61.0

type ProcessingModuleError struct {
	UnderlyingError       error
	ModulePath            string
	HowThisModuleWasFound string
}

func (ProcessingModuleError) Error added in v0.61.0

func (err ProcessingModuleError) Error() string

func (ProcessingModuleError) Unwrap added in v0.61.0

func (err ProcessingModuleError) Unwrap() error

type RunnerPoolStack added in v0.81.6

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

RunnerPoolStack implements the Stack interface for runner pool execution.

func NewRunnerPoolStack added in v0.81.6

func NewRunnerPoolStack(ctx context.Context, l log.Logger, terragruntOptions *options.TerragruntOptions, discovered discovery.DiscoveredConfigs) (*RunnerPoolStack, error)

NewRunnerPoolStack creates a new stack from discovered modules.

func (*RunnerPoolStack) FindModuleByPath added in v0.81.6

func (stack *RunnerPoolStack) FindModuleByPath(path string) *TerraformModule

func (*RunnerPoolStack) GetModuleRunGraph added in v0.81.6

func (stack *RunnerPoolStack) GetModuleRunGraph(terraformCommand string) ([]TerraformModules, error)

func (*RunnerPoolStack) GetParseOptions added in v0.81.6

func (stack *RunnerPoolStack) GetParseOptions() []hclparse.Option

func (*RunnerPoolStack) GetReport added in v0.81.6

func (stack *RunnerPoolStack) GetReport() *report.Report

func (*RunnerPoolStack) GetTerragruntConfig added in v0.81.6

func (stack *RunnerPoolStack) GetTerragruntConfig() *config.TerragruntConfig

func (*RunnerPoolStack) Graph added in v0.81.6

func (stack *RunnerPoolStack) Graph(l log.Logger, opts *options.TerragruntOptions)

func (*RunnerPoolStack) JSONModuleDeployOrder added in v0.81.6

func (stack *RunnerPoolStack) JSONModuleDeployOrder(terraformCommand string) (string, error)

func (*RunnerPoolStack) ListStackDependentModules added in v0.81.6

func (stack *RunnerPoolStack) ListStackDependentModules() map[string][]string

func (*RunnerPoolStack) Lock added in v0.81.6

func (stack *RunnerPoolStack) Lock()

func (*RunnerPoolStack) LogModuleDeployOrder added in v0.81.6

func (stack *RunnerPoolStack) LogModuleDeployOrder(l log.Logger, terraformCommand string) error

func (*RunnerPoolStack) Modules added in v0.81.6

func (stack *RunnerPoolStack) Modules() TerraformModules

func (*RunnerPoolStack) Run added in v0.81.6

func (*RunnerPoolStack) SetModules added in v0.81.6

func (stack *RunnerPoolStack) SetModules(modules TerraformModules)

func (*RunnerPoolStack) SetParseOptions added in v0.81.6

func (stack *RunnerPoolStack) SetParseOptions(parserOptions []hclparse.Option)

func (*RunnerPoolStack) SetReport added in v0.81.6

func (stack *RunnerPoolStack) SetReport(report *report.Report)

func (*RunnerPoolStack) SetTerragruntConfig added in v0.81.6

func (stack *RunnerPoolStack) SetTerragruntConfig(config *config.TerragruntConfig)

func (*RunnerPoolStack) String added in v0.81.6

func (stack *RunnerPoolStack) String() string

func (*RunnerPoolStack) Unlock added in v0.81.6

func (stack *RunnerPoolStack) Unlock()

type RunnerPoolStackBuilder added in v0.81.6

type RunnerPoolStackBuilder struct {
}

RunnerPoolStackBuilder implements StackBuilder for RunnerPoolStack It uses the discovery package to find modules and build the stack.

func NewRunnerPoolStackBuilder added in v0.81.6

func NewRunnerPoolStackBuilder() *RunnerPoolStackBuilder

NewRunnerPoolStackBuilder creates a new builder with the given discovery instance.

func (*RunnerPoolStackBuilder) BuildStack added in v0.81.6

func (b *RunnerPoolStackBuilder) BuildStack(ctx context.Context, l log.Logger, terragruntOptions *options.TerragruntOptions, opts ...Option) (Stack, error)

BuildStack discovers modules and builds a new DefaultStack, returning it as a Stack interface.

type RunningModule added in v0.66.7

type RunningModule struct {
	Err            error
	Module         *TerraformModule
	Logger         log.Logger
	DependencyDone chan *RunningModule
	Dependencies   map[string]*RunningModule
	NotifyWhenDone []*RunningModule
	Status         ModuleStatus
	FlagExcluded   bool
}

RunningModule represents a module we are trying to "run" (i.e. apply or destroy) as part of the run --all apply or run --all destroy command.

type RunningModules added in v0.66.7

type RunningModules map[string]*RunningModule

func (RunningModules) RemoveFlagExcluded added in v0.66.7

func (modules RunningModules) RemoveFlagExcluded(r *report.Report, reportExperiment bool) (RunningModules, error)

RemoveFlagExcluded returns a cleaned-up map that only contains modules and dependencies that should not be excluded

type Stack

type Stack interface {
	String() string
	LogModuleDeployOrder(l log.Logger, terraformCommand string) error
	JSONModuleDeployOrder(terraformCommand string) (string, error)
	Graph(l log.Logger, opts *options.TerragruntOptions)
	Run(ctx context.Context, l log.Logger, opts *options.TerragruntOptions) error
	GetModuleRunGraph(terraformCommand string) ([]TerraformModules, error)
	ListStackDependentModules() map[string][]string
	Modules() TerraformModules
	FindModuleByPath(path string) *TerraformModule
	SetTerragruntConfig(config *config.TerragruntConfig)
	GetTerragruntConfig() *config.TerragruntConfig
	SetParseOptions(parserOptions []hclparse.Option)
	GetParseOptions() []hclparse.Option
	SetReport(report *report.Report)
	GetReport() *report.Report
	Lock()
	Unlock()
}

Stack is the abstraction for a stack of Terraform modules.

func FindStackInSubfolders

func FindStackInSubfolders(ctx context.Context, l log.Logger, terragruntOptions *options.TerragruntOptions, opts ...Option) (Stack, error)

FindStackInSubfolders finds all the Terraform modules in the subfolders of the working directory of the given TerragruntOptions and assemble them into a Stack object that can be applied or destroyed in a single command

type StackBuilder added in v0.81.1

type StackBuilder interface {
	BuildStack(ctx context.Context, l log.Logger, terragruntOptions *options.TerragruntOptions, opts ...Option) (Stack, error)
}

StackBuilder is the abstraction for building a Stack.

type TerraformModule

type TerraformModule struct {
	Stack                Stack
	TerragruntOptions    *options.TerragruntOptions
	Logger               log.Logger
	Path                 string
	Dependencies         TerraformModules
	Config               config.TerragruntConfig
	AssumeAlreadyApplied bool
	FlagExcluded         bool
}

TerraformModule 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 (*TerraformModule) FlushOutput added in v0.68.2

func (module *TerraformModule) FlushOutput() error

FlushOutput flushes buffer data to the output writer.

func (*TerraformModule) MarshalJSON added in v0.48.5

func (module *TerraformModule) MarshalJSON() ([]byte, error)

func (*TerraformModule) String

func (module *TerraformModule) String() string

String renders this module as a human-readable string

type TerraformModules added in v0.61.0

type TerraformModules []*TerraformModule

func FindWhereWorkingDirIsIncluded added in v0.33.0

func FindWhereWorkingDirIsIncluded(ctx context.Context, l log.Logger, opts *options.TerragruntOptions, terragruntConfig *config.TerragruntConfig) TerraformModules

FindWhereWorkingDirIsIncluded - find where working directory is included, flow: 1. Find root git top level directory and build list of modules 2. Iterate over includes from opts if git top level directory detection failed 3. Filter found module only items which has in dependencies working directory

func (TerraformModules) CheckForCycles added in v0.61.0

func (modules TerraformModules) CheckForCycles() error

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

func (TerraformModules) FindByPath added in v0.77.10

func (modules TerraformModules) FindByPath(path string) *TerraformModule

func (TerraformModules) RunModules added in v0.61.0

func (modules TerraformModules) RunModules(ctx context.Context, opts *options.TerragruntOptions, r *report.Report, parallelism int) error

RunModules runs the given map of module path to runningModule. To "run" a module, execute the RunTerragrunt command in its TerragruntOptions object. The modules will be executed in an order determined by their inter-dependencies, using as much concurrency as possible.

func (TerraformModules) RunModulesIgnoreOrder added in v0.61.0

func (modules TerraformModules) RunModulesIgnoreOrder(ctx context.Context, opts *options.TerragruntOptions, r *report.Report, parallelism int) error

RunModulesIgnoreOrder runs the given map of module path to runningModule. To "run" a module, execute the RunTerragrunt command in its TerragruntOptions object. The modules will be executed without caring for inter-dependencies.

func (TerraformModules) RunModulesReverseOrder added in v0.61.0

func (modules TerraformModules) RunModulesReverseOrder(ctx context.Context, opts *options.TerragruntOptions, r *report.Report, parallelism int) error

RunModulesReverseOrder runs the given map of module path to runningModule. To "run" a module, execute the RunTerragrunt command in its TerragruntOptions object. The modules will be executed in the reverse order of their inter-dependencies, using as much concurrency as possible.

func (TerraformModules) ToRunningModules added in v0.66.7

func (modules TerraformModules) ToRunningModules(dependencyOrder DependencyOrder, r *report.Report, opts *options.TerragruntOptions) (RunningModules, error)

ToRunningModules converts the list of modules to a map from module path to a runningModule struct. This struct contains information about executing the module, such as whether it has finished running or not and any errors that happened. Note that this does NOT actually run the module. For that, see the RunModules method.

func (TerraformModules) WriteDot added in v0.61.0

func (modules TerraformModules) 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/master/digraph/graphviz.go adding some styling to modules that are excluded from the execution in *-all commands

type TerraformModulesMap added in v0.61.0

type TerraformModulesMap map[string]*TerraformModule

type UnrecognizedDependencyError added in v0.61.0

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

func (UnrecognizedDependencyError) Error added in v0.61.0

func (err UnrecognizedDependencyError) Error() string

Jump to

Keyboard shortcuts

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