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 providerblock. 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

--

--

--

Be Happy, Be Awesome! We deliver high-quality digital services to citizens and businesses in Singapore 😊

Recommended from Medium

Research Summary: WIP: Finding Bugs Automatically in Smart Contracts with Parameterized Invariants

Repeating and Missing Number in Array

Interested in Machine Learning on AWS?

Log Monitoring in Docker & Kubernetes by Garylog and Filebeat

Django Blog Tutorial: Model View Template P2

Django Blog Tutorial: Model View Template P2

moving docker images around using ssh and pipe

Deep Dive into Apache Spark DateTime Functions

Just wow them 1 time!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Salihan Zaol-kefli

Salihan Zaol-kefli

Software Engineer, Amateur Writer, Casual Gamer

More from Medium

Terraform Module Testing with LocalStack and GitHub Actions

Terraform + LocalStack + GitHub = Heart Eyes Emoji

Ephemeral AWS Credentials with Vault and Terraform

Infrastructure Problems that Spacelift Solves

Move your resources in Terraform state