Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - fix(init): do not require re-init after explicit init on clean directory #2949

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 @@ -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 Expand Up @@ -235,7 +235,7 @@ func TestDownloadTerraformSourceIfNecessaryRemoteUrlOverrideSource(t *testing.T)

copyFolder(t, "../../../test/fixture-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