From f204c681adb3b6244ad0d3c76ba7509be4d2c44f Mon Sep 17 00:00:00 2001 From: Elia Bracci Date: Tue, 20 Dec 2022 23:42:58 +0100 Subject: [PATCH] Moved CheckDarwinArm64VersionConstraint to a new function --- lib/install.go | 12 ++++-------- lib/semver.go | 9 +++++++++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/install.go b/lib/install.go index 5637ac9..1f52753 100644 --- a/lib/install.go +++ b/lib/install.go @@ -9,8 +9,6 @@ import ( "regexp" "runtime" "strings" - - semver "github.com/hashicorp/go-version" ) const ( @@ -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" } diff --git a/lib/semver.go b/lib/semver.go index 4ef4982..120b730 100644 --- a/lib/semver.go +++ b/lib/semver.go @@ -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 +}