Last active
September 7, 2022 01:57
-
-
Save jc1518/fa63225c1eae2f201992f68bae3b4b43 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
warning_list="" | |
RED="\033[0;31m" | |
NC="\033[0m" | |
for target_group in $(aws elbv2 describe-target-groups --query "TargetGroups[?starts_with(TargetGroupName, 'serverless-')].TargetGroupArn" --output text) | |
do | |
echo "---------------------------------------" | |
dns=$(aws elbv2 describe-tags --resource-arns "$target_group" --query "TagDescriptions[*].Tags[?Key=='dns'].Value" --output text) | |
echo "Backend DNS: $dns" | |
new_ip="" | |
for ip in $(dig +short "$dns" | sort) | |
do | |
if [[ "$ip" == "192."* ]] | |
then | |
if [ "$new_ip" = "" ] | |
then | |
new_ip=$ip | |
else | |
new_ip="$new_ip $ip" | |
fi | |
fi | |
done | |
echo "New IP: $new_ip" | |
old_ip=$(aws elbv2 describe-tags --resource-arns "$target_group" --query "TagDescriptions[*].Tags[?Key=='ip'].Value" --output text) | |
echo "Old IP: $old_ip" | |
if [ "$new_ip" != "$old_ip" ] | |
then | |
echo -e "${RED}IP addresses have changed!${NC}" | |
if [ "$warning_list" = "" ] | |
then | |
warning_list=$dns | |
else | |
warning_list="$warning_list, $dns" | |
fi | |
else | |
echo "IP addresses are still the same" | |
fi | |
done | |
echo "-----------------Summary------------------" | |
if [ "$warning_list" != "" ] | |
then | |
echo -e "${RED}${warning_list} IP addresses have changed${NC}" | |
echo "::set-output name=re_deploy::yes" | |
else | |
echo "All good!" | |
echo "::set-output name=re_deploy::no" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment