Skip to content

Commit

Permalink
fix(init): do not require re-init after init
Browse files Browse the repository at this point in the history
  • Loading branch information
jaymecd committed Feb 19, 2024
1 parent ccce607 commit ec916ab
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion cli/commands/terraform/download_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ func downloadTerraformSourceIfNecessary(terraformSource *terraform.Source, terra
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)
if createErr != nil {
Expand Down
4 changes: 2 additions & 2 deletions cli/commands/terraform/download_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,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 @@ -187,7 +187,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

0 comments on commit ec916ab

Please sign in to comment.