0
0
Terraformcloud~10 mins

Terragrunt for DRY configurations in Terraform - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Terragrunt for DRY configurations
Write common config in terragrunt.hcl
Reference common config in child modules
Run terragrunt apply in child module
Terragrunt merges configs
Terraform runs with merged config
Infrastructure deployed with DRY configs
Terragrunt lets you write shared config once and reuse it in many places, avoiding repetition.
Execution Sample
Terraform
terraform {
  source = "../modules/app"
}

include {
  path = find_in_parent_folders()
}
Child terragrunt.hcl references common config from parent to reuse settings.
Process Table
StepActionConfig SourceMerged ConfigResult
1Terragrunt reads child terragrunt.hclChild fileChild config onlyPartial config loaded
2Terragrunt finds parent terragrunt.hclParent fileParent config onlyCommon config loaded
3Terragrunt merges parent and child configsParent + ChildCombined configFull config ready
4Terragrunt runs terraform with merged configMerged configFinal configTerraform applies infrastructure
5Terraform deploys resourcesFinal configN/AInfrastructure created
6Execution endsN/AN/ADeployment complete
💡 All configs merged and terraform applied successfully
Status Tracker
VariableStartAfter Step 2After Step 3Final
config{}{common settings}{common + child settings}{merged config}
Key Moments - 2 Insights
Why does Terragrunt look for a parent terragrunt.hcl?
Terragrunt searches parent folders to find shared config to merge with child config, as shown in execution_table step 2 and 3.
What happens if child and parent configs have the same setting?
Child config overrides parent config for that setting during merge (step 3), ensuring specific customization.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step does Terragrunt merge parent and child configs?
AStep 1
BStep 3
CStep 2
DStep 4
💡 Hint
Check the 'Action' column for merging configs in execution_table row 3.
According to variable_tracker, what is the state of 'config' after step 2?
A{}
B{common + child settings}
C{common settings}
D{merged config}
💡 Hint
Look at the 'After Step 2' column for 'config' in variable_tracker.
If the child config overrides a setting from the parent, which step shows this effect?
AStep 3
BStep 2
CStep 1
DStep 5
💡 Hint
Merging configs and resolving conflicts happens at step 3 in execution_table.
Concept Snapshot
Terragrunt helps avoid repeating config by
sharing common settings in a parent terragrunt.hcl.
Child configs include parent with 'include' block.
Terragrunt merges configs before running Terraform.
Overrides in child config customize behavior.
Run 'terragrunt apply' in child folder to deploy.
Full Transcript
Terragrunt is a tool that helps you keep your Terraform configurations DRY, meaning you don't repeat the same settings in many places. You write common configuration once in a parent terragrunt.hcl file. Then, in child folders, you write terragrunt.hcl files that include the parent config using the 'include' block. When you run 'terragrunt apply' in a child folder, Terragrunt reads the child config, finds the parent config, merges them together, and then runs Terraform with the combined configuration. If the child config has settings that overlap with the parent, the child's settings take priority. This way, you can share common infrastructure settings and customize only what you need in each child folder. The execution table shows these steps clearly, from reading configs to merging and applying infrastructure. The variable tracker shows how the configuration state changes as Terragrunt processes the files. This approach saves time and reduces errors by avoiding duplicated code.