Currently terragrunt hclfmt will recursively modify files. This is very nice but it doesn't work well in CI pipelines to test if code is properly formatted.
Please consider implementing a -check option (or similar) like the one in terraform fmt -check.
That's a good idea. A PR to add this functionality would be very welcome. The idea would be to expose a CLI arg that propagates down to this function (https://github.com/gruntwork-io/terragrunt/blob/master/cli/hclfmt.go#L42), which is then used to toggle between writing the output and checking a diff.
@yorinasub17
What would be the function behavior with check mode enabled? I assume, in case of success, the file won't be written out and error set to nil. But in case of failure, when newContents != contents what would be the return value? Do you want to extend the function by additional return value with a type of bool?
I was imagining it would return an error. I am not a huge fan of overloading the meaning of an error, but in CI, we probably want to bubble an error in the end so that the command exits in a way that causes the build to fail.
The command should probably also be improved to not failfast and instead collect all failures as it goes and report it at the end, similar to what we do with xxx-all (of course, with improved error reporting!).
Basically, in this loop (https://github.com/gruntwork-io/terragrunt/blob/master/cli/hclfmt.go#L30), it should collect the errors in a larger error struct as opposed to just returning the error.
Yeah, totally. As long as the return code is not successful, that's fine. I am on the same page.
Once I am in the office tomorrow, I will come up with PR.
Thanks!
I did come up with PR. But I am unsure about using terragruntOptions.TerraformCliArgs to check Terragrunt specific options. What would be the best option here?
Lastly, comments are more than welcome!
This was released in https://github.com/gruntwork-io/terragrunt/releases/tag/v0.19.16
Most helpful comment
This was released in https://github.com/gruntwork-io/terragrunt/releases/tag/v0.19.16