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

fix: adapt terraform download due to new folder zip structure #4478

Closed
Closed
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
30 changes: 23 additions & 7 deletions server/core/terraform/terraform_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,6 @@
}

constraint, _ := version.NewConstraint(requiredVersionSetting)
// Since terraform version 1.8.2, terraform is not a single file download anymore and
// Atlantis fails to download version 1.8.2 and higher. So, as a short-term fix,
// we need to block any version higher than 1.8.1 until proper solution is implemented.
// More details on the issue here - https://github.com/runatlantis/atlantis/issues/4471
highestSupportedConstraint, _ := version.NewConstraint("<= 1.8.1")
versions := make([]*version.Version, len(tfVersions))

for i, tfvals := range tfVersions {
Expand All @@ -360,7 +355,7 @@
sort.Sort(sort.Reverse(version.Collection(versions)))

for _, element := range versions {
if constraint.Check(element) && highestSupportedConstraint.Check(element) { // Validate a version against a constraint
if constraint.Check(element) { // Validate a version against a constraint
tfversionStr := element.String()
if lib.ValidVersionFormat(tfversionStr) { //check if version format is correct
tfversion, _ := version.NewVersion(tfversionStr)
Expand Down Expand Up @@ -562,10 +557,31 @@
binURL := fmt.Sprintf("%s_%s_%s.zip", urlPrefix, runtime.GOOS, runtime.GOARCH)
checksumURL := fmt.Sprintf("%s_SHA256SUMS", urlPrefix)
fullSrcURL := fmt.Sprintf("%s?checksum=file:%s", binURL, checksumURL)
if err := dl.GetFile(dest, fullSrcURL); err != nil {
if err := dl.GetAny(dest, fullSrcURL); err != nil {
return "", errors.Wrapf(err, "downloading terraform version %s at %q", v.String(), fullSrcURL)
}

file, err := os.Open(dest)
if err != nil {
return "", errors.Wrapf(err, "opening terraform version %s at %q", v.String(), dest)
}
fileInfo := file.Stat()

Check failure on line 568 in server/core/terraform/terraform_client.go

View workflow job for this annotation

GitHub Actions / Tests

assignment mismatch: 1 variable but file.Stat returns 2 values

Check failure on line 568 in server/core/terraform/terraform_client.go

View workflow job for this annotation

GitHub Actions / Linting

assignment mismatch: 1 variable but file.Stat returns 2 values) (typecheck)

Check failure on line 568 in server/core/terraform/terraform_client.go

View workflow job for this annotation

GitHub Actions / Linting

assignment mismatch: 1 variable but file.Stat returns 2 values) (typecheck)
file.Close()
if fileInfo.IsDir() {
err := os.Rename(dest, dest+"_working")
if err != nil {
return "", errors.Wrapf(err, "renaming terraform version %s at %q", v.String(), dest)
}
err = os.Rename(dest+"_working/terraform", dest)
if err != nil {
return "", errors.Wrapf(err, "renaming terraform version %s at %q", v.String(), dest)
}
err = os.RemoveAll(dest + "_working")
if err != nil {
return "", errors.Wrapf(err, "removing terraform version %s at %q", v.String(), dest)
}
}

log.Info("Downloaded terraform %s to %s", v.String(), dest)
versions[v.String()] = dest
return dest, nil
Expand Down
Loading