Using Terragrunt’s generate block to make your Terraform DRY
As you write more Terraform modules for your Infrastructure as Code (IaC), you will notice some repetitions across all your modules. An example of this is the provider
block. Terragrunt’s generate
block can be used to eliminate this repetition and keep your Terraform DRY.
Example Time
Let’s say you have the following directory structure for your IaC
terragrunt/
- terragrunt.hcl
- vpc/
- terragrunt.hcl
- security_groups/
- terragrunt.hcl
modules/
- vpc/
- main.tf
…