gruntwork-io / terragrunt

Terragrunt is a flexible orchestration tool that allows Infrastructure as Code written in OpenTofu/Terraform to scale.
https://terragrunt.gruntwork.io/
MIT License
8.07k stars 979 forks source link

Tooling to Enforce good workflow? #412

Open john-mcgowan-wowza opened 6 years ago

john-mcgowan-wowza commented 6 years ago

This isn't really an issue, but thought this would be a good place to add this question.

I've been working with tg for a couple weeks now and I really like it. It really helps keep me sane while managing my tf environments.

I was wondering if it would be useful for terragrunt to have options to help enforce good workflow practices? For example, a pre-apply check that makes sure that if you're in a git repo it's fully up to date with origin and everything is committed/pushed?

Personally I've started to build this sort of tooling with Rake and I really like it.

I've also enabled the Rakefile to automatically infer a terragrunt-source param when I pass it a flag that says I want to use a local copy of the tf module.

I would love it if I didn't have to use another tool to do these sorts of things and just wondering what the TG authors would think about this type of [optional] functionality being added to tg?

brikis98 commented 6 years ago

Hi @john-mcgowan-wowza! Yes, we'd love something of this sort. Quite a few folks have asked for it, and we've needed it for our own use cases, but haven't had enough time to think through a nice design and build it.

One of the ideas we had in #377, at least as a starting point, is to add "hooks" to the Terragrunt configuration that allow you to execute arbitrary code before/after a Terragrunt command. Some "built-in" hooks, such as a "everything committed/pushed" check, would be great too. A PR for that would be very welcome :)

john-mcgowan-wowza commented 6 years ago

Thanks @brikis98 .

Ok, good to know that this type of thing would be appreciated. As I continue to build out features in my Rake wrapper I'm going to give some thought as to how they might translate into terragrunt pre/post operational hooks.

Am I right in assuming that we'd never really want to have terragrunt smart enough to check something like the status of the git repo and that kind of functionality would be farmed out to external scripts/programs. Or is there any precedent for baking in some common patterns so that we don't need to rely on external scripts for something as common as "never run apply unless git fetch/pull/status is clean"

brikis98 commented 6 years ago

Am I right in assuming that we'd never really want to have terragrunt smart enough to check something like the status of the git repo and that kind of functionality would be farmed out to external scripts/programs.

I think it would make sense to start with generic patterns, such as hooks, as those would be useful for just about all cases.

Checking git status is definitely more specialized, but if there is enough interest in it, it might make sense to add. That said, a bash script to check git status would likely be just a few lines, and easy to use from a Terragrunt "hook" too.

john-mcgowan-wowza commented 6 years ago

I'm going to Add my further comments over on #377 , because I agree with you, that that is the best way to get this feature rolling.