Skip to content

relgap drift ​

Scans each root for repositories the way 'relgap pins' does and prints a matrix with a row per repository and a column per tool that drifts. A tool drifts when its pins stand for more than one version across the scanned repositories. It reads files only and makes no network calls unless --latest is set.

An exact pin counts as its version. A value marked ≈ allows more than one version. A constraint (~> 1.15) counts as the highest exact pin of the tool in the same repository that satisfies it, otherwise as its lower bound (1.15.0). Prefix (26) and channel (latest) pins aren't compared. --drift-ignore-constraints leaves constraint pins out of the comparison too. A version marked * differs from the version most repositories pin.

--from-tfcensus reads the JSON of 'tfcensus inventory --format json' (schema_version 1) instead of scanning, or as well when roots are given. Each unit and workspace becomes a row named repo/path, with :workspace for a workspace other than default. The version that last wrote the unit's state is an exact terraform pin, or opentofu when tfcensus says OpenTofu applied it, and each provider version from the unit's lock file is an exact tfprovider pin. Units without a version add no pins. The inventory's errors make the report partial. An inventory from another tool or schema version exits 2. - reads it from stdin.

Tools that agree everywhere, or that only one repository pins, are listed below the matrix. --tool limits the report to the named tools and gives each one a column, even when it doesn't drift. Ignore rules in the config drop matching pins.

--latest adds a latest row with the newest stable version of each tool, from GraphQL queries of 10 to 25 tools, sent in parallel.

--format sarif writes a SARIF 2.1.0 log for GitHub code scanning with a result per drifted pin (a compared pin whose version differs from the version most repositories pin, the cells marked *), at the pin's file and line, and a failed result per file that doesn't parse or tool whose latest version can't be listed.

--fail-on drift counts the drifted pins and exits 3 once the count reaches --min-count (default 1). Otherwise a file that doesn't parse, or a tool whose latest version can't be listed, exits 1 after printing the rest.

Roots default to scan.roots, then the current directory, unless --from-tfcensus is set.

Usage ​

sh
relgap drift [roots...] [flags]

Arguments ​

ArgumentRequiredRepeatable
rootsnoyes

Flags ​

FlagDescriptionTypeDefaultValuesConfig keyNotes
--drift-ignore-constraintscompare exact pins only; constraint pins are shown but don't countbool
--fail-onexit 3 when this matches: drift; repeatable (config policy.fail_on)list, repeatabledrift: repositories pin different versionspolicy.fail_on
--from-tfcensusadd the units of this tfcensus inventory JSON as rows (- for stdin); without roots, scan nothingstring
--latestadd the newest stable version of each tool (needs the network or the cache)bool
--md-max-charscut Markdown output to this many characters at a row or section boundary; 0 means no limitint60000
--min-countfindings a --fail-on value needs before it exits 3int1
--outalso write the report to a file as format=path (repeatable); format is one of plain, md, json, sarif or githubstring, repeatableplain: table without color
md: Markdown
json: JSON envelope for scripts
sarif: SARIF 2.1.0 for code scanning
github: GitHub Actions annotations
--submodulesscan checked-out git submodules as repositoriesbool
--toolreport only this tool, with a column even when it agrees; repeatablelist, repeatable

The global flags work with every command.

Output formats ​

--format accepts tty, plain, md, json, sarif, github. Without it, the format is tty when stdout is a terminal and plain otherwise. Formats are described on the global flags page.

Fail-on values ​

--fail-on makes the command exit 3 when the report has a match:

ValueMatches
driftrepositories pin different versions

Exit codes ​

CodeMeaning
0The command finished. With --fail-on, nothing matched.
1The command failed: a read, a write, a child process or a check failed.
2Wrong usage: an unknown command or flag, a bad value or argument, an invalid config file, or a prompt with no terminal.
3A --fail-on gate matched. The report is still written.
4Credentials were missing or rejected for every source the command needed.
130Interrupted by Ctrl-C (SIGINT) or a cancelled context.

All codes are listed on the exit codes page.

Examples ​

sh
relgap drift ~/src/infra
tfcensus inventory ~/src/infra/* --format json | relgap drift --from-tfcensus -
relgap drift ~/src/infra --from-tfcensus inventory.json --tool terraform
relgap drift ~/src/infra --tool terraform --tool terragrunt
relgap drift ~/src/infra ~/src/apps --latest --format md
relgap drift --fail-on drift --drift-ignore-constraints
relgap drift ~/src/infra --fail-on drift --min-count 3 --format sarif > drift.sarif