Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terragrunt support #65

Open
Alexey-Tsarev opened this issue Jan 19, 2024 · 8 comments
Open

Terragrunt support #65

Alexey-Tsarev opened this issue Jan 19, 2024 · 8 comments
Labels
help wanted Extra attention is needed

Comments

@Alexey-Tsarev
Copy link

Hi! You have an interesting util, but suddenly it does not work with Terragrunt.

I tried, but I got the following error:

terragrunt run-all plan --terragrunt-non-interactive --terragrunt-working-dir ./vpc | tf-summarize
INFO[0000] The stack at ./vpc will be processed in the following order for command plan:
Group 1
- Module .../vpc

error when parsing input: invalid character '\x1b' looking for beginning of value
@yyarmoshyk
Copy link

yyarmoshyk commented Feb 16, 2024

The following approach can be used

  1. 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 |
+--------+----------+
+--------+----------+

@armenr
Copy link

armenr commented Mar 9, 2024

+1 to terragrunt support. This would be a huge DX and quality-of-life improvement. I'd donate money to see that developed.

@thiagomaeda
Copy link

It would be great to have terragrunt support, the logs there are far from the ideal size.

@tide-jamiegwatkin
Copy link

Likewise we'd love terragrunt support!

@dineshba dineshba added the help wanted Extra attention is needed label Oct 10, 2024
@rmittal123
Copy link

+1 for terragrunt support.

@prabhu43
Copy link

prabhu43 commented Oct 26, 2024

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:

  • Save plan out in corresponding modules. 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
  • Use a script to run tfsummarize on each plan file generated in all subfolders
#!/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

@dineshba
Copy link
Owner

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

@LEI
Copy link

LEI commented Nov 11, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

9 participants