Created
November 4, 2019 01:35
-
-
Save augustovictor/5c7695b07f3e459c2cc5a898e7bc616f 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/sh | |
TERRAFORM_DIR=./terraform | |
APP_PROPERTIES_DIR=./src/main/resources | |
TERRAFORM_SSM_FILE="${TERRAFORM_DIR}/ssm.tf" | |
APP_PROPERTIES_FILE="${APP_PROPERTIES_DIR}/application.properties" | |
TERRAFORM_SSM_PROPERTY_PREFIX="" | |
# ssm variables | |
ssm_variables_regex="ssm_parameter_name *= *\"(\/config.*\/.*\/)?(.*)\"" | |
ssm_properties=() | |
while read line; do | |
if [[ $line =~ $ssm_variables_regex ]]; then | |
ssm_properties+=(${BASH_REMATCH[2]}) | |
TERRAFORM_SSM_PROPERTY_PREFIX=${BASH_REMATCH[1]} | |
fi | |
done < $TERRAFORM_SSM_FILE | |
# Application | |
application_properties_regex="(.*)=" | |
application_properties=() | |
while read line; do | |
if [[ $line =~ $application_properties_regex ]]; then | |
application_properties+=(${BASH_REMATCH[1]}) | |
fi | |
done < $APP_PROPERTIES_FILE | |
# Verification | |
in_ssm_only=() | |
for ssm_property in ${ssm_properties[@]}; do | |
missing_property="" | |
is_property_found=false | |
for i in "${!application_properties[@]}"; do | |
if [ $is_property_found == false ]; then | |
if [ ${application_properties[i]} == ${ssm_property} ]; then | |
is_property_found=true | |
else | |
missing_property=${ssm_property} | |
fi | |
fi | |
done | |
if [ $is_property_found == false ]; then | |
in_ssm_only+=($missing_property) | |
fi | |
done | |
in_application_properties_only=() | |
for application_property in ${application_properties[@]}; do | |
missing_property="" | |
is_property_found=false | |
for i in "${!ssm_properties[@]}"; do | |
if [ $is_property_found == false ]; then | |
if [ ${ssm_properties[i]} == ${application_property} ]; then | |
is_property_found=true | |
else | |
missing_property=${application_property} | |
fi | |
fi | |
done | |
if [ $is_property_found == false ]; then | |
in_application_properties_only+=($missing_property) | |
fi | |
done | |
# Result | |
ui_divider="============================================================================================" | |
if ((${#in_ssm_only[@]})); then | |
printf "\n\e[31m$ui_divider" | |
printf "\n application.properties IS MISSING PROPERTIES" | |
printf "\n$ui_divider\e[0m" | |
printf "\nAdd the following properties to \e[1;31m$APP_PROPERTIES_FILE\e[0m:" | |
printf "\n%s=" "${in_ssm_only[@]}" | |
else | |
printf "\n\e[32m$ui_divider" | |
printf "\n$APP_PROPERTIES_FILE has all properties defined in $TERRAFORM_SSM_FILE" | |
printf "\n\e[32m$ui_divider\e[0m\n" | |
fi | |
if ((${#in_application_properties_only[@]})); then | |
printf "\n\e[31m$ui_divider" | |
printf "\n terraform IS MISSING PARAMETERS" | |
printf "\n$ui_divider\e[0m" | |
printf "\nAdd the following parameters to \e[1;31m$TERRAFORM_SSM_FILE\e[0m:\n" | |
printf "$TERRAFORM_SSM_PROPERTY_PREFIX%s\n" "${in_application_properties_only[@]}" | |
else | |
printf "\n\e[32m$ui_divider" | |
printf "\n$TERRAFORM_SSM_FILE has all parameters defined in $APP_PROPERTIES_FILE" | |
printf "\n\e[32m$ui_divider\e[0m\n" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment