Terragrunt

Taking the GRUNT work out of your Terraform code!

Having worked with Terraform over the last few years I can say that it is an amazing tool and this shows with the popularity of it across the DEVOPS industry.

When using Terraform you create IaC scripts to deploy infrastructure to the main 3 cloud providers (AWS, Azure, GCP) but you can also deploy code to many other cloud providers, databases or services using its ‘Providers’.

As your Terraform code base develops into multiple modules and projects it can be hard to manage all the variables needed to deploy your code via .tfvar files, for example if you have two environments DEV and Prod for a certain deployment you will need two different .tfvar files with variables for each of their environments, which is fine but what you do also end up with is multiple variables that are duplicated and multiple areas where code needs to be updated if anything changes.

This is where Terragrunt comes in to solve this issue by applying a thin wrapper around your Terraform code and makes your code DRY (Don’t Repeat Yourself), it does this by allowing you to have one common Terragrunt file (terragrunt.hcl) at the root of your code and small environment specific Terragrunt files for your environments that filter down and use the common Terragrunt file variables during deployment reducing duplicate code.

Another benefit of Terragrunt is that you no longer need to specify a .tfvar file when deploying your code i.e “Terraform plan -var-file terraform.tfvar”, with Terragrunt you only need to run “Terragrunt plan”or “Terragrunt apply”from the environment location where the Terragrunt file is located.


Summary:

Terragrunt can help you accomplish the following:

  1. Keep your backend configuration DRY
  2. Keep your provider configuration DRY
  3. Keep your Terraform CLI arguments DRY
  4. Promote immutable, versioned Terraform modules across environments

If you think this is something that can help you and your company head over to Terragrunt for more in-depth documentation and examples.

https://terragrunt.gruntwork.io/

Hope this has helped and if you have any questions or anything to add comment below 🙂