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

Feature request: Detect if uname -m arch is available, if not, fall back to amd64 #55

Open
nitrocode opened this issue Jul 14, 2022 · 1 comment

Comments

@nitrocode
Copy link

nitrocode commented Jul 14, 2022

This is how tfenv solves this issue. It detects the architecture and checks if the version has the arm binary with hard coded versions, if no arm binary, then it downloads x86. This all works without having to override the env var.

https://github.com/tfutils/tfenv/blob/c05c364a0565b0bee63d97b763def4521d620884/libexec/tfenv-install#L85-L105


It would be nice to have a fallback set

On arm64

# Set fallback arch
ASDF_HASHICORP_OVERWRITE_ARCH_FALLBACK=amd64

# This will install amd64 since arm64 is unavailable
# https://releases.hashicorp.com/terraform/1.0.1/
asdf install terraform 1.0.1

# This will install since arm64 is available
# https://releases.hashicorp.com/terraform/1.0.2/
asdf install terraform 1.0.2

Currently, I'm using this which doesn't do a retry but has a hard coded string for the last_version_before_arm which is 1.0.1 for terraform.

#!/usr/bin/env sh

asdftf() {
  current_version_to_install="$*"
  # https://releases.hashicorp.com/terraform/1.0.1/
  # https://releases.hashicorp.com/terraform/1.0.2/
  last_version_before_arm="1.0.1"
  # sort algorithm puts the earliest version first
  # ref: https://stackoverflow.com/a/25731924
  get_earliest_version=$(printf '%s\n%s' "$last_version_before_arm" "$current_version_to_install" | sort -t '.' -k 1,1 -k 2,2 -k 3,3 -k 4,4 -g | head -1)
  # if the version is the same, that means it's below 1.0.1
  if [ "$get_earliest_version" = "$current_version_to_install" ]; then
    arch="amd64"
  else
    arch=$(uname -m)
  fi
  ASDF_HASHICORP_OVERWRITE_ARCH_TERRAFORM="$arch" asdf install terraform "$current_version_to_install"
}
$ asdftf 1.0.1
Downloading terraform version 1.0.1 from https://releases.hashicorp.com/terraform/1.0.1/terraform_1.0.1_darwin_amd64.zip
$ asdftf 1.0.2
Downloading terraform version 1.0.2 from https://releases.hashicorp.com/terraform/1.0.2/terraform_1.0.2_darwin_arm64.zip
@voiski
Copy link
Contributor

voiski commented Oct 10, 2022

I made that change on my PR #59

It is working fine for me with old terraform versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants