Open Alexey-Tsarev opened 10 months ago
The following approach can be used
Update global terragrunt.hcl with the following:
terraform {
extra_arguments "auto_plan_file" {
commands = [
"plan",
]
arguments = ["-out=tfplan.output"]
}
}
Next run the following:
find . -name tfplan.output -exec tf-summarize {} \;
But I don't really like the output. I think there is a need to add some filtering for resources that are not being updated:
+--------+----------+
| CHANGE | RESOURCE |
+--------+----------+
+--------+----------+
+--------+----------+
| CHANGE | RESOURCE |
+--------+----------+
+--------+----------+
+--------+----------+
| CHANGE | RESOURCE |
+--------+----------+
+--------+----------+
+--------+----------+
| CHANGE | RESOURCE |
+--------+----------+
+--------+----------+
+1 to terragrunt support. This would be a huge DX and quality-of-life improvement. I'd donate money to see that developed.
It would be great to have terragrunt support, the logs there are far from the ideal size.
Likewise we'd love terragrunt support!
+1 for terragrunt support.
tf-summarize works on plan generated from terragrunt plan -out tg_plan.txt
.
the issue here is terragrunt run-all
command cannot generate a single plan output file. it will generate plan for each and every module in its respective folder
Alternate solution:
terragrunt run-all plan -out=tgplan
. this will generate plan output of modules in respective module folder. you can check by running find . -name "tgplan" -ls
#!/bin/bash
# Find all files named "tgplan" and iterate over each
find . -type f -name "tgplan" | while read -r tgplan_file; do
# Get the directory of the tgplan file
dir=$(dirname "$tgplan_file")
cd "$dir" || exit
echo "Running tf-summarize on $tgplan_file in directory $dir"
tf-summarize tgplan
cd -
done
Thanks @prabhu43 and @yyarmoshyk for the comments with steps to use tf-summarize with terragrunt.
Is this helpful?
Or do you expect different support in tf-summarize? if yes, you can please provide details on the requirement. cc: @rmittal123 @tide-jamiegwatkin @thiagomaeda @armenr @Alexey-Tsarev
While this works for individual plans, it seems to lack a way to execute a final command after all plans to summarize without a second command invocation:
terraform {
extra_arguments "auto_plan_file" {
commands = ["plan"]
arguments = ["-out=$TF_PLAN_NAME"]
}
after_hook "after_hook" {
commands = ["plan"]
execute = ["sh", "-c", "find . -name $TF_PLAN_NAME -exec tf-summarize {} \\;"]
}
extra_arguments "summarize" {
commands = ["plan"]
env_vars = {
TF_BINARY = "tofu"
TF_PLAN_NAME = "plan.cache"
}
}
}
Currently this has to be scripted out of Terragrunt:
export TF_BINARY=tofu TF_PLAN_NAME=plan.cache
find . -name plan.cache -exec sh -c 'plan="{}"; cd "${plan%'"$TF_PLAN_NAME"'}" && tf-summarize -json '"$TF_PLAN_NAME" \; | jq '.[] | select(keys | length > 0)'
Maybe this could be solved in Terragrunt with a new after_all
hook, or a final_hook
similar to error_hook
.
Note: the output of run-all plan
could be directly piped to jq for formatting, though I am trying to reduce plumbing around each command.
Hi! You have an interesting util, but suddenly it does not work with Terragrunt.
I tried, but I got the following error: