Skip to content

Commit

Permalink
fix(init): do not require re-init after explicit init on clean direct…
Browse files Browse the repository at this point in the history
…ory (#2949)

* fix(init): avoid re-init warning after explicit init

* fix failed test

* fix linter issue
  • Loading branch information
jaymecd authored Oct 7, 2024
1 parent 38c8f29 commit e7ddb35
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion cli/commands/terraform/download_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ func DownloadTerraformSourceIfNecessary(ctx context.Context, terraformSource *te
currentVersion, err := terraformSource.EncodeSourceVersion()
// if source versions are different or calculating version failed, create file to run init
// https://github.com/gruntwork-io/terragrunt/issues/1921
if previousVersion != currentVersion || err != nil {
if (previousVersion != "" && previousVersion != currentVersion) || err != nil {
terragruntOptions.Logger.Debugf("Requesting re-init, source version has changed from %s to %s recently.", previousVersion, currentVersion)

initFile := util.JoinPath(terraformSource.WorkingDir, ModuleInitRequiredFile)

f, createErr := os.Create(initFile)
Expand Down
6 changes: 3 additions & 3 deletions cli/commands/terraform/download_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func TestDownloadTerraformSourceIfNecessaryLocalDirToEmptyDir(t *testing.T) {
downloadDir := tmpDir(t)
defer os.Remove(downloadDir)

testDownloadTerraformSourceIfNecessary(t, canonicalURL, downloadDir, false, "# Hello, World", true)
testDownloadTerraformSourceIfNecessary(t, canonicalURL, downloadDir, false, "# Hello, World", false)
}

func TestDownloadTerraformSourceIfNecessaryLocalDirToAlreadyDownloadedDir(t *testing.T) {
Expand All @@ -190,7 +190,7 @@ func TestDownloadTerraformSourceIfNecessaryRemoteUrlToEmptyDir(t *testing.T) {
downloadDir := tmpDir(t)
defer os.Remove(downloadDir)

testDownloadTerraformSourceIfNecessary(t, canonicalURL, downloadDir, false, "# Hello, World", true)
testDownloadTerraformSourceIfNecessary(t, canonicalURL, downloadDir, false, "# Hello, World", false)
}

func TestDownloadTerraformSourceIfNecessaryRemoteUrlToAlreadyDownloadedDir(t *testing.T) {
Expand Down Expand Up @@ -238,7 +238,7 @@ func TestDownloadTerraformSourceIfNecessaryRemoteUrlOverrideSource(t *testing.T)

copyFolder(t, "../../../test/fixtures/download-source/hello-world-version-remote", downloadDir)

testDownloadTerraformSourceIfNecessary(t, canonicalURL, downloadDir, true, "# Hello, World", true)
testDownloadTerraformSourceIfNecessary(t, canonicalURL, downloadDir, true, "# Hello, World", false)
}

func TestDownloadTerraformSourceIfNecessaryInvalidTerraformSource(t *testing.T) {
Expand Down

0 comments on commit e7ddb35

Please sign in to comment.