Skip to content

Commit fb73491

Browse files
committed
feat(infra): a Terragrunt unit IMPORTS what it includes and reads
A Terragrunt unit (terragrunt.hcl) composes itself from other files -- `include` blocks, read_terragrunt_config calls, dependencies on other units -- and the graph held none of it: its blocks only met same-named blocks elsewhere through the generic name matcher. Every unit is now evaluated in its own context, the way Terragrunt evaluates it (also the files it includes): an include IMPORTS {local_name, via: terragrunt, line} the file its path names; a read_terragrunt_config IMPORTS {via: terragrunt, read, line} the file it names -- from the block holding the call or, for a call in an included file, from the unit's include block that brings that file in, `read` naming the file holding the call; a dependency DEPENDS_ON the other unit's terragrunt.hcl; a local terraform source IMPORTS its Folder. Paths may be string templates of find_in_parent_folders (searched from the unit's parent directory upward), dirname and get_terragrunt_dir; anything else is unknown and links nothing. A run holding any .hcl file re-links every unit (a .hcl change takes the full rebuild since the previous commit). Measured on 17 infrastructure repositories: 30 of 30 composition pairs of the 6 units of the Terragrunt repository against an independent evaluator, nothing else; deterministic over three runs; the incremental re-index equals a full index in 5 scenarios (a read file edited or deleted, the included root file edited or reading another file, a unit edited). Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 246d1a0 commit fb73491

4 files changed

Lines changed: 475 additions & 6 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ The install script placed beside the binary is **reported, not deleted** — uni
258258
- `OVERRIDE` with `via: patch` — a Kustomize patch to each object of its kustomization's build it changes (child → base): a patch file's documents to the object of the same kind and name; an inline patch (from the kustomization) or a JSON6902 operation file to what its `target` selects (group, version, kind, name, namespace, label selector); a component's in the build of each kustomization including it. The edge keeps `kustomization`, `patch` and `line`; a patch file is an `IMPORTS` (`local_name: patches`) of its kustomization, never a member of the build
259259
- `USAGE` with `via: terraform` — a Terraform / OpenTofu reference (`var.X`, `local.X`, `module.X`, `data.T.N`, `T.N`) from the top-level block holding it to the block of its module — the `.tf` / `.tofu` files of its directory — that declares it (a `locals` entry: its `locals` block); an entry of the block's `depends_on` list is a `DEPENDS_ON` instead. The edge keeps `ref` (`var`, `local`, `module`, `data`, `resource`) and `line`; a name only mentioned in string text is no reference. A module call with a local source (`module "net" { source = "./modules/net" }`) `IMPORTS` (`local_name`: the module's name) the `Folder` of that directory (the root directory: the `Project`), and `module.net.id` (also `module.net[0].id`, `module.net[*].id`) `USAGE`s (`ref: output`) the `output "id"` there, beside `module.net`
260260
- `OVERRIDE` with `via: tfvars` — a `.tfvars` assignment to a variable the module of its own directory declares, from the file's `Variable` to that `variable` block (the edge keeps `line`); a `.tfvars` file elsewhere is applied by a `-var-file` the repository does not state and links nothing
261+
- Terragrunt (`via: terragrunt`) — a unit (`terragrunt.hcl`), evaluated in its own context: an `include` `IMPORTS` (`local_name`) the file its `path` names; a `read_terragrunt_config` `IMPORTS` (`read`: the file holding the call) the file it names, from the block holding the call or, for a call in an included file, from the unit's `include` block that brings it in; a `dependency` `DEPENDS_ON` the other unit; a local `terraform` `source` `IMPORTS` its `Folder`. Paths may use `find_in_parent_folders`, `dirname` and `get_terragrunt_dir`; anything else is unknown and links nothing
261262
- `EMITS`, `LISTENS_ON` (channels)
262263
- `DATA_FLOWS` with arg-to-param mapping + field access chains
263264
- `SIMILAR_TO` (MinHash + LSH near-clone detection, Jaccard scored)

0 commit comments

Comments
 (0)