Skip to content

Commit

Permalink
fixing get_password exception error
Browse files Browse the repository at this point in the history
  • Loading branch information
husky committed Feb 2, 2023
1 parent 7e5a753 commit 98726fa
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions aws-lab/get_password.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,23 @@ instanceid=$(jq -r '.instanceid')
user=$(aws ec2 get-console-output --instance-id $instanceid --output text --no-paginate | grep "the default application username is" | awk -F "'" '{print $2}')
password=$(aws ec2 get-console-output --instance-id $instanceid --output text --no-paginate | grep "Setting Bitnami application password to" | awk -F "'" '{print $2}')

# Check if username and password were successfully retrieved
# Check if username and password were successfully retrieved. Return a valid JSON object saying "unknown" if we can't retrieve the pass
# This is to allow TF to continue execution even in the event of a bash script error
if [ -z "$user" ] || [ -z "$password" ]; then
>&2 echo "Error: Unable to retrieve username or password from instance output"
exit 1
cat <<EOF | jq -c
{
"user": "[unknown]",
"password": "[unknown]"
}
EOF

else
# Generate and print output JSON
cat <<EOF | jq -c
{
"user": "$user",
"password": "$password"
}
EOF
fi

# Generate and print output JSON
cat <<EOF | jq -c
{
"user": "$user",
"password": "$password"
}
EOF

0 comments on commit 98726fa

Please sign in to comment.