terragrunt icon indicating copy to clipboard operation
terragrunt copied to clipboard

[WIP] Add a "output-module-groups" command

Open smaftoul opened this issue 2 years ago • 6 comments

Description

Fixes #2016 .

This PR introduces the terragrunt groups-json command which outputs as JSON the groups of modules (as an array of array) of the current stack.

TODOs

Read the Gruntwork contribution guidelines.

  • [ ] Update the docs.
  • [ ] Run the relevant tests successfully, including pre-commit checks.
  • [x] Include release notes. If this PR is backward incompatible, include a migration guide.

Release Notes (draft)

Added the "groups-json" command.

smaftoul avatar Jun 01 '22 07:06 smaftoul

  • [ ] Update the docs.

@denis256 before updating docs, do you have a suggestion that is better than "groups-json" for the command name ?

  • [ ] Run the relevant tests successfully, including pre-commit checks.

The PR doesn't modify any code, though, I should probably add some tests ?

smaftoul avatar Jun 01 '22 12:06 smaftoul

Hi, since is related to reading output, I was thinking about something output-xxx

denis256 avatar Jun 03 '22 11:06 denis256

Hi, since is related to reading output, I was thinking about something output-xxx

denis256 avatar Jun 03 '22 11:06 denis256

@smaftoul thank you for the PR! I am very excited to see it might be implemented soon 🤞 🙏

CarterSheehan avatar Sep 13 '22 23:09 CarterSheehan

@CarterSheehan Hi ! Thanks for pinging, I stopped working on this because I have been fired (like a lot of startups are laying off) and took some holidays ... I should definitely finish this feature, as it almost already works !

smaftoul avatar Sep 14 '22 06:09 smaftoul

@smaftoul I like this feature a lot for cicd, but I am not clear exactly how it is intended to be used. When I run it, I just get the same module list as normal, except it is in json (which is useable, but takes a lot of additional work). What I was thinking would be most useful and applicable to cicd would be to run a command at the root that will automatically

  1. get module groups
  2. for Group1, run a plan for all modules and check if there are any changes
  3. if there are changes, output a plan file and exit (ci tools can then post this for human review, which will then get ingested into an apply
  4. if there are no changes to Group1, then move on to Group2

This nicely separates each dependency layer in your stack, and ensures that you have as much knowledge as possible about each deployment's consequences. No more having to fiddle around with "mock outputs", because modules only have a plan attempted when all previous-order modules have no pending changes.

Wish I could help, but I am still learning Go

phillip-constantine avatar Sep 15 '22 21:09 phillip-constantine

Would love to see this @smaftoul ! I believe that this output can enable you to code what you are describing @phillip-constantine, but I don't think the whole process should be managed by Terragrunt.

Laudenlaruto avatar Feb 03 '23 16:02 Laudenlaruto

I've added the documentation required :)

Laudenlaruto avatar Feb 07 '23 14:02 Laudenlaruto

Thanks @Laudenlaruto, getting this PR out of WIP ... after 9 month waiting for a bit of doc ;)

smaftoul avatar Feb 07 '23 14:02 smaftoul

@denis256 can I request a review on this ?

smaftoul avatar Mar 27 '23 09:03 smaftoul

Hey @denis256 can I request a review ? :)

Laudenlaruto avatar May 23 '23 12:05 Laudenlaruto

[INFO] Initializing environment for https://github.com/gruntwork-io/pre-commit.
Terraform fmt............................................................Passed
goimports................................................................Failed
- hook id: goimports
- files were modified by this hook

cli/cli_app.go
configstack/module.go
configstack/module.go
cli/cli_app.go
configstack/module.go

denis256 avatar May 24 '23 20:05 denis256

Up on the review @denis256 :)

Laudenlaruto avatar Jul 13 '23 13:07 Laudenlaruto

Also, there are no tests in this pull request, how we will know in the future that this feature will continue to work without it?

Some examples can be found in integration_test.go, TestRenderJsonAttributesMetadata

I've implemented a test close to the TestTerragruntOutputFromDependency test. WDYT ?

Laudenlaruto avatar Jul 24 '23 16:07 Laudenlaruto

Looks like CI build is failing:

Stderr: # github.com/gruntwork-io/terragrunt/cli
cli/cli_app.go:643:50: not enough arguments in call to configstack.FindStackInSubfolders
	have (*options.TerragruntOptions)
	want (*options.TerragruntOptions, *config.TerragruntConfig)

denis256 avatar Jul 24 '23 19:07 denis256

Looks like CI build is failing:

Stderr: # github.com/gruntwork-io/terragrunt/cli
cli/cli_app.go:643:50: not enough arguments in call to configstack.FindStackInSubfolders
	have (*options.TerragruntOptions)
	want (*options.TerragruntOptions, *config.TerragruntConfig)

Fixed 🔨

Laudenlaruto avatar Jul 25 '23 08:07 Laudenlaruto