Documentation
¶
Overview ¶
Package config provides functionality for parsing Terragrunt configuration files.
Package config provides telemetry support for configuration parsing operations.
Index ¶
- Constants
- Variables
- func ConstraintCheck(ctx context.Context, pctx *ParsingContext, args []string) (bool, error)
- func ConvertValuesMapToCtyVal(valMap map[string]cty.Value) (cty.Value, error)
- func CopyFieldsMetadata(sourceConfig *TerragruntConfig, targetConfig *TerragruntConfig)
- func CopyLockFile(l log.Logger, opts *options.TerragruntOptions, ...) error
- func CtyToStruct(ctyValue cty.Value, target any) error
- func CtyValueAsString(val cty.Value) (string, error)
- func DetectDeprecatedConfigurations(ctx context.Context, pctx *ParsingContext, l log.Logger, file *hclparse.File) error
- func DetectInputsCtyUsage(file *hclparse.File) bool
- func EndsWith(ctx context.Context, pctx *ParsingContext, args []string) (bool, error)
- func EvaluateLocalsBlock(ctx context.Context, pctx *ParsingContext, l log.Logger, file *hclparse.File) (map[string]cty.Value, error)
- func FindConfigFilesInPath(rootPath string, opts *options.TerragruntOptions) ([]string, error)
- func FindInParentFolders(ctx context.Context, pctx *ParsingContext, l log.Logger, params []string) (string, error)
- func FormatValue(value cty.Value) (string, error)
- func GenerateStackFile(ctx context.Context, l log.Logger, opts *options.TerragruntOptions, ...) error
- func GetDefaultConfigPath(workingDir string) string
- func GetFirstKey(m map[string]cty.Value) string
- func GetParentTerragruntDir(ctx context.Context, pctx *ParsingContext, l log.Logger, params []string) (string, error)
- func GetTerraformSourceURL(terragruntOptions *options.TerragruntOptions, ...) (string, error)
- func GetTerragruntDir(ctx context.Context, pctx *ParsingContext, l log.Logger) (string, error)
- func GetTerragruntSourceForModule(sourcePath string, modulePath string, moduleTerragruntConfig *TerragruntConfig) (string, error)
- func GetUnitDir(dir string, unit *Unit) string
- func GetValueString(value cty.Value) (string, error)
- func GoTypeToCty(val any) (cty.Value, error)
- func IsComplexType(value cty.Value) bool
- func IsValidConfigPath(v cty.Value) bool
- func ParseAndDecodeVarFile(l log.Logger, opts *options.TerragruntOptions, varFile string, ...) error
- func ParseRemoteState(ctx context.Context, l log.Logger, opts *options.TerragruntOptions) (*remotestate.RemoteState, error)
- func ParseTerragruntConfig(ctx context.Context, pctx *ParsingContext, l log.Logger, configPath string, ...) (cty.Value, error)
- func PathRelativeFromInclude(ctx context.Context, pctx *ParsingContext, l log.Logger, params []string) (string, error)
- func PathRelativeToInclude(ctx context.Context, pctx *ParsingContext, l log.Logger, params []string) (string, error)
- func ReadValues(ctx context.Context, l log.Logger, opts *options.TerragruntOptions, ...) (*cty.Value, error)
- func RemoteStateAsCty(remote *remotestate.RemoteState) (cty.Value, error)
- func RunCommand(ctx context.Context, pctx *ParsingContext, l log.Logger, args []string) (string, error)
- func StartsWith(ctx context.Context, pctx *ParsingContext, args []string) (bool, error)
- func StrContains(ctx context.Context, pctx *ParsingContext, args []string) (bool, error)
- func TerraformOutputJSONToCtyValueMap(targetConfigPath string, jsonBytes []byte) (map[string]cty.Value, error)
- func TerragruntConfigAsCty(config *TerragruntConfig) (cty.Value, error)
- func TerragruntConfigAsCtyWithMetadata(config *TerragruntConfig) (cty.Value, error)
- func TimeCmp(ctx context.Context, pctx *ParsingContext, l log.Logger, args []string) (int64, error)
- func TraceParseBaseBlocksResult(ctx context.Context, configPath string, baseBlocks *DecodedBaseBlocks)
- func TraceParseConfigDecode(ctx context.Context, configPath string, fn func(ctx context.Context) error) error
- func TraceParseConfigFile(ctx context.Context, configPath string, workingDir string, isPartial bool, ...) error
- func TraceParseDependencies(ctx context.Context, configPath string, skipOutputsResolution bool, ...) error
- func TraceParseDependency(ctx context.Context, dependencyName string, dependencyPath string, ...) error
- func TraceParseIncludeMerge(ctx context.Context, configPath string, includeCount int, ...) error
- func ValidateStackConfig(config *StackConfigFile) error
- func WithConfigValues(ctx context.Context) context.Context
- type CatalogConfig
- type ConflictingRunCmdCacheOptionsError
- type CouldNotEvaluateAllLocalsError
- type CouldNotResolveTerragruntConfigInFileError
- type CtyTerraformConfig
- type DecodedBaseBlocks
- type Dependencies
- type Dependency
- type DependencyConfigNotFound
- type DependencyCycleError
- type DependencyDirNotFoundError
- type DependencyFileNotFoundError
- type DependencyInvalidConfigPathError
- type DuplicatedGenerateBlocksError
- type EmptyStringNotAllowedError
- type EngineConfig
- type EnvVar
- type EnvVarNotFoundError
- type ErrorHook
- type ErrorsConfig
- type ExcludeConfig
- type FeatureFlag
- type FeatureFlags
- type Hook
- type IgnoreBlock
- type IncludeConfig
- type IncludeConfigNotFoundError
- type IncludeConfigs
- type IncludeConfigsMap
- type IncludeIsNotABlockErr
- type IncludedConfigMissingPathError
- type InvalidArgError
- type InvalidEnvParamNameError
- type InvalidGetEnvParamsError
- type InvalidIncludeKeyError
- type InvalidMergeStrategyTypeError
- type InvalidParameterTypeError
- type InvalidPartialBlockName
- type InvalidSopsFormatError
- type InvalidSourceURLError
- type InvalidSourceURLWithMapError
- type MaxIterError
- type MaxParseDepthError
- type MergeStrategyType
- type ModuleDependencies
- type MultipleBareIncludeBlocksErr
- type ParentFileNotFoundError
- type ParsedVariable
- type ParsingContext
- func (ctx *ParsingContext) Clone() *ParsingContext
- func (ctx *ParsingContext) WithDecodeList(decodeList ...PartialDecodeSectionType) *ParsingContext
- func (ctx *ParsingContext) WithDecodedDependencies(v *cty.Value) *ParsingContext
- func (ctx *ParsingContext) WithDiagnosticsSuppressed(l log.Logger) *ParsingContext
- func (ctx *ParsingContext) WithFeatures(features *cty.Value) *ParsingContext
- func (ctx *ParsingContext) WithIncrementedDepth() (*ParsingContext, error)
- func (ctx *ParsingContext) WithLocals(locals *cty.Value) *ParsingContext
- func (ctx *ParsingContext) WithParseOption(parserOptions []hclparse.Option) *ParsingContext
- func (ctx *ParsingContext) WithSkipOutputsResolution() *ParsingContext
- func (ctx *ParsingContext) WithTerragruntOptions(opts *options.TerragruntOptions) *ParsingContext
- func (ctx *ParsingContext) WithTrackInclude(trackInclude *TrackInclude) *ParsingContext
- func (ctx *ParsingContext) WithValues(values *cty.Value) *ParsingContext
- type ParsingModulePathError
- type PartialDecodeSectionType
- type RetryBlock
- type Stack
- type StackConfig
- func ParseStackConfig(ctx context.Context, l log.Logger, parser *ParsingContext, ...) (*StackConfig, error)
- func ReadStackConfigFile(ctx context.Context, l log.Logger, opts *options.TerragruntOptions, ...) (*StackConfig, error)
- func ReadStackConfigString(ctx context.Context, l log.Logger, opts *options.TerragruntOptions, ...) (*StackConfig, error)
- type StackConfigFile
- type TFVarFileNotFoundError
- type TerraformConfig
- type TerraformExtraArguments
- type TerragruntConfig
- func ParseConfig(ctx context.Context, pctx *ParsingContext, l log.Logger, file *hclparse.File, ...) (*TerragruntConfig, error)
- func ParseConfigFile(ctx context.Context, pctx *ParsingContext, l log.Logger, configPath string, ...) (*TerragruntConfig, error)
- func ParseConfigString(ctx context.Context, pctx *ParsingContext, l log.Logger, configPath string, ...) (*TerragruntConfig, error)
- func PartialParseConfig(ctx context.Context, pctx *ParsingContext, l log.Logger, file *hclparse.File, ...) (*TerragruntConfig, error)
- func PartialParseConfigFile(ctx context.Context, pctx *ParsingContext, l log.Logger, configPath string, ...) (*TerragruntConfig, error)
- func PartialParseConfigString(ctx context.Context, pctx *ParsingContext, l log.Logger, ...) (*TerragruntConfig, error)
- func ReadTerragruntConfig(ctx context.Context, l log.Logger, opts *options.TerragruntOptions, ...) (*TerragruntConfig, error)
- func TerragruntConfigFromPartialConfig(ctx context.Context, pctx *ParsingContext, l log.Logger, file *hclparse.File, ...) (*TerragruntConfig, error)
- func (cfg *TerragruntConfig) DeepMerge(l log.Logger, sourceConfig *TerragruntConfig, ...) error
- func (cfg *TerragruntConfig) EngineOptions() (*options.EngineOptions, error)
- func (cfg *TerragruntConfig) ErrorsConfig() (*options.ErrorsConfig, error)
- func (cfg *TerragruntConfig) GetFieldMetadata(fieldName string) (map[string]string, bool)
- func (cfg *TerragruntConfig) GetIAMRoleOptions() options.IAMRoleOptions
- func (cfg *TerragruntConfig) GetMapFieldMetadata(fieldType, fieldName string) (map[string]string, bool)
- func (cfg *TerragruntConfig) GetRemoteState(l log.Logger, opts *options.TerragruntOptions) (*remotestate.RemoteState, error)
- func (cfg *TerragruntConfig) Merge(l log.Logger, sourceConfig *TerragruntConfig, ...) error
- func (cfg *TerragruntConfig) SetFieldMetadata(fieldName string, m map[string]any)
- func (cfg *TerragruntConfig) SetFieldMetadataMap(field string, data map[string]any, metadata map[string]any)
- func (cfg *TerragruntConfig) SetFieldMetadataWithType(fieldType, fieldName string, m map[string]any)
- func (cfg *TerragruntConfig) String() string
- func (cfg *TerragruntConfig) ToRunConfig(l log.Logger) *runcfg.RunConfig
- func (cfg *TerragruntConfig) WriteTo(w io.Writer) (int64, error)
- type TerragruntConfigNotFoundError
- type TerragruntDependency
- type TerragruntOutputEncodingError
- type TerragruntOutputListEncodingError
- type TerragruntOutputParsingError
- type TerragruntOutputTargetNoOutputs
- type TooManyLevelsOfInheritanceError
- type TrackInclude
- type Unit
- type ValueWithMetadata
- type WrongNumberOfParamsError
Constants ¶
const ( DefaultTerragruntConfigPath = "terragrunt.hcl" DefaultStackFile = "terragrunt.stack.hcl" DefaultTerragruntJSONConfigPath = "terragrunt.hcl.json" RecommendedParentConfigName = "root.hcl" FoundInFile = "found_in_file" DefaultEngineType = "rpc" 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" MetadataIamRole = "iam_role" MetadataIamAssumeRoleDuration = "iam_assume_role_duration" MetadataIamAssumeRoleSessionName = "iam_assume_role_session_name" MetadataIamWebIdentityToken = "iam_web_identity_token" MetadataInputs = "inputs" MetadataLocals = "locals" MetadataLocal = "local" MetadataCatalog = "catalog" MetadataEngine = "engine" MetadataGenerateConfigs = "generate" MetadataDependentModules = "dependent_modules" MetadataInclude = "include" MetadataFeatureFlag = "feature" MetadataExclude = "exclude" MetadataErrors = "errors" MetadataRetry = "retry" MetadataIgnore = "ignore" MetadataValues = "values" MetadataStack = "stack" MetadataUnit = "unit" )
const ( FuncNameFindInParentFolders = "find_in_parent_folders" FuncNamePathRelativeToInclude = "path_relative_to_include" FuncNamePathRelativeFromInclude = "path_relative_from_include" FuncNameGetEnv = "get_env" FuncNameRunCmd = "run_cmd" FuncNameReadTerragruntConfig = "read_terragrunt_config" FuncNameGetPlatform = "get_platform" FuncNameGetRepoRoot = "get_repo_root" FuncNameGetPathFromRepoRoot = "get_path_from_repo_root" FuncNameGetPathToRepoRoot = "get_path_to_repo_root" FuncNameGetTerragruntDir = "get_terragrunt_dir" FuncNameGetOriginalTerragruntDir = "get_original_terragrunt_dir" FuncNameGetTerraformCommand = "get_terraform_command" FuncNameGetTerraformCLIArgs = "get_terraform_cli_args" FuncNameGetParentTerragruntDir = "get_parent_terragrunt_dir" FuncNameGetAWSAccountAlias = "get_aws_account_alias" FuncNameGetAWSAccountID = "get_aws_account_id" FuncNameGetAWSCallerIdentityArn = "get_aws_caller_identity_arn" FuncNameGetAWSCallerIdentityUserID = "get_aws_caller_identity_user_id" FuncNameGetTerraformCommandsThatNeedVars = "get_terraform_commands_that_need_vars" FuncNameGetTerraformCommandsThatNeedLocking = "get_terraform_commands_that_need_locking" FuncNameGetTerraformCommandsThatNeedInput = "get_terraform_commands_that_need_input" FuncNameGetTerraformCommandsThatNeedParallelism = "get_terraform_commands_that_need_parallelism" FuncNameSopsDecryptFile = "sops_decrypt_file" FuncNameGetTerragruntSourceCLIFlag = "get_terragrunt_source_cli_flag" FuncNameGetDefaultRetryableErrors = "get_default_retryable_errors" FuncNameReadTfvarsFile = "read_tfvars_file" FuncNameGetWorkingDir = "get_working_dir" FuncNameStartsWith = "startswith" FuncNameEndsWith = "endswith" FuncNameStrContains = "strcontains" FuncNameTimeCmp = "timecmp" FuncNameMarkAsRead = "mark_as_read" FuncNameConstraintCheck = "constraint_check" )
const ( HclCacheContextKey configKey = iota TerragruntConfigCacheContextKey configKey = iota RunCmdCacheContextKey configKey = iota DependencyOutputCacheContextKey configKey = iota JSONOutputCacheContextKey configKey = iota OutputLocksContextKey configKey = iota )
const ( TelemetryOpParseConfigFile = "parse_config_file" TelemetryOpParseBaseBlocks = "parse_base_blocks" TelemetryOpParseBaseBlocksResult = "parse_base_blocks_result" TelemetryOpParseDependencies = "parse_dependencies" TelemetryOpParseDependency = "parse_dependency" TelemetryOpParseConfigDecode = "parse_config_decode" TelemetryOpParseIncludeMerge = "parse_include_merge" )
Telemetry operation names for config parsing operations.
const ( AttrConfigPath = "config_path" AttrWorkingDir = "working_dir" AttrIsPartial = "is_partial" AttrDecodeList = "decode_list" AttrCacheHit = "cache_hit" AttrIncludeFromChild = "include_from_child" AttrIncludeChildPath = "include_child_path" AttrHasIncludes = "has_includes" AttrIncludeCount = "include_count" AttrIncludePaths = "include_paths" AttrDependencyCount = "dependency_count" AttrDependencyNames = "dependency_names" AttrDependencyName = "dependency_name" AttrDependencyPath = "dependency_path" AttrLocalsCount = "locals_count" AttrLocalsNames = "locals_names" AttrFeatureFlagCount = "feature_flag_count" AttrFeatureFlagNames = "feature_flag_names" AttrSkipOutputs = "skip_outputs_resolution" )
Telemetry attribute keys for config parsing operations.
const MaxIter = 1000
MaxIter is the maximum number of depth we support in recursively evaluating locals.
const ( // MaxParseDepth limits nested parsing to prevent stack overflow // from deeply recursive config structures (includes, dependencies, etc.). MaxParseDepth = 1000 )
const (
StackDir = ".terragrunt-stack"
)
Variables ¶
var ( // Order matters, for example if none of the files are found `GetDefaultConfigPath` func returns the last element. DefaultTerragruntConfigPaths = []string{ DefaultTerragruntJSONConfigPath, DefaultTerragruntConfigPath, } DefaultParserOptions = func(l log.Logger, opts *options.TerragruntOptions) []hclparse.Option { writer := writer.New( writer.WithLogger(l), writer.WithDefaultLevel(log.ErrorLevel), writer.WithMsgSeparator(logMsgSeparator), ) parseOpts := make([]hclparse.Option, 0, 3) parseOpts = append(parseOpts, hclparse.WithDiagnosticsWriter(writer, l.Formatter().DisabledColors()), hclparse.WithLogger(l), ) strictControl := opts.StrictControls.Find(controls.BareInclude) if strictControl != nil { strictControl.SuppressWarning() if err := strictControl.Evaluate(context.Background()); err != nil { return parseOpts } } parseOpts = append(parseOpts, hclparse.WithFileUpdate(updateBareIncludeBlock)) return parseOpts } DefaultGenerateBlockIfDisabledValueStr = codegen.DisabledSkipStr )
var TerraformCommandsNeedInput = []string{
"apply",
"import",
"init",
"plan",
"refresh",
}
TerraformCommandsNeedInput is list of terraform commands that accept -input=
var TerraformCommandsNeedLocking = []string{
"apply",
"destroy",
"import",
"plan",
"refresh",
"taint",
"untaint",
}
TerraformCommandsNeedLocking is a list of terraform commands that accept -lock-timeout
var TerraformCommandsNeedParallelism = []string{
"apply",
"plan",
"destroy",
}
TerraformCommandsNeedParallelism is a list of terraform commands that accept -parallelism=
var TerraformCommandsNeedVars = []string{
"apply",
"console",
"destroy",
"import",
"plan",
"push",
"refresh",
}
TerraformCommandsNeedVars is a list of terraform commands that accept -var or -var-file
Functions ¶
func ConstraintCheck ¶
ConstraintCheck Implementation of Terraform's StartsWith function
func ConvertValuesMapToCtyVal ¶
ConvertValuesMapToCtyVal takes a map of name - cty.Value pairs and converts to a single cty.Value object.
func CopyFieldsMetadata ¶
func CopyFieldsMetadata(sourceConfig *TerragruntConfig, targetConfig *TerragruntConfig)
CopyFieldsMetadata Copy fields metadata between TerragruntConfig instances.
func CopyLockFile ¶
func CopyLockFile(l log.Logger, opts *options.TerragruntOptions, sourceFolder, destinationFolder string) error
CopyLockFile copies the lock file from the source folder to the destination folder.
Terraform 0.14 now generates a lock file when you run `terraform init`. If any such file exists, this function will copy the lock file to the destination folder
func CtyToStruct ¶
CtyToStruct converts a cty.Value to a go struct.
func CtyValueAsString ¶
CtyValueAsString converts a cty.Value to a string.
func DetectDeprecatedConfigurations ¶
func DetectDeprecatedConfigurations(ctx context.Context, pctx *ParsingContext, l log.Logger, file *hclparse.File) error
DetectDeprecatedConfigurations detects if deprecated configurations are used in the given HCL file.
func DetectInputsCtyUsage ¶
DetectInputsCtyUsage detects if an identifier matching dependency.foo.inputs.bar is used in the given HCL file.
This is deprecated functionality, so we look for this to determine if we should throw an error or warning.
func EvaluateLocalsBlock ¶
func EvaluateLocalsBlock(ctx context.Context, pctx *ParsingContext, l log.Logger, file *hclparse.File) (map[string]cty.Value, error)
EvaluateLocalsBlock is a routine to evaluate the locals block in a way to allow references to other locals. This will:
- Extract a reference to the locals block from the parsed file
- Continuously evaluate the block until all references are evaluated, deferring evaluation of anything that references other locals until those references are evaluated.
This returns a map of the local names to the evaluated expressions (represented as `cty.Value` objects). This will error if there are remaining unevaluated locals after all references that can be evaluated has been evaluated.
func FindConfigFilesInPath ¶
func FindConfigFilesInPath(rootPath string, opts *options.TerragruntOptions) ([]string, error)
FindConfigFilesInPath 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 FindInParentFolders ¶
func FindInParentFolders( ctx context.Context, pctx *ParsingContext, l log.Logger, params []string, ) (string, error)
FindInParentFolders fings a parent Terragrunt configuration file in the parent folders above the current Terragrunt configuration file and return its path.
func FormatValue ¶
FormatValue converts a primitive value to its string representation.
func GenerateStackFile ¶
func GenerateStackFile(ctx context.Context, l log.Logger, opts *options.TerragruntOptions, pool *worker.Pool, stackFilePath string) error
GenerateStackFile generates the Terragrunt stack configuration from the given stackFilePath, reads necessary values, and generates units and stacks in the target directory. It handles the creation of required directories and returns any errors encountered.
func GetDefaultConfigPath ¶
GetDefaultConfigPath returns the default path to use for the Terragrunt configuration that exists within the path giving preference to `terragrunt.hcl`
func GetFirstKey ¶
GetFirstKey returns the first key from a map. This is a helper for maps that are known to have exactly one element.
func GetParentTerragruntDir ¶
func GetParentTerragruntDir(ctx context.Context, pctx *ParsingContext, l log.Logger, params []string) (string, error)
GetParentTerragruntDir returns the parent directory where the Terragrunt configuration file lives.
func GetTerraformSourceURL ¶
func GetTerraformSourceURL(terragruntOptions *options.TerragruntOptions, terragruntConfig *TerragruntConfig) (string, error)
GetTerraformSourceURL returns the source URL for OpenTofu/Terraform configuration.
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 GetTerragruntDir ¶
GetTerragruntDir returns the directory where the Terragrunt configuration file lives.
func GetTerragruntSourceForModule ¶
func GetTerragruntSourceForModule(sourcePath string, modulePath string, moduleTerragruntConfig *TerragruntConfig) (string, error)
GetTerragruntSourceForModule returns the source path for a module based on the source path of the parent module and the source path specified in the module's terragrunt.hcl file.
If one of the xxx-all commands is called with the --source parameter, then for each module, we need to build its own --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 --source parameter
Example:
--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 GetUnitDir ¶
GetUnitDir returns the directory path for a unit based on its no_dot_terragrunt_stack setting.
func GetValueString ¶
GetValueString returns the string representation of a cty.Value. If the value is of type cty.String, it returns the raw string value directly. Otherwise, it falls back to converting the value to a JSON-formatted string using the CtyValueAsString helper function.
Returns an error if the conversion fails.
func GoTypeToCty ¶
GoTypeToCty converts arbitrary go type (struct that has cty tags, slice, map with string keys, string, bool, int uint, float, cty.Value) to a cty Value
func IsComplexType ¶
IsComplexType checks if a value is a complex data type that can't be used with raw output.
func IsValidConfigPath ¶
IsValidConfigPath checks if a cty.Value is a valid, usable config path.
func ParseAndDecodeVarFile ¶
func ParseAndDecodeVarFile(l log.Logger, opts *options.TerragruntOptions, varFile string, fileContents []byte, out any) error
ParseAndDecodeVarFile uses the HCL2 file to parse the given varfile string into an HCL file body, and then decode it into the provided output.
func ParseRemoteState ¶
func ParseRemoteState(ctx context.Context, l log.Logger, opts *options.TerragruntOptions) (*remotestate.RemoteState, error)
ParseRemoteState reads the Terragrunt config file from its default location and parses and returns the `remote_state` block.
func ParseTerragruntConfig ¶
func ParseTerragruntConfig(ctx context.Context, pctx *ParsingContext, l log.Logger, configPath string, defaultVal *cty.Value) (cty.Value, error)
ParseTerragruntConfig parses the terragrunt config and return a representation that can be used as a reference. If given a default value, this will return the default if the terragrunt config file does not exist.
func PathRelativeFromInclude ¶
func PathRelativeFromInclude(ctx context.Context, pctx *ParsingContext, l log.Logger, params []string) (string, error)
PathRelativeFromInclude returns the relative path from the current Terragrunt configuration to the included Terragrunt configuration file
func PathRelativeToInclude ¶
func PathRelativeToInclude(ctx context.Context, pctx *ParsingContext, l log.Logger, params []string) (string, error)
PathRelativeToInclude returns the relative path between the included Terragrunt configuration file and the current Terragrunt configuration file. Name param is required and used to lookup the relevant import block when called in a child config with multiple import blocks.
func ReadValues ¶
func ReadValues(ctx context.Context, l log.Logger, opts *options.TerragruntOptions, directory string) (*cty.Value, error)
ReadValues reads values from the terragrunt.values.hcl file in the specified directory.
func RemoteStateAsCty ¶
func RemoteStateAsCty(remote *remotestate.RemoteState) (cty.Value, error)
RemoteStateAsCty serializes RemoteState to a cty Value. We can't directly serialize the struct because `config` and `encryption` are arbitrary interfaces whose type we do not know, so we have to do a hack to go through json.
func RunCommand ¶
func RunCommand(ctx context.Context, pctx *ParsingContext, l log.Logger, args []string) (string, error)
RunCommand is a helper function that runs a command and returns the stdout as the interpolation for each `run_cmd` in locals section, function is called twice result
func StartsWith ¶
StartsWith Implementation of Terraform's StartsWith function
func StrContains ¶
StrContains Implementation of Terraform's StrContains function
func TerraformOutputJSONToCtyValueMap ¶
func TerraformOutputJSONToCtyValueMap(targetConfigPath string, jsonBytes []byte) (map[string]cty.Value, error)
TerraformOutputJSONToCtyValueMap takes the terraform output json and converts to a mapping between output keys to the parsed cty.Value encoding of the json objects.
func TerragruntConfigAsCty ¶
func TerragruntConfigAsCty(config *TerragruntConfig) (cty.Value, error)
TerragruntConfigAsCty serializes 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)
func TraceParseBaseBlocksResult ¶
func TraceParseBaseBlocksResult( ctx context.Context, configPath string, baseBlocks *DecodedBaseBlocks, )
TraceParseBaseBlocksResult adds result attributes to the current span from context.
func TraceParseConfigDecode ¶
func TraceParseConfigDecode( ctx context.Context, configPath string, fn func(ctx context.Context) error, ) error
TraceParseConfigDecode wraps config decoding with telemetry.
func TraceParseConfigFile ¶
func TraceParseConfigFile( ctx context.Context, configPath string, workingDir string, isPartial bool, decodeList []PartialDecodeSectionType, includeFromChild *IncludeConfig, cacheHit bool, fn func(ctx context.Context) error, ) error
TraceParseConfigFile wraps a config file parsing operation with telemetry.
func TraceParseDependencies ¶
func TraceParseDependencies( ctx context.Context, configPath string, skipOutputsResolution bool, dependencyCount int, dependencyNames []string, fn func(ctx context.Context) error, ) error
TraceParseDependencies wraps dependency parsing with telemetry.
func TraceParseDependency ¶
func TraceParseDependency( ctx context.Context, dependencyName string, dependencyPath string, fn func(ctx context.Context) error, ) error
TraceParseDependency wraps individual dependency output resolution with telemetry.
func TraceParseIncludeMerge ¶
func TraceParseIncludeMerge( ctx context.Context, configPath string, includeCount int, includePaths []string, fn func(ctx context.Context) error, ) error
TraceParseIncludeMerge wraps include merging with telemetry.
func ValidateStackConfig ¶
func ValidateStackConfig(config *StackConfigFile) error
ValidateStackConfig validates a StackConfigFile instance according to the rules: - Unit name, source, and path shouldn't be empty - Unit names should be unique - Units shouldn't have duplicate paths - Stack name, source, and path shouldn't be empty - Stack names should be unique - Stack shouldn't have duplicate paths
Types ¶
type CatalogConfig ¶
type CatalogConfig struct {
NoShell *bool `hcl:"no_shell,optional" cty:"no_shell"`
NoHooks *bool `hcl:"no_hooks,optional" cty:"no_hooks"`
DefaultTemplate string `hcl:"default_template,optional" cty:"default_template"`
URLs []string `hcl:"urls,attr" cty:"urls"`
}
func ReadCatalogConfig ¶
func ReadCatalogConfig(parentCtx context.Context, l log.Logger, opts *options.TerragruntOptions) (*CatalogConfig, error)
ReadCatalogConfig reads the `catalog` block from the nearest `terragrunt.hcl` file in the parent directories.
We want users to be able to browse to any folder in an `infra-live` repo, run `terragrunt catalog` (with no URL) arg. ReadCatalogConfig looks for the "nearest" `terragrunt.hcl` in the parent directories if the given `opts.TerragruntConfigPath` does not exist. Since our normal parsing `ParseConfig` does not always work, as some `terragrunt.hcl` files are meant to be used from an `include` and/or they might use `find_in_parent_folders` and they only work from certain child folders, it parses this file to see if the config contains `include{...find_in_parent_folders()...}` block to determine if it is the root configuration. If it finds `terragrunt.hcl` that already has `include`, then read that configuration as is, otherwise generate a stub child `terragrunt.hcl` in memory with an `include` to pull in the one we found. Unlike the "ReadTerragruntConfig" func, it ignores any configuration errors not related to the "catalog" block.
func (*CatalogConfig) String ¶
func (cfg *CatalogConfig) String() string
type ConflictingRunCmdCacheOptionsError ¶
type ConflictingRunCmdCacheOptionsError struct{}
func (ConflictingRunCmdCacheOptionsError) Error ¶
func (err ConflictingRunCmdCacheOptionsError) Error() string
type CouldNotEvaluateAllLocalsError ¶
type CouldNotEvaluateAllLocalsError struct {
Err error
}
func (CouldNotEvaluateAllLocalsError) Error ¶
func (err CouldNotEvaluateAllLocalsError) Error() string
func (CouldNotEvaluateAllLocalsError) Unwrap ¶
func (err CouldNotEvaluateAllLocalsError) Unwrap() error
type CouldNotResolveTerragruntConfigInFileError ¶
type CouldNotResolveTerragruntConfigInFileError string
func (CouldNotResolveTerragruntConfigInFileError) Error ¶
func (err CouldNotResolveTerragruntConfigInFileError) Error() string
type CtyTerraformConfig ¶
type CtyTerraformConfig struct {
ExtraArgs map[string]TerraformExtraArguments `cty:"extra_arguments"`
Source *string `cty:"source"`
IncludeInCopy *[]string `cty:"include_in_copy"`
ExcludeFromCopy *[]string `cty:"exclude_from_copy"`
CopyTerraformLockFile *bool `cty:"copy_terraform_lock_file"`
BeforeHooks map[string]Hook `cty:"before_hook"`
AfterHooks map[string]Hook `cty:"after_hook"`
ErrorHooks map[string]ErrorHook `cty:"error_hook"`
}
CtyTerraformConfig is an alternate representation of TerraformConfig that converts internal blocks into a map that maps the name to the underlying struct, as opposed to a list representation.
type DecodedBaseBlocks ¶
type DecodedBaseBlocks struct {
TrackInclude *TrackInclude
Locals *cty.Value
FeatureFlags *cty.Value
}
DecodedBaseBlocks decoded base blocks struct
func DecodeBaseBlocks ¶
func DecodeBaseBlocks(ctx context.Context, pctx *ParsingContext, l log.Logger, file *hclparse.File, includeFromChild *IncludeConfig) (*DecodedBaseBlocks, 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 - features - include
func TraceParseBaseBlocks ¶
func TraceParseBaseBlocks( ctx context.Context, l log.Logger, configPath string, fn func(ctx context.Context) (*DecodedBaseBlocks, error), ) (*DecodedBaseBlocks, error)
TraceParseBaseBlocks wraps base blocks parsing with telemetry.
type Dependencies ¶
type Dependencies []Dependency
func (Dependencies) FilteredWithoutConfigPath ¶
func (deps Dependencies) FilteredWithoutConfigPath() Dependencies
type Dependency ¶
type Dependency struct {
ConfigPath cty.Value `hcl:"config_path,attr" cty:"config_path"`
Enabled *bool `hcl:"enabled,attr" cty:"enabled"`
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"`
Inputs *cty.Value `cty:"inputs"`
Name string `hcl:",label" cty:"name"`
}
func (*Dependency) DeepMerge ¶
func (dep *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 DependencyCycleError ¶
type DependencyCycleError []string
func (DependencyCycleError) Error ¶
func (err DependencyCycleError) Error() string
type DependencyDirNotFoundError ¶
type DependencyDirNotFoundError struct {
Dir []string
}
func (DependencyDirNotFoundError) Error ¶
func (err DependencyDirNotFoundError) Error() string
type DependencyFileNotFoundError ¶
type DependencyFileNotFoundError struct {
Path string
}
func (DependencyFileNotFoundError) Error ¶
func (err DependencyFileNotFoundError) Error() string
type DependencyInvalidConfigPathError ¶
type DependencyInvalidConfigPathError struct {
DependencyName string
}
func (DependencyInvalidConfigPathError) Error ¶
func (err DependencyInvalidConfigPathError) Error() string
type DuplicatedGenerateBlocksError ¶
type DuplicatedGenerateBlocksError struct {
BlockName []string
}
func (DuplicatedGenerateBlocksError) Error ¶
func (err DuplicatedGenerateBlocksError) Error() string
type EmptyStringNotAllowedError ¶
type EmptyStringNotAllowedError string
func (EmptyStringNotAllowedError) Error ¶
func (err EmptyStringNotAllowedError) Error() string
type EngineConfig ¶
type EngineConfig struct {
Version *string `hcl:"version,attr" cty:"version"`
Type *string `hcl:"type,attr" cty:"type"`
Meta *cty.Value `hcl:"meta,attr" cty:"meta"`
Source string `hcl:"source,attr" cty:"source"`
}
EngineConfig represents the structure of the HCL data
func (*EngineConfig) Clone ¶
func (c *EngineConfig) Clone() *EngineConfig
Clone returns a copy of the EngineConfig used in deep copy
func (*EngineConfig) Merge ¶
func (c *EngineConfig) Merge(engine *EngineConfig)
Merge merges the EngineConfig with another EngineConfig
type EnvVarNotFoundError ¶
type EnvVarNotFoundError struct {
EnvVar string
}
func (EnvVarNotFoundError) Error ¶
func (err EnvVarNotFoundError) Error() string
type ErrorHook ¶
type ErrorHook struct {
SuppressStdout *bool `hcl:"suppress_stdout,attr" cty:"suppress_stdout"`
WorkingDir *string `hcl:"working_dir,attr" cty:"working_dir"`
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"`
}
type ErrorsConfig ¶
type ErrorsConfig struct {
Retry []*RetryBlock `cty:"retry" hcl:"retry,block"`
Ignore []*IgnoreBlock `cty:"ignore" hcl:"ignore,block"`
}
ErrorsConfig represents the top-level errors configuration
func (*ErrorsConfig) Clone ¶
func (c *ErrorsConfig) Clone() *ErrorsConfig
Clone returns a deep copy of ErrorsConfig
func (*ErrorsConfig) Merge ¶
func (c *ErrorsConfig) Merge(other *ErrorsConfig)
Merge combines the current ErrorsConfig with another one, prioritizing the other config
type ExcludeConfig ¶
type ExcludeConfig struct {
ExcludeDependencies *bool `cty:"exclude_dependencies" hcl:"exclude_dependencies,attr" json:"exclude_dependencies"`
NoRun *bool `cty:"no_run" hcl:"no_run,attr" json:"no_run"`
Actions []string `cty:"actions" hcl:"actions,attr" json:"actions"`
If bool `cty:"if" hcl:"if,attr" json:"if"`
}
ExcludeConfig configurations for hcl files.
func (*ExcludeConfig) Clone ¶
func (e *ExcludeConfig) Clone() *ExcludeConfig
Clone returns a new instance of ExcludeConfig with the same values as the original.
func (*ExcludeConfig) IsActionListed ¶
func (e *ExcludeConfig) IsActionListed(action string) bool
IsActionListed checks if the action is listed in the exclude block.
func (*ExcludeConfig) Merge ¶
func (e *ExcludeConfig) Merge(exclude *ExcludeConfig)
Merge merges the values of the provided ExcludeConfig into the original.
func (*ExcludeConfig) ShouldPreventRun ¶
func (e *ExcludeConfig) ShouldPreventRun(action string) bool
ShouldPreventRun checks if the unit should be prevented from running based on the no_run attribute and current action.
type FeatureFlag ¶
type FeatureFlag struct {
Default *cty.Value `cty:"default" hcl:"default,attr"`
Name string `cty:"name" hcl:",label"`
}
FeatureFlag feature flags struct.
func (*FeatureFlag) DeepMerge ¶
func (feature *FeatureFlag) DeepMerge(source *FeatureFlag) error
DeepMerge merges the source FeatureFlag into the target FeatureFlag.
func (*FeatureFlag) DefaultAsString ¶
func (feature *FeatureFlag) DefaultAsString() (string, error)
DefaultAsString returns the default value of the feature flag as a string.
type FeatureFlags ¶
type FeatureFlags []*FeatureFlag
FeatureFlags represents a list of feature flags.
type Hook ¶
type Hook struct {
If *bool `hcl:"if,attr" cty:"if"`
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"`
Name string `hcl:"name,label" cty:"name"`
Commands []string `hcl:"commands,attr" cty:"commands"`
Execute []string `hcl:"execute,attr" cty:"execute"`
}
Hook specifies terraform commands (apply/plan) and array of os commands to execute
type IgnoreBlock ¶
type IgnoreBlock struct {
Signals map[string]cty.Value `cty:"signals" hcl:"signals,optional"`
Label string `cty:"name" hcl:"name,label"`
Message string `cty:"message" hcl:"message,optional"`
IgnorableErrors []string `cty:"ignorable_errors" hcl:"ignorable_errors"`
}
IgnoreBlock represents a labeled ignore block
func (*IgnoreBlock) Clone ¶
func (i *IgnoreBlock) Clone() *IgnoreBlock
Clone returns a deep copy of an IgnoreBlock
type IncludeConfig ¶
type IncludeConfig struct {
Expose *bool `hcl:"expose,attr"`
MergeStrategy *string `hcl:"merge_strategy,attr"`
Name string `hcl:"name,label"`
Path string `hcl:"path,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 (include *IncludeConfig) GetExpose() bool
func (*IncludeConfig) GetMergeStrategy ¶
func (include *IncludeConfig) GetMergeStrategy() (MergeStrategyType, error)
func (*IncludeConfig) String ¶
func (include *IncludeConfig) String() string
type IncludeConfigNotFoundError ¶
func (IncludeConfigNotFoundError) Error ¶
func (err IncludeConfigNotFoundError) Error() string
type IncludeConfigs ¶
type IncludeConfigs []IncludeConfig
type IncludeConfigsMap ¶
type IncludeConfigsMap map[string]IncludeConfig
func (IncludeConfigsMap) ContainsPath ¶
func (cfgs IncludeConfigsMap) 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 IncludedConfigMissingPathError ¶
type IncludedConfigMissingPathError string
func (IncludedConfigMissingPathError) Error ¶
func (err IncludedConfigMissingPathError) Error() string
type InvalidArgError ¶
type InvalidArgError string
func (InvalidArgError) Error ¶
func (e InvalidArgError) Error() string
type InvalidEnvParamNameError ¶
type InvalidEnvParamNameError struct {
EnvName string
}
func (InvalidEnvParamNameError) Error ¶
func (err InvalidEnvParamNameError) Error() string
type InvalidGetEnvParamsError ¶
func (InvalidGetEnvParamsError) Error ¶
func (err InvalidGetEnvParamsError) Error() string
type InvalidIncludeKeyError ¶
type InvalidIncludeKeyError struct {
// contains filtered or unexported fields
}
func (InvalidIncludeKeyError) Error ¶
func (err InvalidIncludeKeyError) Error() string
type InvalidMergeStrategyTypeError ¶
type InvalidMergeStrategyTypeError string
func (InvalidMergeStrategyTypeError) Error ¶
func (err InvalidMergeStrategyTypeError) Error() string
type InvalidParameterTypeError ¶
func (InvalidParameterTypeError) Error ¶
func (err InvalidParameterTypeError) Error() string
type InvalidPartialBlockName ¶
type InvalidPartialBlockName struct {
// contains filtered or unexported fields
}
func (InvalidPartialBlockName) Error ¶
func (err InvalidPartialBlockName) Error() string
type InvalidSopsFormatError ¶
type InvalidSopsFormatError struct {
SourceFilePath string
}
func (InvalidSopsFormatError) Error ¶
func (err InvalidSopsFormatError) Error() string
type InvalidSourceURLError ¶
type InvalidSourceURLError struct {
ModulePath string
ModuleSourceURL string
TerragruntSource string
}
func (InvalidSourceURLError) Error ¶
func (err InvalidSourceURLError) Error() string
type InvalidSourceURLWithMapError ¶
func (InvalidSourceURLWithMapError) Error ¶
func (err InvalidSourceURLWithMapError) Error() string
type MaxIterError ¶
type MaxIterError struct{}
func (MaxIterError) Error ¶
func (err MaxIterError) Error() string
type MaxParseDepthError ¶ added in v0.99.0
MaxParseDepthError is returned when config parsing exceeds the maximum allowed depth.
func (MaxParseDepthError) Error ¶ added in v0.99.0
func (err MaxParseDepthError) 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 ¶
func (err MultipleBareIncludeBlocksErr) Error() string
type ParentFileNotFoundError ¶
func (ParentFileNotFoundError) Error ¶
func (err ParentFileNotFoundError) Error() string
type ParsedVariable ¶
type ParsedVariable struct {
Name string
Description string
Type string
DefaultValue string
DefaultValuePlaceholder string
}
ParsedVariable structure with input name, default value and description.
func ParseVariables ¶
func ParseVariables(l log.Logger, opts *options.TerragruntOptions, directoryPath string) ([]*ParsedVariable, error)
ParseVariables - parse variables from tf files.
type ParsingContext ¶
type ParsingContext struct {
TerragruntOptions *options.TerragruntOptions
// TrackInclude represents contexts of included configurations.
TrackInclude *TrackInclude
// Locals are pre-evaluated variable bindings that can be used by reference in the code.
Locals *cty.Value
// Features are the feature flags that are enabled for the current terragrunt config.
Features *cty.Value
// Values of the unit.
Values *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
// These functions have the highest priority and will overwrite any others with the same name
PredefinedFunctions map[string]function.Function
// Set a custom converter to TerragruntConfig.
// Used to read a "catalog" configuration where only certain blocks (`catalog`, `locals`) do not need to be converted, avoiding errors if any of the remaining blocks were not evaluated correctly.
ConvertToTerragruntConfigFunc func(ctx context.Context, pctx *ParsingContext, configPath string, terragruntConfigFromFile *terragruntConfigFile) (cfg *TerragruntConfig, err error)
// FilesRead tracks files that were read during parsing (absolute paths).
// This is a pointer so that it's shared across all parsing context copies.
FilesRead *[]string
// 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 ctx is partial, meaning that not all configuration values are
// expected to be available.
PartialParseDecodeList []PartialDecodeSectionType
// ParserOptions is used to configure hcl Parser.
ParserOptions []hclparse.Option
// SkipOutputsResolution is used to optionally opt-out of resolving outputs.
SkipOutputsResolution bool
// ParseDepth tracks the current parsing recursion depth.
// This prevents stack overflow from deeply nested configs.
ParseDepth int
}
ParsingContext provides various variables that are used throughout all funcs and passed from function to function. Using `ParsingContext` makes the code more readable. Note: context.Context should be passed explicitly as the first parameter to functions, not embedded in this struct.
func NewParsingContext ¶
func NewParsingContext(ctx context.Context, l log.Logger, opts *options.TerragruntOptions) (context.Context, *ParsingContext)
func (*ParsingContext) Clone ¶
func (ctx *ParsingContext) Clone() *ParsingContext
Clone returns a shallow copy of the ParsingContext.
func (*ParsingContext) WithDecodeList ¶
func (ctx *ParsingContext) WithDecodeList(decodeList ...PartialDecodeSectionType) *ParsingContext
func (*ParsingContext) WithDecodedDependencies ¶
func (ctx *ParsingContext) WithDecodedDependencies(v *cty.Value) *ParsingContext
func (*ParsingContext) WithDiagnosticsSuppressed ¶
func (ctx *ParsingContext) WithDiagnosticsSuppressed(l log.Logger) *ParsingContext
WithDiagnosticsSuppressed returns a new ParsingContext with diagnostics suppressed. Diagnostics are written to stderr in debug mode for troubleshooting, otherwise discarded. This avoids false positive "There is no variable named dependency" errors during parsing when dependency outputs haven't been resolved yet.
func (*ParsingContext) WithFeatures ¶
func (ctx *ParsingContext) WithFeatures(features *cty.Value) *ParsingContext
WithFeatures sets the feature flags to be used in evaluation context.
func (*ParsingContext) WithIncrementedDepth ¶ added in v0.99.0
func (ctx *ParsingContext) WithIncrementedDepth() (*ParsingContext, error)
WithIncrementedDepth returns a new ParsingContext with incremented parse depth. Returns an error if the maximum depth would be exceeded.
func (*ParsingContext) WithLocals ¶
func (ctx *ParsingContext) WithLocals(locals *cty.Value) *ParsingContext
func (*ParsingContext) WithParseOption ¶
func (ctx *ParsingContext) WithParseOption(parserOptions []hclparse.Option) *ParsingContext
func (*ParsingContext) WithSkipOutputsResolution ¶
func (ctx *ParsingContext) WithSkipOutputsResolution() *ParsingContext
func (*ParsingContext) WithTerragruntOptions ¶
func (ctx *ParsingContext) WithTerragruntOptions(opts *options.TerragruntOptions) *ParsingContext
func (*ParsingContext) WithTrackInclude ¶
func (ctx *ParsingContext) WithTrackInclude(trackInclude *TrackInclude) *ParsingContext
func (*ParsingContext) WithValues ¶
func (ctx *ParsingContext) WithValues(values *cty.Value) *ParsingContext
type ParsingModulePathError ¶
type ParsingModulePathError struct {
ModuleSourceURL string
}
func (ParsingModulePathError) Error ¶
func (err ParsingModulePathError) 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 FeatureFlagsBlock EngineBlock ExcludeBlock ErrorsBlock )
type RetryBlock ¶
type RetryBlock struct {
Label string `cty:"name" hcl:"name,label"`
RetryableErrors []string `cty:"retryable_errors" hcl:"retryable_errors"`
MaxAttempts int `cty:"max_attempts" hcl:"max_attempts"`
SleepIntervalSec int `cty:"sleep_interval_sec" hcl:"sleep_interval_sec"`
}
RetryBlock represents a labeled retry block
func (*RetryBlock) Clone ¶
func (r *RetryBlock) Clone() *RetryBlock
Clone returns a deep copy of a RetryBlock
type Stack ¶
type Stack struct {
NoStack *bool `hcl:"no_dot_terragrunt_stack,attr"`
NoValidation *bool `hcl:"no_validation,attr"`
Values *cty.Value `hcl:"values,attr"`
Name string `hcl:",label"`
Source string `hcl:"source,attr"`
Path string `hcl:"path,attr"`
}
Stack represents the stack block in the configuration.
type StackConfig ¶
StackConfig represents the structure of terragrunt.stack.hcl stack file.
func ParseStackConfig ¶
func ParseStackConfig(ctx context.Context, l log.Logger, parser *ParsingContext, opts *options.TerragruntOptions, file *hclparse.File, values *cty.Value) (*StackConfig, error)
ParseStackConfig parses the stack configuration from the given file and values.
func ReadStackConfigFile ¶
func ReadStackConfigFile(ctx context.Context, l log.Logger, opts *options.TerragruntOptions, filePath string, values *cty.Value) (*StackConfig, error)
ReadStackConfigFile reads and parses a Terragrunt stack configuration file from the given path. It creates a parsing context, processes locals, and decodes the file into a StackConfig struct. Validation is performed on the resulting config, and any encountered errors cause an early return.
func ReadStackConfigString ¶
func ReadStackConfigString( ctx context.Context, l log.Logger, opts *options.TerragruntOptions, configPath string, configString string, values *cty.Value, ) (*StackConfig, error)
ReadStackConfigString reads and parses a Terragrunt stack configuration from a string.
type StackConfigFile ¶
type StackConfigFile struct {
Locals *terragruntLocal `hcl:"locals,block"`
Stacks []*Stack `hcl:"stack,block"`
Units []*Unit `hcl:"unit,block"`
}
StackConfigFile represents the structure of terragrunt.stack.hcl stack file.
type TFVarFileNotFoundError ¶
func (TFVarFileNotFoundError) Error ¶
func (err TFVarFileNotFoundError) Error() string
type TerraformConfig ¶
type TerraformConfig struct {
Source *string `hcl:"source,attr"`
// 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"`
ExcludeFromCopy *[]string `hcl:"exclude_from_copy,attr"`
CopyTerraformLockFile *bool `hcl:"copy_terraform_lock_file,attr"`
ExtraArgs []TerraformExtraArguments `hcl:"extra_arguments,block"`
BeforeHooks []Hook `hcl:"before_hook,block"`
AfterHooks []Hook `hcl:"after_hook,block"`
ErrorHooks []ErrorHook `hcl:"error_hook,block"`
}
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 (cfg *TerraformConfig) GetAfterHooks() []Hook
func (*TerraformConfig) GetBeforeHooks ¶
func (cfg *TerraformConfig) GetBeforeHooks() []Hook
func (*TerraformConfig) GetErrorHooks ¶
func (cfg *TerraformConfig) GetErrorHooks() []ErrorHook
func (*TerraformConfig) String ¶
func (cfg *TerraformConfig) String() string
func (*TerraformConfig) ValidateHooks ¶
func (cfg *TerraformConfig) ValidateHooks() error
type TerraformExtraArguments ¶
type TerraformExtraArguments struct {
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"`
EnvVars *map[string]string `hcl:"env_vars,attr" cty:"env_vars"`
Name string `hcl:"name,label" cty:"name"`
Commands []string `hcl:"commands,attr" cty:"commands"`
}
TerraformExtraArguments sets a list of arguments to pass to Terraform if command fits any in the `Commands` list
func (*TerraformExtraArguments) GetVarFiles ¶
func (args *TerraformExtraArguments) GetVarFiles(l log.Logger) []string
func (*TerraformExtraArguments) String ¶
func (args *TerraformExtraArguments) String() string
type TerragruntConfig ¶
type TerragruntConfig struct {
Locals map[string]any
ProcessedIncludes IncludeConfigsMap
FieldsMetadata map[string]map[string]any
Terraform *TerraformConfig
Errors *ErrorsConfig
RemoteState *remotestate.RemoteState
Dependencies *ModuleDependencies
Exclude *ExcludeConfig
PreventDestroy *bool
GenerateConfigs map[string]codegen.GenerateConfig
IamAssumeRoleDuration *int64
Inputs map[string]any
Engine *EngineConfig
Catalog *CatalogConfig
IamWebIdentityToken string
IamAssumeRoleSessionName string
IamRole string
DownloadDir string
TerragruntVersionConstraint string
TerraformVersionConstraint string
TerraformBinary string
TerragruntDependencies Dependencies
FeatureFlags FeatureFlags
DependentModulesPath []*string
IsPartial bool
}
TerragruntConfig represents a parsed and expanded configuration NOTE: if any attributes are added, make sure to update terragruntConfigAsCty in config_as_cty.go
func ParseConfig ¶
func ParseConfig( ctx context.Context, pctx *ParsingContext, l log.Logger, file *hclparse.File, includeFromChild *IncludeConfig, ) (*TerragruntConfig, error)
ParseConfig parses the Terragrunt config contained in the given hcl file 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:
- 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.
- 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/gruntwork-io/terragrunt/issues/814 Allowed References: - locals
- 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
- 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
- Merge the included config with the parsed config. Note that all the config data is mergeable except for `locals` blocks, which are only scoped to be available within the defining config.
func ParseConfigFile ¶
func ParseConfigFile( ctx context.Context, pctx *ParsingContext, l log.Logger, configPath string, includeFromChild *IncludeConfig, ) (*TerragruntConfig, error)
ParseConfigFile parses 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(ctx context.Context, pctx *ParsingContext, l log.Logger, configPath string, configString string, includeFromChild *IncludeConfig) (*TerragruntConfig, error)
func PartialParseConfig ¶
func PartialParseConfig(ctx context.Context, pctx *ParsingContext, l log.Logger, file *hclparse.File, includeFromChild *IncludeConfig) (*TerragruntConfig, error)
func PartialParseConfigFile ¶
func PartialParseConfigFile(ctx context.Context, pctx *ParsingContext, l log.Logger, configPath string, include *IncludeConfig) (*TerragruntConfig, error)
func PartialParseConfigString ¶
func PartialParseConfigString(ctx context.Context, pctx *ParsingContext, l log.Logger, configPath, configString string, include *IncludeConfig) (*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
- FeatureFlagsBlock: Parses the `feature` block in the config
- EngineBlock: Parses the `engine` block in the config
- ExcludeBlock : Parses the `exclude` 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(ctx context.Context, l log.Logger, opts *options.TerragruntOptions, parserOptions []hclparse.Option, ) (*TerragruntConfig, error)
ReadTerragruntConfig reads the Terragrunt config file from its default location
func TerragruntConfigFromPartialConfig ¶
func TerragruntConfigFromPartialConfig(ctx context.Context, pctx *ParsingContext, l log.Logger, file *hclparse.File, includeFromChild *IncludeConfig) (*TerragruntConfig, error)
TerragruntConfigFromPartialConfig is a 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 (cfg *TerragruntConfig) DeepMerge(l log.Logger, 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) EngineOptions ¶
func (cfg *TerragruntConfig) EngineOptions() (*options.EngineOptions, error)
EngineOptions fetch engine options
func (*TerragruntConfig) ErrorsConfig ¶
func (cfg *TerragruntConfig) ErrorsConfig() (*options.ErrorsConfig, error)
ErrorsConfig fetch errors configuration for options package
func (*TerragruntConfig) GetFieldMetadata ¶
func (cfg *TerragruntConfig) GetFieldMetadata(fieldName string) (map[string]string, bool)
GetFieldMetadata return field metadata by field name.
func (*TerragruntConfig) GetIAMRoleOptions ¶
func (cfg *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 (cfg *TerragruntConfig) GetMapFieldMetadata(fieldType, fieldName string) (map[string]string, bool)
GetMapFieldMetadata return field metadata by field type and name.
func (*TerragruntConfig) GetRemoteState ¶
func (cfg *TerragruntConfig) GetRemoteState(l log.Logger, opts *options.TerragruntOptions) (*remotestate.RemoteState, error)
func (*TerragruntConfig) Merge ¶
func (cfg *TerragruntConfig) Merge(l log.Logger, 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 (cfg *TerragruntConfig) SetFieldMetadata(fieldName string, m map[string]any)
SetFieldMetadata set metadata on the given field name.
func (*TerragruntConfig) SetFieldMetadataMap ¶
func (cfg *TerragruntConfig) SetFieldMetadataMap(field string, data map[string]any, metadata map[string]any)
SetFieldMetadataMap set metadata on fields from map keys. Example usage - setting metadata on all variables from inputs.
func (*TerragruntConfig) SetFieldMetadataWithType ¶
func (cfg *TerragruntConfig) SetFieldMetadataWithType(fieldType, fieldName string, m map[string]any)
SetFieldMetadataWithType set metadata on the given field name grouped by type. Example usage - setting metadata on different dependencies, locals, inputs.
func (*TerragruntConfig) String ¶
func (cfg *TerragruntConfig) String() string
func (*TerragruntConfig) ToRunConfig ¶ added in v0.99.0
func (cfg *TerragruntConfig) ToRunConfig(l log.Logger) *runcfg.RunConfig
ToRunConfig translates a TerragruntConfig to a runcfg.RunConfig. This is the primary method for converting config types to runner types.
type TerragruntConfigNotFoundError ¶
type TerragruntConfigNotFoundError struct {
Path string
}
func (TerragruntConfigNotFoundError) Error ¶
func (err TerragruntConfigNotFoundError) Error() string
type TerragruntDependency ¶
type TerragruntDependency struct {
Remain hcl.Body `hcl:",remain"`
Dependencies Dependencies `hcl:"dependency,block"`
}
TerragruntDependency is a struct that can be used to only decode the dependency blocks in the terragrunt config
type TerragruntOutputEncodingError ¶
func (TerragruntOutputEncodingError) Error ¶
func (err TerragruntOutputEncodingError) Error() string
type TerragruntOutputListEncodingError ¶
func (TerragruntOutputListEncodingError) Error ¶
func (err TerragruntOutputListEncodingError) Error() string
type TerragruntOutputParsingError ¶
func (TerragruntOutputParsingError) Error ¶
func (err TerragruntOutputParsingError) Error() string
type TerragruntOutputTargetNoOutputs ¶
type TerragruntOutputTargetNoOutputs struct {
// contains filtered or unexported fields
}
func (TerragruntOutputTargetNoOutputs) Error ¶
func (err TerragruntOutputTargetNoOutputs) Error() string
func (TerragruntOutputTargetNoOutputs) ExitCode ¶
func (err TerragruntOutputTargetNoOutputs) ExitCode() int
func (TerragruntOutputTargetNoOutputs) Unwrap ¶
func (err TerragruntOutputTargetNoOutputs) Unwrap() error
type TooManyLevelsOfInheritanceError ¶
type TooManyLevelsOfInheritanceError struct {
ConfigPath string
FirstLevelIncludePath string
SecondLevelIncludePath string
}
func (TooManyLevelsOfInheritanceError) Error ¶
func (err TooManyLevelsOfInheritanceError) Error() string
type TrackInclude ¶
type TrackInclude struct {
// 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
// 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 IncludeConfigs
}
TrackInclude is used to differentiate between an included config in the current parsing ctx, and an included config that was passed through from a previous parsing ctx.
type Unit ¶
type Unit struct {
NoStack *bool `hcl:"no_dot_terragrunt_stack,attr"`
NoValidation *bool `hcl:"no_validation,attr"`
Values *cty.Value `hcl:"values,attr"`
Name string `hcl:",label"`
Source string `hcl:"source,attr"`
Path string `hcl:"path,attr"`
}
Unit represents unit from a stack file.
func (*Unit) ReadOutputs ¶
func (u *Unit) ReadOutputs(ctx context.Context, l log.Logger, opts *options.TerragruntOptions, unitDir string) (map[string]cty.Value, error)
ReadOutputs retrieves the OpenTofu/Terraform output JSON for this unit, converts it into a map of cty.Values, and logs the operation for debugging. It returns early in case of any errors during retrieval or conversion.
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 WrongNumberOfParamsError ¶
func (WrongNumberOfParamsError) Error ¶
func (err WrongNumberOfParamsError) Error() string