Development, DevOps, LABS

Terragrunt : Terraform the easy way

March 12, 2019

March 12, 2019 by Sergio Robles

We are using Terraform to configure our Infrastructure as Code in AWS and we used it with Terragrunt from the first day.

What is Terragrunt? the official definition

“… is a thin wrap for Terraform that provides additional tools to maintain your Terraform DRY configurations, work with multiple Terraform modules, and manage the remote state.”  (read more)

We have found Terragrunt very useful, it allows us to configure the remote state, locking, additional arguments, etc. depending on the configuration of your terraform.tfvars file.

The best features of Terragrunt for us are:

1) Terraform remote state file parameterized,

Terraform writes the infrastructure state to a remote data store, which can then be shared among all the members of a team and add a lock mechanism to prevent the simultaneous application of changes.

Using Terragrunt we can save the status file using a parameterized path for the Terraform infrastructure state file, for example, using the environment variables.

Using the same code, a terraform.tfvars and environment variables Terraform will be calculated different state files for each environment.

2) Do not Repeat Your Terraform code (DRY), we manage multiple environments of an application and multiple accounts in the cloud.

Normally, you will manage many applications, environments and accounts in the cloud. If you only use terraform, you must work with a folder tree (for example, a directory for each cloud account and a subdirectory for each environment of an Infrastructure as Code). This is a lot to copy and paste the same code.

Using clean Terragrunt, you can forget about this structure. Your code structure is clear as water and all in a flat directory structure.

3) Automation

Using point #1 and #2, we have created a Jenkins Pipeline in order to test the code and get a plan over the real infrastructure.

For us, these small improvements have a lot of value add to our day to day work..

Share on Share on FacebookGoogle+Tweet about this on TwitterShare on LinkedIn

Your email address will not be published. Required fields are marked *