Terragrunt: Add color to `terragrunt apply` output

Created on 18 Jan 2018  路  8Comments  路  Source: gruntwork-io/terragrunt

It'd be a better user experience if the output of terragrunt apply(-all):

[terragrunt] [/path/to/live] 2018/01/18 05:56:56 Module /path/to/live has finished successfully!

would produce green-colored output when it's a success (exit 0), and red-colored output when it's a failure (exit 1).

Same for terragrunt destroy, of course.

enhancement help wanted

Most helpful comment

All 8 comments

That's really cool. Would be great to integrate into Terragrunt :)

@brikis98 I just tested and you can just pipe terragrunt into landscape. terragrunt plan | landscape

Sweet!

@davidneudorfer Hmm that didnt work for me on MacOS. Piping everything into "landscape" hides all terraform output and I'm just left with terragrunts output. I have the latest version of each tool as well.

[terragrunt] 2019/01/15 12:27:11 Running command: terraform plan
No changes.

@yuriydee I just updated to the latest versions and everything still works.

terragrunt version v0.17.4
Terraform v0.11.11
Terraform Landscape 0.2.2

@davidneudorfer I took another look and yeah it actually works. So turns out landscape doesnt work when you have no infra changes and it truncates the output to just one line. But when I am removing/adding resources it works for me with both terraform and terragrunt.

The landscape will require ruby and it will increase my pipeline docker image. I wrote this simple solution to help me for now, at least to help us to see errors and visualize the changes.

terragrunt_color

#!/bin/bash

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}

terragrunt ${*} 2>&1 | sed \
    -e "s/\(\\[terragrunt\\] \\[.*\\]\)\( [0-9\\/]* [0-9:]*\) /${BLUEBOLD}\1${BLUERESET}\2${RESET} /" \
    -e "s/\(\\[terragrunt\\]\)\( [0-9\\/]* [0-9:]*\) /${BLUEBOLD}\1${BLUERESET}\2${RESET} /" \
    -e "s/\(Error: \)\(.*\)/${REDBOLD}\1${REDRESET}\2${RESET}/" \
    -e "s/\(Hit multiple errors:\)/${REDBOLD}\1${RESET}/" \
    -e "s/\(exit status 1\)/${RED}\1${RESET}/" \
    -e "s/\( WARNING: \)\(.*\)/${YELLOW}${BOLD}\1${RESET}${YELLOW}\2${RESET}/" \
    -e "s/\( Running command: \)\(.*\)/\1${CYAN}\2${RESET}/" \
    -e "s/\(  *.*:  *\)\(\".*\"\)\( => \)\(\".*\"\)/${YELLOW}\1${RED}\2${BLACK}\3${GREEN}\4${RESET}/" \
    -e "s/\(  *.*:  *\".*\"\)/${GREEN}\1${RESET}/"

./terragrunt_color plan-all
Was this page helpful?
0 / 5 - 0 ratings

Related issues

MacFlurry picture MacFlurry  路  4Comments

ozbillwang picture ozbillwang  路  3Comments

GauntletWizard picture GauntletWizard  路  3Comments

jtai-omniex picture jtai-omniex  路  3Comments

dmlemos picture dmlemos  路  3Comments