Terragrunt - Keep providers and backend DRY

Hi Guys,

Recently I have started exploring Terragrunt for our projects. One of the issue I have is, I am repeating myself in defining provider and backend for each module in live project. Dont want to keep it in the modules because it can be used by others for different providers and backends.

Please share is there any better way to manage this with terragrunt. I was thinking about writing a wrapper script to achieve this but if there is a solution already I am looking to reuse.

Thanks

This is exactly a use-case for hooks in Terragrunt which will be executed before or after some commands.

I use this code to copy main_providers.tf where providers configuration is defined:

terragrunt = {
  terraform {
    after_hook "copy_common_main_providers" {
      commands = ["init-from-module"]
      execute  = ["cp", "${get_parent_tfvars_dir()}/../common/main_providers.tf", "."]
    }
  }
}
2 Likes

Thank you. It helped me to achieve the goal.