Learn how to use multiple terragrunt configurations to DRY up your architecture.
Highlights
To do this, we will introduce a new env.hcl configuration in each environment:
└── live
├── terragrunt.hcl
├── _env
│ ├── app.hcl
│ ├── mysql.hcl
│ └── vpc.hcl
├── prod
│ ├── env.hcl
│ ├── app
│ │ └── terragrunt.hcl
│ ├── mysql
│ │ └── terragrunt.hcl
│ └── vpc
│ └── terragrunt.hcl
├── qa
│ ├── env.hcl
│ ├── app
│ │ └── terragrunt.hcl
│ ├── mysql
│ │ └── terragrunt.hcl
│ └── vpc
│ └── terragrunt.hcl
└── stage
├── env.hcl
├── app
│ └── terragrunt.hcl
├── mysql
│ └── terragrunt.hcl
└── vpc
└── terragrunt.hcl
The env.hcl configuration will look like the following:
locals {
env = "qa" # this will be prod in the prod folder, and stage in the stage folder.
}
We can then load the env.hcl file in the _env/app.hcl file to load the env string:
locals {
Load the relevant env.hcl file based on where terragrunt was invoked. This works because find_in_parent_folders
always works at the context of the child configuration.
Roll out the change to the qa environment first terragrunt run-all plan --terragrunt-modules-that-include _env/app.hcl --terragrunt-working-dir qa terragrunt run-all apply --terragrunt-modules-that-include _env/app.hcl --terragrunt-working-dir qa # If the apply succeeds to qa, move on to the stage environment terragrunt run-all plan --terragrunt-modules-that-include _env/app.hcl --terragrunt-working-dir stage terragrunt run-all apply --terragrunt-modules-that-include _env/app.hcl --terragrunt-working-dir stage # And finally, prod. terragrunt run-all plan --terragrunt-modules-that-include _env/app.hcl --terragrunt-working-dir prod terragrunt run-all apply --terragrunt-modules-that-include _env/app.hcl --terragrunt-working-dir prod ([View Highlight] (https://read.readwise.io/read/01h1mvge4qc50sfzmayq9v4ctz))