Skip to content

Commit

Permalink
Moved CheckDarwinArm64VersionConstraint to a new function
Browse files Browse the repository at this point in the history
  • Loading branch information
Elia Bracci committed Dec 20, 2022
1 parent 44bf724 commit f204c68
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
12 changes: 4 additions & 8 deletions lib/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"regexp"
"runtime"
"strings"

semver "github.com/hashicorp/go-version"
)

const (
Expand Down Expand Up @@ -184,13 +182,11 @@ func Install(tgversion string, usrBinPath string, mirrorURL string) string {

goarch := runtime.GOARCH
goos := runtime.GOOS
versionObj, err := semver.NewVersion(tgversion)

// Constraint for darwin M1. Terragrunt started release arm64 versions for linux and darwin OS from version 0.28.12 included.
// However, amd64 versions work on darwin arm64. To be tested on linux platforms.
darwinM1constraint, err := semver.NewConstraint("< 0.28.12")
if darwinM1constraint.Check(versionObj) && goarch == "arm64" && goos == "darwin" {
fmt.Printf("%s satisfies constraints %s", versionObj, darwinM1constraint)
checkDarwinArm64Constraint, err := CheckDarwinArm64VersionConstraint(tgversion, goarch, goos)

if checkDarwinArm64Constraint && err == nil {
fmt.Printf("%s satisfies Darwin arm64 constraints for tg version < 0.28.12. Switching arch to amd64 \n", tgversion)
goarch = "amd64"
}

Expand Down
9 changes: 9 additions & 0 deletions lib/semver.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,12 @@ func SemVerParser(tfconstraint *string, tflist []string) (string, error) {
func PrintInvalidTFVersion() {
fmt.Println("Version does not exist or invalid terraform version format.\n Format should be #.#.# or #.#.#-@# where # are numbers and @ are word characters.\n For example, 0.11.7 and 0.11.9-beta1 are valid versions")
}

// Function that check constraint for darwin M1. Terragrunt started release arm64 versions for linux and darwin OS from version 0.28.12 included.
// However, amd64 versions work on darwin arm64. To be tested on linux platforms.
func CheckDarwinArm64VersionConstraint(tgversion string, goarch string, goos string) (bool, error) {
version, err := semver.NewVersion(tgversion)
darwinM1constraint, err := semver.NewConstraint("< 0.28.12")

return darwinM1constraint.Check(version) && goarch == "arm64" && goos == "darwin", err
}

0 comments on commit f204c68

Please sign in to comment.