config

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: Apache-2.0 Imports: 46 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultTerragruntConfigPath     = "terragrunt.hcl"
	DefaultTerragruntJsonConfigPath = "terragrunt.hcl.json"
)
View Source
const (
	MetadataTerraform                   = "terraform"
	MetadataTerraformBinary             = "terraform_binary"
	MetadataTerraformVersionConstraint  = "terraform_version_constraint"
	MetadataTerragruntVersionConstraint = "terragrunt_version_constraint"
	MetadataRemoteState                 = "remote_state"
	MetadataDependencies                = "dependencies"
	MetadataDependency                  = "dependency"
	MetadataDownloadDir                 = "download_dir"
	MetadataPreventDestroy              = "prevent_destroy"
	MetadataSkip                        = "skip"
	MetadataIamRole                     = "iam_role"
	MetadataIamAssumeRoleDuration       = "iam_assume_role_duration"
	MetadataIamAssumeRoleSessionName    = "iam_assume_role_session_name"
	MetadataInputs                      = "inputs"
	MetadataLocals                      = "locals"
	MetadataGenerateConfigs             = "generate"
	MetadataRetryableErrors             = "retryable_errors"
	MetadataRetryMaxAttempts            = "retry_max_attempts"
	MetadataRetrySleepIntervalSec       = "retry_sleep_interval_sec"
	MetadataDependentModules            = "dependent_modules"
)
View Source
const FoundInFile = "found_in_file"
View Source
const MaxIter = 1000

MaxIter is the maximum number of depth we support in recursively evaluating locals.

Variables

Order matters, for example if none of the files are found `GetDefaultConfigPath` func returns the last element.

View Source
var TERRAFORM_COMMANDS_NEED_INPUT = []string{
	"apply",
	"import",
	"init",
	"plan",
	"refresh",
}

List of terraform commands that accept -input=

View Source
var TERRAFORM_COMMANDS_NEED_LOCKING = []string{
	"apply",
	"destroy",
	"import",
	"plan",
	"refresh",
	"taint",
	"untaint",
}

List of terraform commands that accept -lock-timeout

View Source
var TERRAFORM_COMMANDS_NEED_PARALLELISM = []string{
	"apply",
	"plan",
	"destroy",
}

List of terraform commands that accept -parallelism=

View Source
var TERRAFORM_COMMANDS_NEED_VARS = []string{
	"apply",
	"console",
	"destroy",
	"import",
	"plan",
	"push",
	"refresh",
}

List of terraform commands that accept -var or -var-file

Functions

func ClearOutputCache

func ClearOutputCache()

ClearOutputCache clears the output cache. Useful during testing.

func CreateTerragruntEvalContext

func CreateTerragruntEvalContext(
	filename string,
	terragruntOptions *options.TerragruntOptions,
	extensions EvalContextExtensions,
) (*hcl.EvalContext, error)

Create an EvalContext for the HCL2 parser. We can define functions and variables in this context that the HCL2 parser will make available to the Terragrunt configuration during parsing.

func FindConfigFilesInPath

func FindConfigFilesInPath(rootPath string, terragruntOptions *options.TerragruntOptions) ([]string, error)

Returns a list of all Terragrunt config files in the given path or any subfolder of the path. A file is a Terragrunt config file if it has a name as returned by the DefaultConfigPath method

func GetDefaultConfigPath

func GetDefaultConfigPath(workingDir string) string

Return the default path to use for the Terragrunt configuration that exists within the path giving preference to `terragrunt.hcl`

func GetTerraformSourceUrl

func GetTerraformSourceUrl(terragruntOptions *options.TerragruntOptions, terragruntConfig *TerragruntConfig) (string, error)

There are two ways a user can tell Terragrunt that it needs to download Terraform configurations from a specific URL: via a command-line option or via an entry in the Terragrunt configuration. If the user used one of these, this method returns the source URL or an empty string if there is no source url

func GetTerragruntSourceForModule

func GetTerragruntSourceForModule(sourcePath string, modulePath string, moduleTerragruntConfig *TerragruntConfig) (string, error)

If one of the xxx-all commands is called with the --terragrunt-source parameter, then for each module, we need to build its own --terragrunt-source parameter by doing the following:

1. Read the source URL from the Terragrunt configuration of each module 2. Extract the path from that URL (the part after a double-slash) 3. Append the path to the --terragrunt-source parameter

Example:

--terragrunt-source: /source/infrastructure-modules source param in module's terragrunt.hcl: git::git@github.com:acme/infrastructure-modules.git//networking/vpc?ref=v0.0.1

This method will return: /source/infrastructure-modules//networking/vpc

func ParseAndDecodeVarFile

func ParseAndDecodeVarFile(hclContents string, filename string, out interface{}) (err error)

ParseAndDecodeVarFile uses the HCL2 parser to parse the given varfile string into an HCL file body, and then decode it into the provided output.

func TerragruntConfigAsCty

func TerragruntConfigAsCty(config *TerragruntConfig) (cty.Value, error)

Serialize TerragruntConfig struct to a cty Value that can be used to reference the attributes in other config. Note that we can't straight up convert the struct using cty tags due to differences in the desired representation. Specifically, we want to reference blocks by named attributes, but blocks are rendered to lists in the TerragruntConfig struct, so we need to do some massaging of the data to convert the list of blocks in to a map going from the block name label to the block value.

func TerragruntConfigAsCtyWithMetadata

func TerragruntConfigAsCtyWithMetadata(config *TerragruntConfig) (cty.Value, error)

Types

type CouldNotEvaluateAllLocalsError

type CouldNotEvaluateAllLocalsError struct{}

func (CouldNotEvaluateAllLocalsError) Error

type CouldNotResolveTerragruntConfigInFile

type CouldNotResolveTerragruntConfigInFile string

func (CouldNotResolveTerragruntConfigInFile) Error

type CtyJsonOutput

type CtyJsonOutput struct {
	Value map[string]interface{}
	Type  interface{}
}

CtyJsonOutput When you convert a cty value to JSON, if any of that types are not yet known (i.e., are labeled as DynamicPseudoType), cty's Marshall method will write the type information to a type field and the actual value to a value field. This struct is used to capture that information so when we parse the JSON back into a Go struct, we can pull out just the Value field we need.

type Dependency

type Dependency struct {
	Name                                string     `hcl:",label" cty:"name"`
	Enabled                             *bool      `hcl:"enabled,attr" cty:"enabled"`
	ConfigPath                          string     `hcl:"config_path,attr" cty:"config_path"`
	SkipOutputs                         *bool      `hcl:"skip_outputs,attr" cty:"skip"`
	MockOutputs                         *cty.Value `hcl:"mock_outputs,attr" cty:"mock_outputs"`
	MockOutputsAllowedTerraformCommands *[]string  `hcl:"mock_outputs_allowed_terraform_commands,attr" cty:"mock_outputs_allowed_terraform_commands"`

	// MockOutputsMergeWithState is deprecated. Use MockOutputsMergeStrategyWithState
	MockOutputsMergeWithState         *bool              `hcl:"mock_outputs_merge_with_state,attr" cty:"mock_outputs_merge_with_state"`
	MockOutputsMergeStrategyWithState *MergeStrategyType `hcl:"mock_outputs_merge_strategy_with_state" cty:"mock_outputs_merge_strategy_with_state"`

	// Used to store the rendered outputs for use when the config is imported or read with `read_terragrunt_config`
	RenderedOutputs *cty.Value `cty:"outputs"`
}

func (*Dependency) DeepMerge

func (dependencyConfig *Dependency) DeepMerge(sourceDepConfig Dependency) error

DeepMerge will deep merge two Dependency configs, updating the target. Deep merge for Dependency configs is defined as follows:

  • For simple attributes (bools and strings), the source will override the target.
  • For MockOutputs, the two maps will be deeply merged together. This means that maps are recursively merged, while lists are concatenated together.
  • For MockOutputsAllowedTerraformCommands, the source will be concatenated to the target.

Note that RenderedOutputs is ignored in the deep merge operation.

type DependencyConfigNotFound

type DependencyConfigNotFound struct {
	Path string
}

func (DependencyConfigNotFound) Error

func (err DependencyConfigNotFound) Error() string

type DependencyCycle

type DependencyCycle []string

func (DependencyCycle) Error

func (err DependencyCycle) Error() string

type DependencyDirNotFound

type DependencyDirNotFound struct {
	Dir []string
}

func (DependencyDirNotFound) Error

func (err DependencyDirNotFound) Error() string

type DuplicatedGenerateBlocks

type DuplicatedGenerateBlocks struct {
	BlockName []string
}

func (DuplicatedGenerateBlocks) Error

func (err DuplicatedGenerateBlocks) Error() string

type EmptyStringNotAllowed

type EmptyStringNotAllowed string

func (EmptyStringNotAllowed) Error

func (err EmptyStringNotAllowed) Error() string

type EnvVar

type EnvVar struct {
	Name         string
	DefaultValue string
	IsRequired   bool
}

type EnvVarNotFound

type EnvVarNotFound struct {
	EnvVar string
}

func (EnvVarNotFound) Error

func (err EnvVarNotFound) Error() string

type ErrorHook

type ErrorHook struct {
	Name           string   `hcl:"name,label" cty:"name"`
	Commands       []string `hcl:"commands,attr" cty:"commands"`
	Execute        []string `hcl:"execute,attr" cty:"execute"`
	OnErrors       []string `hcl:"on_errors,attr" cty:"on_errors"`
	SuppressStdout *bool    `hcl:"suppress_stdout,attr" cty:"suppress_stdout"`
	WorkingDir     *string  `hcl:"working_dir,attr" cty:"working_dir"`
}

func (ErrorHook) GetName

func (conf ErrorHook) GetName() string

func (*ErrorHook) String

func (conf *ErrorHook) String() string

type ErrorParsingModulePath

type ErrorParsingModulePath struct {
	ModuleSourceUrl string
}

func (ErrorParsingModulePath) Error

func (err ErrorParsingModulePath) Error() string

type ErrorParsingTerragruntConfig

type ErrorParsingTerragruntConfig struct {
	ConfigPath string
	Underlying error
}

func (ErrorParsingTerragruntConfig) Error

type EvalContextExtensions

type EvalContextExtensions struct {
	// TrackInclude represents contexts of included configurations.
	TrackInclude *TrackInclude

	// Locals are preevaluated variable bindings that can be used by reference in the code.
	Locals *cty.Value

	// DecodedDependencies are references of other terragrunt config. This contains the following attributes that map to
	// various fields related to that config:
	// - outputs: The map of outputs from the terraform state obtained by running `terragrunt output` on that target
	//            config.
	DecodedDependencies *cty.Value

	// PartialParseDecodeList is the list of sections that are being decoded in the current config. This can be used to
	// indicate/detect that the current parsing context is partial, meaning that not all configuration values are
	// expected to be available.
	PartialParseDecodeList []PartialDecodeSectionType
}

EvalContextExtensions provides various extensions to the evaluation context to enhance the parsing capabilities.

type Hook

type Hook struct {
	Name           string   `hcl:"name,label" cty:"name"`
	Commands       []string `hcl:"commands,attr" cty:"commands"`
	Execute        []string `hcl:"execute,attr" cty:"execute"`
	RunOnError     *bool    `hcl:"run_on_error,attr" cty:"run_on_error"`
	SuppressStdout *bool    `hcl:"suppress_stdout,attr" cty:"suppress_stdout"`
	WorkingDir     *string  `hcl:"working_dir,attr" cty:"working_dir"`
}

Hook specifies terraform commands (apply/plan) and array of os commands to execute

func (Hook) GetName

func (conf Hook) GetName() string

func (*Hook) String

func (conf *Hook) String() string

type IAMRoleOptionsCache

type IAMRoleOptionsCache struct {
	Cache map[string]options.IAMRoleOptions
	Mutex *sync.Mutex
}

IAMRoleOptionsCache - cache for IAMRole options

func NewIAMRoleOptionsCache

func NewIAMRoleOptionsCache() *IAMRoleOptionsCache

NewIAMRoleOptionsCache - create new cache for IAM roles

func (*IAMRoleOptionsCache) Get

Get - get cached value, sha256 hash is used as key to have fixed length keys and avoid duplicates

func (*IAMRoleOptionsCache) Put

func (cache *IAMRoleOptionsCache) Put(key string, value options.IAMRoleOptions)

Put - put value in cache, sha256 hash is used as key to have fixed length keys and avoid duplicates

type IncludeConfig

type IncludeConfig struct {
	Name          string  `hcl:"name,label"`
	Path          string  `hcl:"path,attr"`
	Expose        *bool   `hcl:"expose,attr"`
	MergeStrategy *string `hcl:"merge_strategy,attr"`
}

IncludeConfig represents the configuration settings for a parent Terragrunt configuration file that you can include into a child Terragrunt configuration file. You can have more than one include config.

func (*IncludeConfig) GetExpose

func (cfg *IncludeConfig) GetExpose() bool

func (*IncludeConfig) GetMergeStrategy

func (cfg *IncludeConfig) GetMergeStrategy() (MergeStrategyType, error)

func (*IncludeConfig) String

func (cfg *IncludeConfig) String() string

type IncludeConfigs

type IncludeConfigs map[string]IncludeConfig

func (IncludeConfigs) ContainsPath

func (cfgs IncludeConfigs) ContainsPath(path string) bool

ContainsPath returns true if the given path is contained in at least one configuration.

type IncludeIsNotABlockErr

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

func (IncludeIsNotABlockErr) Error

func (err IncludeIsNotABlockErr) Error() string

type IncludedConfigMissingPath

type IncludedConfigMissingPath string

func (IncludedConfigMissingPath) Error

func (err IncludedConfigMissingPath) Error() string

type InvalidArgError

type InvalidArgError string

func (InvalidArgError) Error

func (e InvalidArgError) Error() string

type InvalidBackendConfigType

type InvalidBackendConfigType struct {
	ExpectedType string
	ActualType   string
}

func (InvalidBackendConfigType) Error

func (err InvalidBackendConfigType) Error() string

type InvalidEnvParamName

type InvalidEnvParamName struct {
	EnvVarName string
}

func (InvalidEnvParamName) Error

func (err InvalidEnvParamName) Error() string

type InvalidGetEnvParams

type InvalidGetEnvParams struct {
	ActualNumParams int
	Example         string
}

func (InvalidGetEnvParams) Error

func (err InvalidGetEnvParams) Error() string

type InvalidIncludeKey

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

func (InvalidIncludeKey) Error

func (err InvalidIncludeKey) Error() string

type InvalidMergeStrategyType

type InvalidMergeStrategyType string

func (InvalidMergeStrategyType) Error

func (err InvalidMergeStrategyType) Error() string

type InvalidParameterType

type InvalidParameterType struct {
	Expected string
	Actual   string
}

func (InvalidParameterType) Error

func (err InvalidParameterType) Error() string

type InvalidPartialBlockName

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

func (InvalidPartialBlockName) Error

func (err InvalidPartialBlockName) Error() string

type InvalidSopsFormat

type InvalidSopsFormat struct {
	SourceFilePath string
}

func (InvalidSopsFormat) Error

func (err InvalidSopsFormat) Error() string

type InvalidSourceUrl

type InvalidSourceUrl struct {
	ModulePath       string
	ModuleSourceUrl  string
	TerragruntSource string
}

func (InvalidSourceUrl) Error

func (err InvalidSourceUrl) Error() string

type InvalidSourceUrlWithMap

type InvalidSourceUrlWithMap struct {
	ModulePath      string
	ModuleSourceUrl string
}

func (InvalidSourceUrlWithMap) Error

func (err InvalidSourceUrlWithMap) Error() string

type Local

type Local struct {
	Name string
	Expr hcl.Expression
}

Local represents a single local name binding. This holds the unevaluated expression, extracted from the parsed file (but before decoding) so that we can look for references to other locals before evaluating.

type MaxIterError

type MaxIterError struct{}

func (MaxIterError) Error

func (err MaxIterError) Error() string

type MergeStrategyType

type MergeStrategyType string
const (
	NoMerge          MergeStrategyType = "no_merge"
	ShallowMerge     MergeStrategyType = "shallow"
	DeepMerge        MergeStrategyType = "deep"
	DeepMergeMapOnly MergeStrategyType = "deep_map_only"
)

type ModuleDependencies

type ModuleDependencies struct {
	Paths []string `hcl:"paths,attr" cty:"paths"`
}

ModuleDependencies represents the paths to other Terraform modules that must be applied before the current module can be applied

func (*ModuleDependencies) Merge

func (deps *ModuleDependencies) Merge(source *ModuleDependencies)

Merge appends the paths in the provided ModuleDependencies object into this ModuleDependencies object.

func (*ModuleDependencies) String

func (deps *ModuleDependencies) String() string

type MultipleBareIncludeBlocksErr

type MultipleBareIncludeBlocksErr struct{}

func (MultipleBareIncludeBlocksErr) Error

type PanicWhileParsingConfig

type PanicWhileParsingConfig struct {
	ConfigFile     string
	RecoveredValue interface{}
}

func (PanicWhileParsingConfig) Error

func (err PanicWhileParsingConfig) Error() string

type ParentFileNotFound

type ParentFileNotFound struct {
	Path  string
	File  string
	Cause string
}

func (ParentFileNotFound) Error

func (err ParentFileNotFound) Error() string

type PartialDecodeSectionType

type PartialDecodeSectionType int

PartialDecodeSectionType is an enum that is used to list out which blocks/sections of the terragrunt config should be decoded in a partial decode.

const (
	DependenciesBlock PartialDecodeSectionType = iota
	DependencyBlock
	TerraformBlock
	TerraformSource
	TerragruntFlags
	TerragruntVersionConstraints
	RemoteStateBlock
)

type StringCache

type StringCache struct {
	Cache map[string]string
	Mutex *sync.Mutex
}

StringCache - structure to store cached values

func NewStringCache

func NewStringCache() *StringCache

NewStringCache - create new string cache

func (*StringCache) Get

func (cache *StringCache) Get(key string) (string, bool)

Get - get cached value, sha256 hash is used as key to have fixed length keys and avoid duplicates

func (*StringCache) Put

func (cache *StringCache) Put(key string, value string)

Put - put value in cache, sha256 hash is used as key to have fixed length keys and avoid duplicates

type TerraformConfig

type TerraformConfig struct {
	ExtraArgs   []TerraformExtraArguments `hcl:"extra_arguments,block"`
	Source      *string                   `hcl:"source,attr"`
	BeforeHooks []Hook                    `hcl:"before_hook,block"`
	AfterHooks  []Hook                    `hcl:"after_hook,block"`
	ErrorHooks  []ErrorHook               `hcl:"error_hook,block"`

	// Ideally we can avoid the pointer to list slice, but if it is not a pointer, Terraform requires the attribute to
	// be defined and we want to make this optional.
	IncludeInCopy *[]string `hcl:"include_in_copy,attr"`
}

TerraformConfig specifies where to find the Terraform configuration files NOTE: If any attributes or blocks are added here, be sure to add it to ctyTerraformConfig in config_as_cty.go as well.

func (*TerraformConfig) GetAfterHooks

func (conf *TerraformConfig) GetAfterHooks() []Hook

func (*TerraformConfig) GetBeforeHooks

func (conf *TerraformConfig) GetBeforeHooks() []Hook

func (*TerraformConfig) GetErrorHooks

func (conf *TerraformConfig) GetErrorHooks() []ErrorHook

func (*TerraformConfig) String

func (conf *TerraformConfig) String() string

func (*TerraformConfig) ValidateHooks

func (conf *TerraformConfig) ValidateHooks() error

type TerraformExtraArguments

type TerraformExtraArguments struct {
	Name             string             `hcl:"name,label" cty:"name"`
	Arguments        *[]string          `hcl:"arguments,attr" cty:"arguments"`
	RequiredVarFiles *[]string          `hcl:"required_var_files,attr" cty:"required_var_files"`
	OptionalVarFiles *[]string          `hcl:"optional_var_files,attr" cty:"optional_var_files"`
	Commands         []string           `hcl:"commands,attr" cty:"commands"`
	EnvVars          *map[string]string `hcl:"env_vars,attr" cty:"env_vars"`
}

TerraformExtraArguments sets a list of arguments to pass to Terraform if command fits any in the `Commands` list

func (TerraformExtraArguments) GetName

func (conf TerraformExtraArguments) GetName() string

func (*TerraformExtraArguments) GetVarFiles

func (conf *TerraformExtraArguments) GetVarFiles(logger *logrus.Entry) []string

func (*TerraformExtraArguments) String

func (conf *TerraformExtraArguments) String() string

type TerragruntConfig

type TerragruntConfig struct {
	Terraform                   *TerraformConfig
	TerraformBinary             string
	TerraformVersionConstraint  string
	TerragruntVersionConstraint string
	RemoteState                 *remote.RemoteState
	Dependencies                *ModuleDependencies
	DownloadDir                 string
	PreventDestroy              *bool
	Skip                        bool
	IamRole                     string
	IamAssumeRoleDuration       *int64
	IamAssumeRoleSessionName    string
	Inputs                      map[string]interface{}
	Locals                      map[string]interface{}
	TerragruntDependencies      []Dependency
	GenerateConfigs             map[string]codegen.GenerateConfig
	RetryableErrors             []string
	RetryMaxAttempts            *int
	RetrySleepIntervalSec       *int

	// Fields used for internal tracking
	// Indicates whether or not this is the result of a partial evaluation
	IsPartial bool

	// Map of processed includes
	ProcessedIncludes IncludeConfigs

	// Map to store fields metadata
	FieldsMetadata map[string]map[string]interface{}

	// List of dependent modules
	DependentModulesPath []*string
}

TerragruntConfig represents a parsed and expanded configuration NOTE: if any attributes are added, make sure to update terragruntConfigAsCty in config_as_cty.go

func ParseConfigFile

func ParseConfigFile(filename string, terragruntOptions *options.TerragruntOptions, include *IncludeConfig, dependencyOutputs *cty.Value) (*TerragruntConfig, error)

Parse the Terragrunt config file at the given path. If the include parameter is not nil, then treat this as a config included in some other config file when resolving relative paths.

func ParseConfigString

func ParseConfigString(
	configString string,
	terragruntOptions *options.TerragruntOptions,
	includeFromChild *IncludeConfig,
	filename string,
	dependencyOutputs *cty.Value,
) (*TerragruntConfig, error)

Parse the Terragrunt config contained in the given string and merge it with the given include config (if any). Note that the config parsing consists of multiple stages so as to allow referencing of data resulting from parsing previous config. The parsing order is:

  1. Parse include. Include is parsed first and is used to import another config. All the config in the include block is then merged into the current TerragruntConfig, except for locals (by design). Note that since the include block is parsed first, you cannot reference locals in the include block config.
  2. Parse locals. Since locals are parsed next, you can only reference other locals in the locals block. Although it is possible to merge locals from a config imported with an include block, we do not do that here to avoid complicated referencing issues. Please refer to the globals proposal for an alternative that allows merging from included config: https://github.com/c3xdev/c3x/internal/hclstack/issues/814 Allowed References: - locals
  3. Parse dependency blocks. This includes running `terragrunt output` to fetch the output data from another terragrunt config, so that it is accessible within the config. See PartialParseConfigString for a way to parse the blocks but avoid decoding. Note that this step is skipped if we already retrieved all the dependencies (which is the case when parsing included config files). This is determined by the dependencyOutputs input parameter. Allowed References: - locals
  4. Parse everything else. At this point, all the necessary building blocks for parsing the rest of the config are available, so parse the rest of the config. Allowed References: - locals - dependency
  5. Merge the included config with the parsed config. Note that all the config data is mergable except for `locals` blocks, which are only scoped to be available within the defining config.

func PartialParseConfigFile

func PartialParseConfigFile(
	filename string,
	terragruntOptions *options.TerragruntOptions,
	include *IncludeConfig,
	decodeList []PartialDecodeSectionType,
) (*TerragruntConfig, error)

func PartialParseConfigString

func PartialParseConfigString(
	configString string,
	terragruntOptions *options.TerragruntOptions,
	includeFromChild *IncludeConfig,
	filename string,
	decodeList []PartialDecodeSectionType,
) (*TerragruntConfig, error)

PartialParseConfigString partially parses and decodes the provided string. Which blocks/attributes to decode is controlled by the function parameter decodeList. These blocks/attributes are parsed and set on the output TerragruntConfig. Valid values are:

  • DependenciesBlock: Parses the `dependencies` block in the config
  • DependencyBlock: Parses the `dependency` block in the config
  • TerraformBlock: Parses the `terraform` block in the config
  • TerragruntFlags: Parses the boolean flags `prevent_destroy` and `skip` in the config
  • TerragruntVersionConstraints: Parses the attributes related to constraining terragrunt and terraform versions in the config.
  • RemoteStateBlock: Parses the `remote_state` block in the config

Note that the following blocks are always decoded: - locals - include Note also that the following blocks are never decoded in a partial parse: - inputs

func ReadTerragruntConfig

func ReadTerragruntConfig(terragruntOptions *options.TerragruntOptions) (*TerragruntConfig, error)

Read the Terragrunt config file from its default location

func TerragruntConfigFromPartialConfigString

func TerragruntConfigFromPartialConfigString(
	configString string,
	terragruntOptions *options.TerragruntOptions,
	includeFromChild *IncludeConfig,
	filename string,
	decodeList []PartialDecodeSectionType,
) (*TerragruntConfig, error)

Wrapper of PartialParseConfigString which checks for cached configs. filename, configString, includeFromChild and decodeList are used for the cache key, by getting the default value (%#v) through fmt.

func (*TerragruntConfig) DeepMerge

func (conf *TerragruntConfig) DeepMerge(sourceConfig *TerragruntConfig, terragruntOptions *options.TerragruntOptions) error

DeepMerge performs a deep merge of the given sourceConfig into the targetConfig. Deep merge is defined as follows:

  • For simple types, the source overrides the target.
  • For lists, the two attribute lists are combined together in concatenation.
  • For maps, the two maps are combined together recursively. That is, if the map keys overlap, then a deep merge is performed on the map value.
  • Note that some structs are not deep mergeable due to an implementation detail. This will change in the future. The following structs have this limitation:
  • remote_state
  • generate
  • Note that the following attributes are deliberately omitted from the merge operation, as they are handled differently in the parser:
  • dependency blocks (TerragruntDependencies) [These blocks need to retrieve outputs, so we need to merge during the parsing step, not after the full config is decoded]
  • locals [These blocks are not merged by design]

func (*TerragruntConfig) GetFieldMetadata

func (conf *TerragruntConfig) GetFieldMetadata(fieldName string) (map[string]string, bool)

GetFieldMetadata return field metadata by field name.

func (*TerragruntConfig) GetIAMRoleOptions

func (conf *TerragruntConfig) GetIAMRoleOptions() options.IAMRoleOptions

GetIAMRoleOptions is a helper function that converts the Terragrunt config IAM role attributes to options.IAMRoleOptions struct.

func (*TerragruntConfig) GetMapFieldMetadata

func (conf *TerragruntConfig) GetMapFieldMetadata(fieldType, fieldName string) (map[string]string, bool)

GetMapFieldMetadata return field metadata by field type and name.

func (*TerragruntConfig) Merge

func (conf *TerragruntConfig) Merge(sourceConfig *TerragruntConfig, terragruntOptions *options.TerragruntOptions) error

Merge performs a shallow merge of the given sourceConfig into the targetConfig. sourceConfig will override common attributes defined in the targetConfig. Note that this will modify the targetConfig. NOTE: the following attributes are deliberately omitted from the merge operation, as they are handled differently in the parser:

  • locals [These blocks are not merged by design]

NOTE: dependencies block is a special case and is merged deeply. This is necessary to ensure the configstack system works correctly, as it uses the `Dependencies` list to track the dependencies of modules for graph building purposes. This list includes the dependencies added from dependency blocks, which is handled in a different stage.

func (*TerragruntConfig) SetFieldMetadata

func (conf *TerragruntConfig) SetFieldMetadata(fieldName string, m map[string]interface{})

SetFieldMetadata set metadata on the given field name.

func (*TerragruntConfig) SetFieldMetadataMap

func (conf *TerragruntConfig) SetFieldMetadataMap(field string, data map[string]interface{}, metadata map[string]interface{})

SetFieldMetadataMap set metadata on fields from map keys. Example usage - setting metadata on all variables from inputs.

func (*TerragruntConfig) SetFieldMetadataWithType

func (conf *TerragruntConfig) SetFieldMetadataWithType(fieldType, fieldName string, m map[string]interface{})

SetFieldMetadataWithType set metadata on the given field name grouped by type. Example usage - setting metadata on different dependencies, locals, inputs.

func (*TerragruntConfig) String

func (conf *TerragruntConfig) String() string

type TerragruntConfigCache

type TerragruntConfigCache struct {
	Cache map[string]*TerragruntConfig
	Mutex *sync.Mutex
}

TerragruntConfigCache - structure to store cached values

func NewTerragruntConfigCache

func NewTerragruntConfigCache() *TerragruntConfigCache

NewTerragruntConfigCache - create new TerragruntConfig cache

func (*TerragruntConfigCache) Get

func (cache *TerragruntConfigCache) Get(key string) (*TerragruntConfig, bool)

Get - get cached value Design decision: Drop the sha256 because map is already a hashtable See https://go.dev/src/runtime/map.go

func (*TerragruntConfigCache) Put

func (cache *TerragruntConfigCache) Put(key string, value *TerragruntConfig)

Put - put value in cache

type TerragruntConfigFile

type TerragruntConfigFile struct {
	Terraform                   *TerraformConfig `hcl:"terraform,block"`
	TerraformBinary             *string          `hcl:"terraform_binary,attr"`
	TerraformVersionConstraint  *string          `hcl:"terraform_version_constraint,attr"`
	TerragruntVersionConstraint *string          `hcl:"terragrunt_version_constraint,attr"`
	Inputs                      *cty.Value       `hcl:"inputs,attr"`

	// We allow users to configure remote state (backend) via blocks:
	//
	// remote_state {
	//   backend = "s3"
	//   config  = { ... }
	// }
	//
	// Or as attributes:
	//
	// remote_state = {
	//   backend = "s3"
	//   config  = { ... }
	// }
	RemoteState     *remoteStateConfigFile `hcl:"remote_state,block"`
	RemoteStateAttr *cty.Value             `hcl:"remote_state,optional"`

	Dependencies             *ModuleDependencies `hcl:"dependencies,block"`
	DownloadDir              *string             `hcl:"download_dir,attr"`
	PreventDestroy           *bool               `hcl:"prevent_destroy,attr"`
	Skip                     *bool               `hcl:"skip,attr"`
	IamRole                  *string             `hcl:"iam_role,attr"`
	IamAssumeRoleDuration    *int64              `hcl:"iam_assume_role_duration,attr"`
	IamAssumeRoleSessionName *string             `hcl:"iam_assume_role_session_name,attr"`
	TerragruntDependencies   []Dependency        `hcl:"dependency,block"`

	// We allow users to configure code generation via blocks:
	//
	// generate "example" {
	//   path     = "example.tf"
	//   contents = "example"
	// }
	//
	// Or via attributes:
	//
	// generate = {
	//   example = {
	//     path     = "example.tf"
	//     contents = "example"
	//   }
	// }
	GenerateAttrs  *cty.Value                `hcl:"generate,optional"`
	GenerateBlocks []terragruntGenerateBlock `hcl:"generate,block"`

	RetryableErrors       []string `hcl:"retryable_errors,optional"`
	RetryMaxAttempts      *int     `hcl:"retry_max_attempts,optional"`
	RetrySleepIntervalSec *int     `hcl:"retry_sleep_interval_sec,optional"`

	// This struct is used for validating and parsing the entire terragrunt config. Since locals and include are
	// evaluated in a completely separate cycle, it should not be evaluated here. Otherwise, we can't support self
	// referencing other elements in the same block.
	// We don't want to use the special Remain keyword here, as that would cause the checker to support parsing config
	// that have extraneous, unsupported blocks and attributes.
	Locals  *terragruntLocal          `hcl:"locals,block"`
	Include []terragruntIncludeIgnore `hcl:"include,block"`
}

TerragruntConfigFile represents the configuration supported in a Terragrunt configuration file (i.e. terragrunt.hcl)

type TerragruntConfigNotFound

type TerragruntConfigNotFound struct {
	Path string
}

func (TerragruntConfigNotFound) Error

func (err TerragruntConfigNotFound) Error() string

type TerragruntOutputEncodingError

type TerragruntOutputEncodingError struct {
	Path string
	Err  error
}

func (TerragruntOutputEncodingError) Error

type TerragruntOutputListEncodingError

type TerragruntOutputListEncodingError struct {
	Paths []string
	Err   error
}

func (TerragruntOutputListEncodingError) Error

type TerragruntOutputParsingError

type TerragruntOutputParsingError struct {
	Path string
	Err  error
}

func (TerragruntOutputParsingError) Error

type TerragruntOutputTargetNoOutputs

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

func (TerragruntOutputTargetNoOutputs) Error

type TooManyLevelsOfInheritance

type TooManyLevelsOfInheritance struct {
	ConfigPath             string
	FirstLevelIncludePath  string
	SecondLevelIncludePath string
}

func (TooManyLevelsOfInheritance) Error

func (err TooManyLevelsOfInheritance) Error() string

type TrackInclude

type TrackInclude struct {
	// CurrentList is used to track the list of configs that should be imported and merged before the final
	// TerragruntConfig is returned. This preserves the order of the blocks as they appear in the config, so that we can
	// merge the included config in the right order.
	CurrentList []IncludeConfig

	// CurrentMap is the map version of CurrentList that maps the block labels to the included config.
	CurrentMap map[string]IncludeConfig

	// Original is used to track the original included config, and is used for resolving the include related
	// functions.
	Original *IncludeConfig
}

TrackInclude is used to differentiate between an included config in the current parsing context, and an included config that was passed through from a previous parsing context.

func DecodeBaseBlocks

func DecodeBaseBlocks(
	terragruntOptions *options.TerragruntOptions,
	parser *hclparse.Parser,
	hclFile *hcl.File,
	filename string,
	includeFromChild *IncludeConfig,
	decodeList []PartialDecodeSectionType,
) (*cty.Value, *TrackInclude, error)

DecodeBaseBlocks takes in a parsed HCL2 file and decodes the base blocks. Base blocks are blocks that should always be decoded even in partial decoding, because they provide bindings that are necessary for parsing any block in the file. Currently base blocks are: - locals - include

type ValueWithMetadata

type ValueWithMetadata struct {
	Value    cty.Value         `json:"value" cty:"value"`
	Metadata map[string]string `json:"metadata" cty:"metadata"`
}

ValueWithMetadata stores value and metadata used in render-json with metadata.

type WrongNumberOfParams

type WrongNumberOfParams struct {
	Func     string
	Expected string
	Actual   int
}

Custom error types

func (WrongNumberOfParams) Error

func (err WrongNumberOfParams) Error() string

Jump to

Keyboard shortcuts

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