cloudposse-archives / tfmask

Terraform utility to mask select output from `terraform plan` and `terraform apply`
https://cloudposse.com/accelerate
Apache License 2.0
202 stars 27 forks source link

tfmask appears to swallow exit codes #26

Closed jcreager closed 3 years ago

jcreager commented 3 years ago

Version: 0.7.0

Expected:

If a process piped to tfmask exits with non-zero exit code tfmask should also exit with a non-zero exit code.

Actual:

tfmask always exits with exit code zero regardless of exit code from piped process.

Steps to reproduce:

exit 1 | tfmask && echo "$?"
0

Additional Info:

I am using tfmask in conjunction with terragrunt and I am finding that although terragrunt will exit with a non-zero exit code if it encounters errors the final exit code is remains zero. This ends up being a problem with CI/CD pipelines that report success/failure based on final exit code.

davidji99 commented 3 years ago

I am facing a similar issue where tfmask swallows the exit code of terraform plan -detailed-exitcode.

jcreager commented 3 years ago

@davidji99 I am now realizing that I completely forgot to update this issue. Try set -o pipefail;.

set -o pipefail; exit 1 | tfmask

That should raise the correct exit code.

davidji99 commented 3 years ago

Oh thanks for the tip @jcreager!