Skip to content

Commit

Permalink
adapt terraform download due to new folder zip structure
Browse files Browse the repository at this point in the history
  • Loading branch information
rkferreira committed Apr 30, 2024
1 parent cf9137b commit 24f338e
Showing 1 changed file with 23 additions and 7 deletions.
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 @@ func (c *DefaultClient) DetectVersion(log logging.SimpleLogging, projectDirector
}

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 @@ func (c *DefaultClient) DetectVersion(log logging.SimpleLogging, projectDirector
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 @@ func ensureVersion(log logging.SimpleLogging, dl Downloader, versions map[string
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

0 comments on commit 24f338e

Please sign in to comment.