diff --git a/config/dependency.go b/config/dependency.go index 69bd799f15..108e61ada0 100644 --- a/config/dependency.go +++ b/config/dependency.go @@ -514,6 +514,8 @@ func getTerragruntOutputIfAppliedElseConfiguredDefault(ctx *ParsingContext, depe // returning mocks is not allowed. So return a useful error message indicating that we expected outputs, but they // did not exist. err := TerragruntOutputTargetNoOutputs{ + targetName: dependencyConfig.Name, + targetPath: dependencyConfig.ConfigPath.AsString(), targetConfig: targetConfig, currentConfig: ctx.TerragruntOptions.TerragruntConfigPath, } diff --git a/config/errors.go b/config/errors.go index 86a9ef1596..477a50f609 100644 --- a/config/errors.go +++ b/config/errors.go @@ -226,15 +226,45 @@ func (err TerragruntOutputListEncodingError) Error() string { } type TerragruntOutputTargetNoOutputs struct { + targetName string + targetPath string targetConfig string currentConfig string } +func (err TerragruntOutputTargetNoOutputs) ExitCode() int { + return 1 +} + +func (err TerragruntOutputTargetNoOutputs) Unwrap() error { + return nil +} + func (err TerragruntOutputTargetNoOutputs) Error() string { + msg := ` +If this dependency is accessed before the outputs are ready (which can happen during the planning phase of an unapplied stack), consider using mock_outputs. +e.g. + +dependency "` + err.targetName + `" { + config_path = "` + err.targetPath + `" + + mock_outputs = { + ` + err.targetName + `_output = "mock-` + err.targetName + `-output" + } +} + +For further details, refer to this resource: +https://terragrunt.gruntwork.io/docs/features/stacks/#unapplied-dependency-and-mock-outputs + +If you do not require outputs from your dependency, consider using the dependencies block instead: +https://terragrunt.gruntwork.io/docs/reference/config-blocks-and-attributes/#dependencies +` + return fmt.Sprintf( - "%s is a dependency of %s but detected no outputs. Either the target module has not been applied yet, or the module has no outputs. If this is expected, set the skip_outputs flag to true on the dependency block.", + "%s is a dependency of %s but detected no outputs. Either the target module has not been applied yet, or the module has no outputs. If this is expected, set the skip_outputs flag to true on the dependency block.\n%s", err.targetConfig, err.currentConfig, + msg, ) }