#! /bin/bash # # Runs an init and apply in all copies of a module # # TODO: Would be really nice if this did some input validation, and if you # could specify 'local' or not. # Grab a list of the terragrunt.hcls that were updated in the last git commit, # but ignore the root terragrunt.hcl, and strip terragrunt.hcl from the end. UPDATED_MODULES=$( git diff --name-only HEAD HEAD~1 | grep terragrunt.hcl | egrep -v "^terragrunt.hcl" | sed "s#/terragrunt.hcl##" | sort -r ) PWD=`pwd` BN=`basename $PWD` if [[ $BN != "xdr-terraform-live" ]]; then echo Must be run from xdr-terraform-live root. exit 1 fi echo The following modules will be applied: for m in ${UPDATED_MODULES}; do printf '\t%s\n' $m done echo "" read -p "Continue [Y/n]? " -n 1 -r echo "" if [[ $REPLY =~ ^[Nn]$ ]]; then echo Exiting.... exit 1 fi for m in ${UPDATED_MODULES}; do echo "" echo ============================================= echo \ Applying $m echo ============================================= pushd $m if [[ -f "../UNUSED.ACCOUNT" ]]; then echo $i is unused. Continuing. popd continue fi terragrunt init --upgrade && terragrunt apply EXITCODE=$? if [[ $EXITCODE != 0 ]]; then # Prompt to continue after each failed module. read -p "Terragrunt completed unsuccessfully. Continue to next module [Y/n]? " -n 1 -r echo "" if [[ $REPLY =~ ^[Nn]$ ]] then echo Exiting... exit 2 fi fi popd done