Use tfcmt with terragrunt run-all
Terragrunt is a thin wrapper that provides extra tools for keeping your configurations DRY, working with multiple Terraform modules, and managing remote state.
Terragrunt supports deploying multiple Terraform modules in a single command by terragrunt run-all command, but tfcmt doesn't support the output.
❌ This doesn't work.
$ tfcmt plan -- terragrunt run-all plan
You can solve the issue by Terragrunt's --terragrunt-tfpath option.
- Create a wrapper script of
terraform
and make it executable
$ vi tfwrapper.sh
$ chmod a+x tfwrapper.sh
tfwrapper.sh
#!/bin/bash
set -euo pipefail
command=$1
base_dir=$(git rev-parse --show-toplevel) # Please fix if necessary
target=${PWD#"$base_dir"/}
if [ "$command" == "plan" ]; then
tfcmt -var "target:${target}" plan -- terraform "$@"
elif [ "$command" == "apply" ]; then
tfcmt -var "target:${target}" apply -- terraform "$@"
else
terraform "$@"
fi
- Run
terragrunt run-all
with--terragrunt-tfpath
$ terragrunt run-all plan --terragrunt-tfpath "<absolute path of tfwrapper.sh>"
Then the result of terraform plan
is posted per module.