configstack

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2025 License: MIT Imports: 27 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 DependencyCycleError

type DependencyCycleError []string

func (DependencyCycleError) Error

func (err DependencyCycleError) Error() string

type DependencyNotFoundWhileCrossLinkingError

type DependencyNotFoundWhileCrossLinkingError struct {
	Module     *RunningModule
	Dependency *TerraformModule
}

func (DependencyNotFoundWhileCrossLinkingError) Error

type DependencyOrder

type DependencyOrder int

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

const (
	NormalOrder DependencyOrder = iota
	ReverseOrder
	IgnoreOrder
)

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 {
	RecursionLevel int
	Modules        map[string]*TerraformModule
}

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 ModuleStatus

type ModuleStatus int

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

const (
	Waiting ModuleStatus = iota
	Running
	Finished
)

type ModuleWriter

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

func NewModuleWriter(out io.Writer) *ModuleWriter

NewModuleWriter returns a new ModuleWriter instance.

func (*ModuleWriter) Flush

func (writer *ModuleWriter) Flush() error

Flush flushes buffer data to the `out` writer.

func (*ModuleWriter) Write

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

Write appends the contents of p to the buffer.

type Option

type Option func(*Stack)

Option is type for passing options to the Stack.

func WithChildTerragruntConfig

func WithChildTerragruntConfig(config *config.TerragruntConfig) Option

func WithParseOptions

func WithParseOptions(parserOptions []hclparse.Option) Option

type ProcessingModuleDependencyError

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

func (ProcessingModuleDependencyError) Error

func (ProcessingModuleDependencyError) ExitStatus

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

func (ProcessingModuleDependencyError) Unwrap

type ProcessingModuleError

type ProcessingModuleError struct {
	UnderlyingError       error
	ModulePath            string
	HowThisModuleWasFound string
}

func (ProcessingModuleError) Error

func (err ProcessingModuleError) Error() string

func (ProcessingModuleError) Unwrap

func (err ProcessingModuleError) Unwrap() error

type RunningModule

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

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

type RunningModules

type RunningModules map[string]*RunningModule

func (RunningModules) RemoveFlagExcluded

func (modules RunningModules) RemoveFlagExcluded() map[string]*RunningModule

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

type Stack

type Stack struct {
	Modules TerraformModules
	// contains filtered or unexported fields
}

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

func FindStackInSubfolders

func FindStackInSubfolders(ctx context.Context, 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

func NewStack

func NewStack(terragruntOptions *options.TerragruntOptions, opts ...Option) *Stack

func (*Stack) GetModuleRunGraph

func (stack *Stack) 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 (*Stack) Graph

func (stack *Stack) Graph(terragruntOptions *options.TerragruntOptions)

Graph creates a graphviz representation of the modules

func (*Stack) JSONModuleDeployOrder

func (stack *Stack) 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 (*Stack) ListStackDependentModules

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

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

func (*Stack) LogModuleDeployOrder

func (stack *Stack) LogModuleDeployOrder(logger 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 (*Stack) ResolveTerraformModules

func (stack *Stack) ResolveTerraformModules(ctx context.Context, 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 (*Stack) Run

func (stack *Stack) Run(ctx context.Context, terragruntOptions *options.TerragruntOptions) error

func (*Stack) String

func (stack *Stack) String() string

String renders this stack as a human-readable string

func (*Stack) WithOptions

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

type TerraformModule

type TerraformModule struct {
	*Stack
	Path                 string
	Dependencies         TerraformModules
	Config               config.TerragruntConfig
	TerragruntOptions    *options.TerragruntOptions
	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

func (module *TerraformModule) FlushOutput() error

FlushOutput flushes buffer data to the output writer.

func (*TerraformModule) MarshalJSON

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

type TerraformModules []*TerraformModule

func FindWhereWorkingDirIsIncluded

func FindWhereWorkingDirIsIncluded(ctx context.Context, 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

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) RunModules

func (modules TerraformModules) RunModules(ctx context.Context, opts *options.TerragruntOptions, 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

func (modules TerraformModules) RunModulesIgnoreOrder(ctx context.Context, opts *options.TerragruntOptions, 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

func (modules TerraformModules) RunModulesReverseOrder(ctx context.Context, opts *options.TerragruntOptions, 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

func (modules TerraformModules) ToRunningModules(dependencyOrder DependencyOrder) (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

func (modules TerraformModules) WriteDot(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

type TerraformModulesMap map[string]*TerraformModule

type UnrecognizedDependencyError

type UnrecognizedDependencyError struct {
	ModulePath            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