Skip to content

Fix bug on old terragrunt version on arm64 (M1 darwin) arch #137

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
Empty file modified install.sh
100644 → 100755
Empty file.
25 changes: 18 additions & 7 deletions lib/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func GetRecentVersions() ([]string, error) {
return nil, nil
}

//CreateRecentFile : create a recent file
// CreateRecentFile : create a recent file
func CreateRecentFile(requestedVersion string) {

installLocation = GetInstallLocation()
Expand Down Expand Up @@ -168,7 +168,7 @@ func ValidVersionFormat(version string) bool {
return semverRegex.MatchString(version)
}

//Install : Install the provided version in the argument
// Install : Install the provided version in the argument
func Install(tgversion string, usrBinPath string, mirrorURL string) string {
/* Check to see if user has permission to the default bin location which is "/usr/local/bin/terragrunt"
* If user does not have permission to default bin location, proceed to create $HOME/bin and install the tgswitch there
Expand All @@ -183,6 +183,17 @@ func Install(tgversion string, usrBinPath string, mirrorURL string) string {
goarch := runtime.GOARCH
goos := runtime.GOOS

checkDarwinArm64Constraint, err := CheckDarwinArm64VersionConstraint(tgversion, goarch, goos)

if err != nil {
log.Println(err)
}

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

/* check if selected version already downloaded */
installFileVersionPath := ConvertExecutableExt(filepath.Join(installLocation, installVersion+tgversion))
fileExist := CheckFileExist(installLocation + installVersion + tgversion)
Expand Down Expand Up @@ -225,7 +236,7 @@ func Install(tgversion string, usrBinPath string, mirrorURL string) string {
/* rename unzipped file to terragrunt version name - terraform_x.x.x */
RenameFile(downloadedFile, installFileVersionPath)

err := os.Chmod(installFileVersionPath, 0755)
err = os.Chmod(installFileVersionPath, 0755)
if err != nil {
log.Println(err)
}
Expand All @@ -244,9 +255,9 @@ func Install(tgversion string, usrBinPath string, mirrorURL string) string {
return ""
}

//InstallableBinLocation : Checks if terragrunt is installable in the location provided by the user.
//If not, create $HOME/bin. Ask users to add $HOME/bin to $PATH
//Return $HOME/bin as install location
// InstallableBinLocation : Checks if terragrunt is installable in the location provided by the user.
// If not, create $HOME/bin. Ask users to add $HOME/bin to $PATH
// Return $HOME/bin as install location
func InstallableBinLocation(userBinPath string) string {

usr, errCurr := user.Current()
Expand Down Expand Up @@ -294,7 +305,7 @@ func PrintCreateDirStmt(unableDir string, writable string) {
fmt.Printf("RUN `export PATH=$PATH:%s` to append bin to $PATH\n", writable)
}

//ConvertExecutableExt : convert excutable with local OS extension
// ConvertExecutableExt : convert excutable with local OS extension
func ConvertExecutableExt(fpath string) string {
switch runtime.GOOS {
case "windows":
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
}
1 change: 1 addition & 0 deletions test-data/test_terragrunt-version_m1/.terragrunt-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.26.7
16 changes: 16 additions & 0 deletions test-data/test_terragrunt_hcl_m1/terragrunt.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
include {
path = "${find_in_parent_folders()}"
}

terraform {
source = "..."

extra_arguments "variables" {
commands = get_terraform_commands_that_need_vars()
}
}
inputs = merge(
jsondecode(file("${find_in_parent_folders("general.tfvars")}"))
)

terragrunt_version_constraint=">= 0.28, < 0.28.1"
1 change: 1 addition & 0 deletions test-data/test_tgswitchrc_m1/.tgswitchrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.28.0
2 changes: 2 additions & 0 deletions test-data/test_tgswitchtoml_m1/.tgswitch.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin = "/usr/local/bin/terragrunt"
version = "0.26.7"
9 changes: 9 additions & 0 deletions test-tgswitch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,12 @@ runtestdir "tgswitchrc" "test_tgswitchrc" "v0.33.0"
runtestdir ".toml" "test_tgswitchtoml" "v0.34.0"
runtestenv "env variable" "0.37.1" "v0.37.1"
runtestarg "passing argument" "0.36.1" "v0.36.1"
# M1 darwin arm64 test versions < 0.28.12
runtestdir "terragrunt version" "test_terragrunt-version_m1" "v0.26.7"
runtestdir "terragrunt hcl" "test_terragrunt_hcl_m1" "v0.28.0"
runtestdir "tgswitchrc" "test_tgswitchrc_m1" "v0.28.0"
runtestdir ".toml" "test_tgswitchtoml_m1" "v0.26.7"
runtestenv "env variable" "0.26.7" "v0.26.7"
runtestarg "passing argument" "0.26.7" "v0.26.7"
# Edge case
runtestarg "passing argument" "0.28.12" "v0.28.12"