Last active
June 3, 2019 20:10
-
-
Save voiski/d25e7917825676c35a927bffae88b408 to your computer and use it in GitHub Desktop.
Add colors to the terragrunt output
This file contains hidden or 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 | |
set -o pipefail | |
BOLD=$(tput bold) | |
BLACK=$(tput setaf 0) | |
RED=$(tput setaf 1) | |
GREEN=$(tput setaf 2) | |
YELLOW=$(tput setaf 3) | |
BLUE=$(tput setaf 4) | |
CYAN=$(tput setaf 6) | |
RESET=$(tput sgr0) | |
REDBOLD=${RED}${BOLD} | |
REDRESET=${RESET}${RED} | |
BLUEBOLD=${BLUE}${BOLD} | |
BLUERESET=${RESET}${BLUE} | |
GREENBOLD=${GREEN}${BOLD} | |
CURRENT_PATH=$(pwd) | |
CURRENT_PATH=${CURRENT_PATH%/aws/*} | |
CURRENT_PATH=${CURRENT_PATH//\//\\/} | |
SED_FILTER=" | |
s/\(\\[terragrunt\\] \\[\)${CURRENT_PATH}\(.*\\]\)\( [0-9\\/]* [0-9:]*\) /${BLUEBOLD}\1.\2${BLUERESET}\3${RESET} /; | |
s/\(\\[terragrunt\\]\)\( [0-9\\/]* [0-9:]*\) /${BLUEBOLD}\1${BLUERESET}\2${RESET} /; | |
s/\( Running command: \)\(.*\)/\1${CYAN}\2${RESET}/; | |
s/\( *.*: *\)\(\".*\"\)\( => \)\(\".*\"\)/${YELLOW}\1${RED}\2${BLACK}\3${GREEN}\4${RESET}/; | |
s/\( *.*: *\)\(\".*\"\)\( => \)\(<computed>\)/${YELLOW}\1${RED}\2${BLACK}\3${GREEN}\4${RESET}/; | |
s/\( *.*: *<computed>\)/${GREEN}\1${RESET}/; | |
s/\( *.*: *\".*\"\)/${GREEN}\1${RESET}/; | |
s/\(.*\)\(Module .* has finished successfully!\)/${GREENBOLD}√\1${GREEN}\2${RESET}/; | |
s/\(.*\)\(Module .* has finished with an error:\)/${REDBOLD}X\1${RED}\2${RESET}/; | |
s/\(Error: \)\(.*\)/${REDBOLD}\1${REDRESET}\2${RESET}/; | |
s/\(Hit multiple errors:\)/${REDBOLD}\1${RESET}/; | |
s/\(exit status 1\)/${RED}\1${RESET}/; | |
s/\( WARNING: \)\(.*\)/${YELLOW}${BOLD}\1${RESET}${YELLOW}\2${RESET}/; | |
s/\(.*Plan:.*\)\( [0-9]* to add,\)\(.*change,\)\(.*destroy.\)/${BOLD}\1${RESET}${GREEN}\2${YELLOW}\3${RED}\4${RESET}/; | |
s/\\\\n/\\ | |
/g; | |
s/\\\\\"/\"/g; | |
" | |
log_file=/tmp/terragrunt_log_803.log | |
exit_code=0 | |
terragrunt "${@}" 2>&1 | sed -e "${SED_FILTER}" | tee ${log_file} || exit_code=1 | |
echo "=========================== | |
${BLUEBOLD}>> Resume:${RESET}" | |
cat ${log_file} | grep 'has finished successfully' | sed 's/\[terra.* \[.*\]//' || true | |
cat ${log_file} | grep 'has finished with an erro' | sed 's/\[terra.* \[.*\]//' || true | |
exit ${exit_code} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It works awesome with
TERM=linux