Note: An updated script with additional capabilities and multi-product support has been published to the hashicorp-installer repo. It defaults to installing Terraform and can be a drop-in replacement for this script.
The terraform-install script automates the process of downloading and installing Terraform. It provides an ideal method for installing installing updates or a specific version.
This script detects the latest version, OS and CPU-Architecture and allows installation to local or system locations. Optional parameters allow installing a specific version and installing to /usr/local/bin without prompting.
Example - install last pre-0.13 release: ./terraform-install.sh -i 0.12.29
Options:
-i VERSION
: Install specific version-a
: Automatically use sudo
to install to /usr/local/bin
sudoInstall=true
)-c
: leave binary in working directory (for CI/DevOps use)-h
: help-v
: display versionThis installer is similar to my Packer Installer and Vault Installer
Download Installer
curl -LO https://raw.github.com/robertpeteuil/terraform-installer/master/terraform-install.sh
chmod +x terraform-install.sh
Download installer via my bootstrap server (iac.sh or https://iac.sh)
curl iac.sh/terraform > getinst.sh
bash getinst.sh
# installer downloaded as terraform-install.sh in current directory
./terraform-install.sh
# usage: terraform-install.sh [-i VERSION] [-a] [-c] [-h] [-v]
# -i VERSION : specify version to install in format '' (OPTIONAL)
# -a : automatically use sudo to install to /usr/local/bin
# -c : leave binary in working directory (for CI/DevOps use)
# -h : help
# -v : display vault-install.sh version
unzip
- terraform downloads are in zip formatcurl
or wget
- script will use either one to retrieve metadata and downloadOptional
jq
- if installed, latest version parsed from hashicorp downloads
-i VERSION
parameter (if specified)jq
installed parse version from hashicorp downloads-i
-c
option, or passing TF_INSTALL_DIR
environment variable/usr/local/bin
if it is writable, or with -a
abort
CPU architecture is detected for each OS accordingly:
lscpu
or by inspecting /proc/cpuinfo
arm
as it's the only arm
version available (for now)amd64
as it's the only version available on macOSamd64
I am a HashiCorp employee, but this is a personal project and not officially endorsed or supported by HashiCorp.
Apache 2.0 License - Copyright (c) 2020 Robert Peteuil