Terraform/Terragrunt: Hide Refreshing State..., Reading..., Read complete after... output

Terraform (and terragrunt) gives a lot of output when running plan or apply, outputting a lot of progress information when refreshing the state before creating the plan. They have reasons for this but it doesn't look like there is going to be any silent flags any time soon Show archive.org snapshot . Especially when running larger environments or running multiple modules with terragrunt, this will clog the output on your terminal or in your CI jobs, possibly making the signal hard to find among the noise.

Here are two simple shell function to wrap terraform and terragrunt and ignore most of the noise. Add it to your .bashrc or .zshrc.

tg() {
    terragrunt $@ | grep -v "Refreshing state...\|Reading...\|Read complete after"
}
tf() {
    terraform $@ | grep -v "Refreshing state...\|Reading...\|Read complete after"
}

Now you can just use tf or tg. If you need the additional progress indicator for debugging why the plan step is taking so long, just use the regular terraform resp. terragrunt commands.

Wrapping terraform or terragrunt in grep has conflicts with output buffering. When you're running an apply job, you won't see the prompt to type yes. You can still type yes at that point though and it will continue without issues.

Florian Heinle 7 months ago