Back to Terragrunt

dependents of vpc, enclosed within the current environment

docs/src/data/experiments/bounded-discovery.mdx

1.1.33.5 KB
Original Source

Enclose graph traversal for a --filter expression within a directory using an inline (dir) operand, instead of the Git repository root.

bounded-discovery - What it does

Graph-traversing filter expressions reach beyond the working directory. Dependent discovery (...{unit}) requires searching from the working directory of the given component up to the Git repository root (if the unit is within a Git repository). Dependency discovery ({unit}...) requires recursive parsing of dependencies to find the terminal dependency. Either way, Terragrunt has to read and parse every configuration it touches along the way for accuracy. In monorepos where sibling environments cannot be parsed independently of each other, that traversal fails or wastes work reaching into them.

When enabled, this experiment unlocks an inline (dir) boundary operand. It sits in the same operand slot as a traversal depth (e.g. 1...{vpc}):

bash
cd environments/staging
terragrunt find --experiment bounded-discovery --filter '(.)...{vpc}'
text
# dependents of vpc, enclosed within the current environment
(.)...{vpc}

# dependencies of vpc, enclosed within the current environment
{vpc}...(.)

# independent bounds per direction
(../shared)...{vpc}...(.)

Any configuration that is discovered outside the boundary, whether a dependent or a dependency, is not read, parsed, or returned. The boundary must be an existing directory. Relative paths are resolved against the working directory, and a dependent-direction boundary must contain the working directory.

A boundary bounds discovery traversal rather than filtering results, so an in-boundary unit reachable only by passing through an out-of-boundary unit is intentionally excluded. Given a --> b --> c, if b is outside the boundary, traversal from a cannot reach c, and vice-versa.

Because the boundary operand claims ( and ), those characters are no longer read as part of a unit name or path. Wrap a name or path that contains them in braces (e.g. {./weird(name)}) to keep it literal.

The experiment also unlocks the --discovery-boundary flag (env: TG_DISCOVERY_BOUNDARY), which applies one boundary to every --filter expression on the command, in both directions:

bash
cd environments/staging
terragrunt find --experiment bounded-discovery --filter '...{vpc}' --discovery-boundary .

An inline (dir) operand overrides the flag for the expression that carries it. See the --discovery-boundary reference for how the boundary is resolved.

bounded-discovery - How to provide feedback

Provide your feedback in the bounded-discovery Experiment Feedback Discussion.

bounded-discovery - Criteria for stabilization

To transition the bounded-discovery feature to a stable release, the following must be addressed:

  • Confirm a single directory boundary covers the common isolation layouts (per-environment directories, shared parent configuration).
  • Decide whether a boundary should also accept a glob, or remain directory-only.
  • Decide whether path-restricting filter intersections (e.g. ...{unit} | ./**) should narrow the boundary automatically, making the explicit boundary unnecessary for most uses.
  • Decide whether and how the boundary should apply to Git-based filter expressions (e.g. [main...HEAD]).
  • Positive feedback from users relying on the operand and the flag in repositories with isolated environments.