Skip to content

Commit 5792581

Browse files
authored
Remove InitNeededButDisabled error and instead log a warning (gruntwork-io#1549)
1 parent b4f39d2 commit 5792581

File tree

5 files changed

+31
-7
lines changed

5 files changed

+31
-7
lines changed

cli/cli_app.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,8 @@ func runTerraformInit(originalTerragruntOptions *options.TerragruntOptions, terr
856856

857857
// Prevent Auto-Init if the user has disabled it
858858
if util.FirstArg(terragruntOptions.TerraformCliArgs) != CMD_INIT && !terragruntOptions.AutoInit {
859-
return errors.WithStackTrace(InitNeededButDisabled("Cannot continue because init is needed, but Auto-Init is disabled. You must run 'terragrunt init' manually."))
859+
terragruntOptions.Logger.Warnf("Detected that init is needed, but Auto-Init is disabled. Continuing with further actions, but subsequent terraform commands may fail.")
860+
return nil
860861
}
861862

862863
initOptions, err := prepareInitOptions(terragruntOptions, terraformSource)
@@ -981,12 +982,6 @@ func (err ArgumentNotAllowed) Error() string {
981982
return fmt.Sprintf(err.Message, err.Argument)
982983
}
983984

984-
type InitNeededButDisabled string
985-
986-
func (err InitNeededButDisabled) Error() string {
987-
return string(err)
988-
}
989-
990985
type BackendNotDefined struct {
991986
Opts *options.TerragruntOptions
992987
BackendType string
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module "mod" {
2+
source = "./module"
3+
}
4+
5+
output "foo" {
6+
value = module.mod.foo
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
resource "null_resource" "foo" {}
2+
3+
output "foo" {
4+
value = null_resource.foo.id
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Intenionally empty

test/integration_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -1740,6 +1740,22 @@ func TestDebugGeneratedInputs(t *testing.T) {
17401740
assert.False(t, isDefined)
17411741
}
17421742

1743+
func TestNoAutoInit(t *testing.T) {
1744+
t.Parallel()
1745+
1746+
cleanupTerraformFolder(t, TEST_FIXTURE_REGRESSIONS)
1747+
tmpEnvPath := copyEnvironment(t, TEST_FIXTURE_REGRESSIONS)
1748+
rootPath := util.JoinPath(tmpEnvPath, TEST_FIXTURE_REGRESSIONS, "skip-init")
1749+
1750+
stdout := bytes.Buffer{}
1751+
stderr := bytes.Buffer{}
1752+
err := runTerragruntCommand(t, fmt.Sprintf("terragrunt apply --terragrunt-no-auto-init --terragrunt-log-level debug --terragrunt-non-interactive --terragrunt-working-dir %s", rootPath), &stdout, &stderr)
1753+
logBufferContentsLineByLine(t, stdout, "no force apply stdout")
1754+
logBufferContentsLineByLine(t, stderr, "no force apply stderr")
1755+
require.Error(t, err)
1756+
require.Contains(t, stderr.String(), "This module is not yet installed.")
1757+
}
1758+
17431759
func TestLocalsParsing(t *testing.T) {
17441760
t.Parallel()
17451761

0 commit comments

Comments
 (0)