Repository navigation
feat(terraform): read installed module versions from .terraform/modules/modules.json - #705
Closed
noahkhomer18 wants to merge 1 commit into
Closed
noahkhomer18 wants to merge 1 commit into
noahkhomer18 wants to merge 1 commit into
Conversation
…es/modules.json After terraform init or tofu init, modules.json records the version installed for each module call. A registry module row now takes that Version as resolvedVersion, and drift is computed from it. Each root reads the modules.json next to the files that call the module, nested module calls are not matched, and a source installed at two versions in one root stays unresolved. A missing or malformed file leaves the row unchanged. Closes vibgrate#621. Signed-off-by: Noah Khomer <108771853+noahkhomer18@users.noreply.github.com>
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request
Summary
vg scannow takes a registry module'sresolvedVersionfrom.terraform/modules/modules.json, the fileterraform init/tofu initwrites, and computes drift from that installed version instead of the lowest version the constraint allows. Without the file, rows are unchanged.As you suggested in #621,
Sourcegoes throughpublicRegistryModuleAddress(host stripped, as in #618) before matching, the file is read through theFileCachewhen there is one, and a missing or broken file falls back silently.Three choices beyond the issue, all to keep the version from landing on the wrong row:
<that dir>/.terraform/modules/modules.json. A scan withenvs/stagingon~> 4.0andenvs/prodon~> 5.0(the case the module-pin comment describes) resolves each from its owninit, and a root that was never initialised stays unresolved even when another root has amodules.json.modules.jsonalso lists modules called from inside other modules (Keylikenetwork.vpc). Those entries are skipped, so a nested call's version doesn't attach to a root-level pin with the same source.resolvedVersion.Related issues
Closes #621
Checklist
pnpm test: 596 of 597 files and 5939 of 5940 tests pass. The one failure wastest/freshness.test.ts› "serves the rebuilt graph after files change", a file-watch timing test that passes on its own (15/15, three runs in a row) and doesn't touch the Terraform scanner.pnpm lint: 0 errors. The 5 warnings are the existing ones, none in files touched here.pnpm exec tsc --noEmitis clean.vg drift, next to the.terraform.lock.hclnote, and a CHANGELOG entry under Fixed.Tests
In
test/terraform-scanner.test.ts, a newscanTerraform module resolved versionsblock:~> 5.0with amodules.jsonentry at5.8.1reportsresolvedVersion: '5.8.1'anddrift: 'current'(the acceptance case);envs/stagingandenvs/prod, each with its ownmodules.json, resolve to4.0.2and5.8.1;modules.jsonis not applied to a module declared inenvs/staging;modules.json:resolvedVersion: null,drift: 'minor-behind', as before;modules.jsonfalls back, with and without aFileCache;network.vpc), and one source installed at two versions in one root all leaveresolvedVersion: null.With
terraform-scanner.tsput back tomain, the three tests that expect a resolved version fail; the others pass on both, as guards.