Terragrunt Overview & Usage


Terragrunt is a thin wrapper that provides extra tools for keeping your configurations DRY, working with multiple Terraform modules, and managing remote state.


To use it, you:

  1. Install Terraform
  2. Install Terragrunt.
  3. Put your Terragrunt configuration in a terragrunt.hcl file.
  4. Now, instead of running terraform directly, you run the same commands with terragrunt:
  • terragrunt validate
  • terragrunt fmt
  • terragrunt plan
  • terragrunt apply
  • terragrunt output
  • terragrunt destroy

Terragrunt will forward almost all commands, arguments, and options directly to Terraform, but based on the settings in your terragrunt.hcl file.


Here is an example configuration we’ve used for one of the pet projects. The following configuration can be used to deploy modules/infra from the terraform folder. 

Files structure:

Configure Terraform provider:

Add backend configuration:

This will create the terraform S3 bucket and DynamoDB table on your behalf if they don’t exist. Terraform built-in function path_relative_to_include() will automatically set S3 bucket key to the relative path between the root terragrunt.hcl and the child module (so your Terraform state folder structure will match your Terraform code folder structure, which makes it easy to go from one to the other). 

Initialize terragrunt:

Create your environment configuration. This terragrunt.hcl file specifies a terraform { …​ } block that specifies from where to download the Terraform code, as well as the environment-specific values for the input variables in that Terraform code:

Include the configuration from the root terragrunt.hcl:

Terraform function find_in_parent_folders() will automatically search up the directory tree to find the root terragrunt.hcl and inherit the remote_state configuration from it.

Read also

Electrifying updates: new Kubernetes 1.26 release

A new Kubernetes version 1.26, named Electrifying, has been released. It has interesting updates in alpha and beta. Let's dive deeper.

Git and GitFlow Best Practice

A version control system, or VCS, monitors the history of changes when individuals and teams work on projects. As developers make modifications to the project, any previous version can be retrieved at any time. Nowadays Git is the most popular VCS, so let's talk a bit about it.