You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.2 KiB

  1. #!/usr/bin/env bash
  2. TERRAFORM_BIN_PATH="${TERRAFORM_BIN_PATH:-$HOME/.terraform}";
  3. TERRAFORM_VERSION=${TERRAFORM_VERSION:-"0.13.5"}
  4. platform='unknown'
  5. platform_uname=$(uname)
  6. if [[ "$platform_uname" == 'Linux' ]]; then
  7. platform='linux'
  8. elif [[ "$platform_uname" == 'FreeBSD' ]]; then
  9. platform='freebsd'
  10. elif [[ "$platform_uname" == 'Darwin' ]]; then
  11. platform='darwin'
  12. else
  13. echo "[$platform_uname] is not recognized as a valid platform"
  14. exit 1
  15. fi
  16. arch="unknown"
  17. arch_uname=$(uname -m)
  18. if [[ "$arch_uname" == 'x86_64' ]]; then
  19. arch='amd64'
  20. elif [[ "$arch_uname" == 'i686' ]]; then
  21. arch='386'
  22. else
  23. echo "[$arch_uname] is not recognized as a valid arch"
  24. exit 1
  25. fi
  26. TERRAFORM_URL="https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_${platform}_${arch}".zip
  27. TERRAFORM_PATH="$TERRAFORM_BIN_PATH/$TERRAFORM_VERSION"
  28. TERRAFORM_CMD="$TERRAFORM_PATH/terraform"
  29. if ! type "$TERRAFORM_CMD" > /dev/null 2>&1; then
  30. if [ ! -f "$TERRAFORM_PATH.zip" ]; then
  31. echo "Downloading $TERRAFORM_URL"
  32. mkdir -p "$TERRAFORM_PATH"
  33. curl -ls "$TERRAFORM_URL" -o "$TERRAFORM_PATH.zip"
  34. fi
  35. cd "$TERRAFORM_PATH" && unzip "$TERRAFORM_PATH.zip" && cd - || exit 2
  36. fi
  37. # shellcheck disable=SC2068
  38. $TERRAFORM_CMD $@