CoursesTerragruntIntermediate

Inputs, includes & locals

Share config across units.

Advanced12 min · lesson 6 of 12

Beyond state, Terragrunt keeps inputs and settings DRY through includes and locals. An include pulls configuration from a parent file (the same mechanism as the shared backend), and Terragrunt merges parent and child — so common inputs (region, tags, account id) live in a parent and each unit adds only its specifics. locals define reusable values within a file, and you can read shared data (like a region config) from a parent locals file.

THE INCLUDE / MERGE HIERARCHY
Repo root (root.hcl)
backend
remote_state, one definition
provider
generated once
Account level (account.hcl)
assume-role
per-account credentials
account id
Environment level (env.hcl)
aws_region
e.g. us-east-1
common_tags
environment, owner
Unit (terragrunt.hcl)
module source
pinned ref
specific inputs
e.g. instance_type
Terragrunt deep-merges each level top-down; a unit inherits everything above it unless it overrides the value.
live/prod/env.hcl
locals {
environment = "prod"
aws_region = "us-east-1"
common_tags = { environment = "prod", owner = "platform" }
}
live/prod/app/terragrunt.hcl
include "root" { path = find_in_parent_folders("root.hcl") }
locals {
env = read_terragrunt_config(find_in_parent_folders("env.hcl")).locals
}
inputs = {
environment = local.env.environment # shared value, defined once
tags = local.env.common_tags
instance_type = "m5.large" # this unit’s specific input
}

Merge behavior and hierarchy

The pattern is a hierarchy of hcl files — a repo root (backend, provider), an account level, an environment level (region, tags), and the unit (its module and specific inputs) — each including the ones above and contributing its layer. Terragrunt deep-merges them, so a value set at the environment level applies to every unit under it unless a unit overrides it. This is how a change like “add a cost-center tag everywhere” is one edit at the right level.

Deep merge means know where a value comes from
With inputs assembled from several included files, a surprising value usually means it was set at a higher level than you were looking. Learn the include hierarchy for your repo, use terragrunt render-json (or terragrunt terragrunt-info) to see the effective merged config, and set each value at the level where it logically belongs so overrides stay predictable.