-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget-terraform-version.sh
executable file
·62 lines (49 loc) · 2.81 KB
/
get-terraform-version.sh
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env bash
# -------------------------------------------------------------------------------- #
# Description #
# -------------------------------------------------------------------------------- #
# A simple script to show how to programatically get the terraform version. #
# -------------------------------------------------------------------------------- #
# -------------------------------------------------------------------------------- #
# Get Terraform Version #
# -------------------------------------------------------------------------------- #
# Programatically get the terraform version. #
# -------------------------------------------------------------------------------- #
function get_terraform_version()
{
local terraform_version
command=$(command -v "terraform")
if [[ -z $command ]]; then
echo "Terraform is not installed - Aborting"
exit
fi
terraform_version=$(terraform --version | head -n 1)
terraform_version=${terraform_version##* } # retain the part after the last space
terraform_version=${terraform_version#?} # strip the first letter
if [[ -z ${terraform_version} ]]; then
echo "Could not determine terraform version - Aborting"
exit
fi
echo "${terraform_version}"
}
# -------------------------------------------------------------------------------- #
# Run Tests #
# -------------------------------------------------------------------------------- #
# A VERY simple test function to ensure that it all works #
# -------------------------------------------------------------------------------- #
function run_tests()
{
tf_version=$(get_terraform_version)
echo "${tf_version}"
}
# -------------------------------------------------------------------------------- #
# Main() #
# -------------------------------------------------------------------------------- #
# This is the actual 'script' and the functions/sub routines are called in order. #
# -------------------------------------------------------------------------------- #
run_tests
# -------------------------------------------------------------------------------- #
# End of Script #
# -------------------------------------------------------------------------------- #
# This is the end - nothing more to see here. #
# -------------------------------------------------------------------------------- #