The terraform-install script automates the process of downloading and installing Terraform. This provides an ideal method for installation on new hosts, installing updates and even downgrading if necessary. This script detects or determines the OS and CPU-Architecture.
Options:
- install specific version:
-i VERSION
- automatically
sudo
install to /usr/local/bin:-a
- prevents user prompt asking for install destination
- user must enter sudo password unless NOPASSWD is enabled
- uncomment line 12 to make this the default behavior (
sudoInstall=true
)
Download the installer and make executable
curl -LO https://raw.github.com/robertpeteuil/terraform-installer/master/terraform-install.sh
chmod +x terraform-install.sh
Run the installer
./terraform-install.sh
Optional Parameters
# -i = Install specific version
./terraform-install.sh -i 0.11.1
# -a = Automatic sudo install to /usr/local/bin/
./terraform-install.sh -a
- visit website download page
- locate version for OS/CPU and download
- find and extract binary from downloaded zip file
- copy binary to a directory on the PATH
- System with Bash Shell (Linux, macOS, Windows Subsystem for Linux)
curl
unzip
- terraform downloads in zip format
- Determines Version to Download and Install
- Uses Version specified by
-i VERSION
parameter (if specified) - Otherwise determines Latest Version
- Uses GitHub API to retrieve latest version number
- Uses Version specified by
- Calculates Download URL based on Version, OS and CPU-Architecture
- Verifies URL Validity before Downloading in Case:
- VERSION incorrectly specified with
-i
- Download URL Format Changed on terraform Website
- VERSION incorrectly specified with
- Determines Install Destination
- Performed before Download/Install Process in case User selects
abort
- Performed before Download/Install Process in case User selects
- Installation Process
- Download, Extract, Install, Cleanup and Display Results
CPU architecture is detected for each OS accordingly:
- Linux / Windows (WSL since this is a Bash script)
- detected with
lscpu
or by inspecting/proc/cpuinfo
- detected with
- macOS - uses Default Arch
amd64
as it's the only version available on macOS - Default Value -
amd64
Apache 2.0 License - Copyright (c) 2018 Robert Peteuil