-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathterraform-switch.sh
More file actions
executable file
·44 lines (38 loc) · 1.11 KB
/
terraform-switch.sh
File metadata and controls
executable file
·44 lines (38 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
# Terraform versions: https://releases.hashicorp.com/terraform/
# Detect OS
if [[ "$OSTYPE" == "darwin"* ]]; then
OS="darwin_amd64"
elif [[ "$OSTYPE" == "linux-gnu" ]]; then
OS="linux_amd64"
elif [[ "$OSTYPE" == "freebsd"* ]]; then
OS="freebsd_amd64"
fi
# Input examples 0.11.8 or 0.12.0
if [ $# -ne 1 ]
then
echo """
Enter a version number as an argument
Versions can be found at: https://releases.hashicorp.com/terraform/
"""
exit 1
fi
version=$1
# Download the terraform binary
if [ ! -f terraform_${version} ]
then
echo "Downloading terraform version ${version}"
wget https://releases.hashicorp.com/terraform/${version}/terraform_${version}_${OS}.zip
unzip terraform_${version}_${OS}.zip
mv terraform /usr/local/bin/ # always unzips as to the name terraform
rm terraform_${version}_darwin_amd64.zip
fi
# check if terraform is already installed, set that path as a variable so we can replace it
if [ ! -z $(which terraform) ]
then
terraform_path=$(which terraform)
else
terraform_path="/usr/local/bin/terraform"
fi
cp terraform_${version} $terraform_path
echo "Set terraform version to ${version}"