Skip to content

Commit 7f1c763

Browse files
Veetahavvv
andauthored
Detect aws cli of incompatible version (#21)
Detect aws cli of incompatible version Co-authored-by: Valery V. Vorotyntsev <valery.vv@gmail.com>
2 parents 6671fb7 + efc935c commit 7f1c763

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

scripts/reds-deploy.sh

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,26 @@ main() {
5353
done
5454

5555
# Verify the commands we are going to use are present ahead of time
56+
assert_cmd_exists aws
5657
assert_cmd_exists mktemp
5758
assert_cmd_exists mkdir
5859
assert_cmd_exists rm
5960
assert_cmd_exists tar
6061
assert_cmd_exists unzip
6162

63+
# Check if the user has the proper version of aws cli installed
64+
local aws_version_output
65+
aws_version_output=$(aws --version);
66+
if [[ ! $aws_version_output =~ aws-cli/2.* ]]; then
67+
local msg=$(cat <<EOF
68+
aws cli version 2 is required.
69+
Found version $aws_version_output
70+
Please follow the installation instructions: https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html
71+
EOF
72+
)
73+
exit_err "$msg"
74+
fi
75+
6276
# Validate the arguments and set proper defaults
6377
if [ ! -v stack_name ]; then
6478
log_error "Missing required argument '--stack-name'"
@@ -149,7 +163,7 @@ get_terraform() {
149163
# Check if the user already has the proper version of terraform installed
150164
local tf_version_output
151165
if tf_version_output=$(terraform --version); then
152-
if [[ "$tf_version_output" =~ Terraform\ v${tf_version}.* ]]; then
166+
if [[ $tf_version_output =~ Terraform\ v${tf_version}.* ]]; then
153167
log_info "Found already installed Terraform v$tf_version."
154168
echo 'terraform'
155169
return 0
@@ -199,7 +213,7 @@ log_error() {
199213
}
200214

201215
exit_err() {
202-
log_error "aborting due to the following error: $1" >&2
216+
log_error "$(printf 'aborting due to the following error:\n%s\n' "$1")" >&2
203217
exit 1
204218
}
205219

0 commit comments

Comments
 (0)