Terraform Configuration management Terragrunt
10/29/2022
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:
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.
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).
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:
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.