Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: Added --with-terraform argument to install coder and terraform together #5586

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

Merged
merged 7 commits into from
Jan 6, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
- Fixed typos
- Added recommend changes for consistency
  • Loading branch information
Admin committed Jan 5, 2023
commit cfd33f96ea6a3dee09fb6217c68fc60074ea4b90
29 changes: 14 additions & 15 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Usage:
Specifies the remote shell for remote installation. Defaults to ssh.

--with-terraform
Installs Terraform binary from https://releases.hashicorp.com/terraform/1.3.4/ source
Installs Terraform binary from https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/ source
alongside coder.
This is great for if you are having issues with Coder installing terraform, or if you
just want it on your base system aswell.
Expand Down Expand Up @@ -157,7 +157,7 @@ main() {
if [ "${TRACE-}" ]; then
set -x
fi

TERRAFORM_VERSION="1.3.4"
unset \
DRY_RUN \
METHOD \
Expand Down Expand Up @@ -222,7 +222,7 @@ main() {
exit 0
;;
--with-terraform)
METHOD=install_terraform
METHOD=with_terraform
;;
--)
shift
Expand Down Expand Up @@ -253,7 +253,7 @@ main() {
fi

METHOD="${METHOD-detect}"
if [ "$METHOD" != detect ] && [ "$METHOD" != install_terraform ] && [ "$METHOD" != standalone ]; then
if [ "$METHOD" != detect ] && [ "$METHOD" != with_terraform ] && [ "$METHOD" != standalone ]; then
echoerr "Unknown install method \"$METHOD\""
echoerr "Run with --help to see usage."
exit 1
Expand Down Expand Up @@ -290,9 +290,9 @@ main() {
exit 1
fi
fi
if [ "$METHOD" = install_terraform ]; then
# Install terraform then contine the script
install_terraform
if [ "$METHOD" = with_terraform ]; then
# Install terraform then continue the script
with_terraform
fi

# DISTRO can be overridden for testing but shouldn't normally be used as it
Expand Down Expand Up @@ -369,20 +369,19 @@ fetch() {
sh_c mv "$FILE.incomplete" "$FILE"
}

install_terraform() {
with_terraform() {
# Check if the unzip package is installed. If not error peacefully.
if !(command_exists unzip); then
echoh
echoerr "This script needs the unzip package to run."
echoerr "Please install unzip to use this function"
exit 1
fi
TERRAFORM_VERSION="1.3.4"
echoh "Installing Terraform version $TERRAFORM_VERSION $TERRAFORM_ARCH package from Hashicorp Source."
echoh "Installing Terraform version $TERRAFORM_VERSION $TERRAFORM_ARCH from the HashiCorp release repository."
echoh

# Download from offical source and save it to cache
fetch "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_1.3.4_${OS}_${TERRAFORM_ARCH}.zip" \
# Download from official source and save it to cache
fetch "https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_${OS}_${TERRAFORM_ARCH}.zip" \
"$CACHE_DIR/terraform_${TERRAFORM_VERSION}_${OS}_${TERRAFORM_ARCH}.zip"

sh_c mkdir -p "$TERRAFORM_INSTALL_PREFIX" 2>/dev/null || true
Expand All @@ -393,7 +392,7 @@ install_terraform() {
fi
# Prepare /usr/local/bin/ and the binary for copying
"$sh_c" mkdir -p "$TERRAFORM_INSTALL_PREFIX/bin"
"$sh_c" unzip -d "$CACHE_DIR" -o "$CACHE_DIR/terraform_1.3.4_${OS}_${ARCH}.zip"
"$sh_c" unzip -d "$CACHE_DIR" -o "$CACHE_DIR/terraform_${TERRAFORM_VERSION}_${OS}_${ARCH}.zip"
COPY_LOCATION="$TERRAFORM_INSTALL_PREFIX/bin/terraform"

# Remove the file if it already exists to
Expand Down Expand Up @@ -578,8 +577,8 @@ arch() {
esac
}

# The following is to change the naming, that way people with armv7 won't recieve a error
# List of binaries can be found here: https://releases.hashicorp.com/terraform/1.3.4/
# The following is to change the naming, that way people with armv7 won't receive a error
# List of binaries can be found here: https://releases.hashicorp.com/terraform/
terraform_arch() {
uname_m=$(uname -m)
case $uname_m in
Expand Down