-
-
Notifications
You must be signed in to change notification settings - Fork 60
Open
Description
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.
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.2Currently, 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.zipMetadata
Metadata
Assignees
Labels
No labels