Skip to content

Commit

Permalink
A couple util scripts (#1546)
Browse files Browse the repository at this point in the history
* A couple util scripts

* Doc
  • Loading branch information
ben851 authored Sep 19, 2024
1 parent 63cf20f commit 691f47d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
4 changes: 4 additions & 0 deletions scripts/setupPreCommitHook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
# This is script is simply a shortcut to the pre-commit hook command that I always forget when I clone this repo.
# The pre-commit hook in ./hooks will automatically run terraform fmt on all terraform files in the repo.
git config set core.hooksPath ./hooks
44 changes: 44 additions & 0 deletions scripts/terragruntInitRecursive.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

### WARNING: THIS IS A POTENTIALLY DANGEROUS SCRIPT.
### MAKE SURE YOU ARE IN THE CORRECT ENVIRONMENT BEFORE RUNNING

### This script is intended to do a terragrunt init --reconfigure on all folders in the env/$ENVIRONMENT directory

runCommand()
{
CMD=$1
eval "$CMD"
if [ $? != 0 ]; then
echo -e "{${RED} ERROR: Command: \"$CMD\" Failed. Halting."
exit 1
fi
}

toApply="common,ecr,ses_receiving_emails,dns,ses_validation_dns_entries,cloudfront,eks,elasticache,rds,lambda-api,lambda-admin-pr,performance-test,heartbeat,database-tools,lambda-google-cidr,ses_to_sqs_email_callbacks,sns_to_sqs_sms_callbacks"

ENVIRONMENT=$1
VARFILE=$2

IFS=', ' read -r -a folders <<< "$toApply"

echo "This script will iterate through all terraform folders and auto upgrade and apply."
echo -e "${YELLOW}The target environment is: ${BYELLOW} $ENVIRONMENT"
echo -e "${YELLOW}Your current kubernetes context is ${BYELLOW} $AWS_PROFILE"
echo "****VERIFY YOUR CONTEXT IS THE TARGET ENVIRONMENT!****"
echo -e "${COLOR_OFF}"
echo "Are you sure you want to proceed? Only "yes" will be accepted"
read RESPONSE

if [ "$RESPONSE" == "yes" ]; then
for folder in "${folders[@]}"
do
pushd ../env/$ENVIRONMENT/$folder
runCommand "terragrunt init --reconfigure"
popd
done
exit 0
else
echo "USER REQUESTED CANCELLATION"
exit 0
fi

0 comments on commit 691f47d

Please sign in to comment.