Skip to content

Commit d1bf070

Browse files
committed
feat(infra): a Terraform module call IMPORTS its source; module.X.Y reads its output
A module call with a local source -- `module "net" { source = "./modules/net" }` -- linked nothing: 379 such calls on the 7 Terraform repositories of 17 infrastructure corpora, and every `module.net.id` reached at most the calling block, never the output it reads. Such a call now IMPORTS {local_name, via: terraform, line} the Folder of its source directory (the repository root: the Project), when that directory lies inside the repository and holds .tf / .tofu files; a registry, git or http source, or a path not starting with ./ or ../, makes none. `module.net.id` -- also `module.net[0].id`, `module.net.0.id` and `module.net[*].id` -- USAGEs {ref: output} the `output "id"` of that directory, beside the USAGE of `module.net`. Output reads cross directories, so a run touching any .tf / .tofu file now resolves every module directory of the repository: an unchanged caller keeps its reads when the callee file is re-parsed. A full index takes as long as before; an incremental re-index touching a .tf file pays for parsing them all (+0.24 s on a 2,000-file repository). Measured: 349 of the 379 calls name a directory that exists in the repository and IMPORT it, nothing else (the 30 others name paths a test harness creates or that are absent); 644 of 644 output reads (holding block to output) against an independent reading; the reference pairs of the module resolver stay exact; only edges are added; deterministic over three runs; the incremental re-index equals a full index in 6 scenarios (an output's value edited in the callee, its outputs file deleted, a source moved, a widely called module edited, the root module's caller edited). Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent a9d7a96 commit d1bf070

4 files changed

Lines changed: 358 additions & 107 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ The install script placed beside the binary is **reported, not deleted** — uni
256256
- `DEPENDS_ON` — a Helm chart to the charts it declares (the local chart for a resolvable `file://` repository, otherwise an external `Chart`; the edge keeps `repository`), and a `go.mod` / `requirements.txt` file to an external `Package`; a Dockerfile to the `Image`s it builds on (`via: from`, `copy-from`); an `Image` to the Dockerfile it is built from (`via: build`; `tool`: `skaffold`, `compose`, `docker-build` for `docker` / `podman` / `nerdctl` / `buildah` build commands in scripts, Make and CI); a compose service to the services its `depends_on` / `links` name
257257
- `CONFIGURES` — code reading an environment variable to the shared `EnvVar` of that name (`strategy: env_access`); a Kubernetes container, compose service or Dockerfile (`ENV` of the image) setting one to that container's own `EnvVar` (`strategy: env_set`, with `source`: `value`, `configMapKeyRef`, `secretKeyRef`, `fieldRef`, ..., `compose`, `dockerfile` — values are never stored); and that container's `EnvVar` to the code reading the name inside the files its image is built from (`strategy: env_read`, with `dockerfile`) — the image's files are the sources its Dockerfile's `COPY` / `ADD` put into it, less the context's `.dockerignore`
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
259-
- `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
259+
- `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
- `EMITS`, `LISTENS_ON` (channels)
261261
- `DATA_FLOWS` with arg-to-param mapping + field access chains
262262
- `SIMILAR_TO` (MinHash + LSH near-clone detection, Jaccard scored)

0 commit comments

Comments
 (0)