tfcensus drift
drift runs a plan in every Terragrunt unit and reports the resources that changed outside terraform, attribute by attribute. It runs
terragrunt run --all [--filter ...] --tf-path <bin> --json-out-dir <tmp> --report-file <tmp>/report.json
--report-format json --log-format json -- plan -refresh-only -lock=false -detailed-exitcodein each repo, with TG_TF_PATH set, and reads every unit's tfplan.json and the run report. Plain Terraform root modules are skipped. With --mode full, the plan isn't refresh-only, and drift tells the drift the plan reverts (the code disagrees) from the drift it keeps.
--from-json-out-dir reads plans an earlier terragrunt run wrote, without running anything. Pass the same run's --report-file, so units that failed before writing a plan are reported.
Identical changes in several units become one group (--collapse shape compares type, action and attribute paths; strict also compares values; none keeps one group per change). Noise rules under drift.noise hide attribute changes or whole changes; the presets aws-tags-all and computed-hashes hide tags_all updates and computed hashes. A rule past its expires date stops hiding drift and drift warns. drift.never_hide (default delete and replace) lists actions no rule can hide.
drift prints attribute paths, never values. --show-attributes adds before and after values; sensitive values show as (sensitive) and unknown ones as (known after apply).
The exit code is 3 when a --fail-on gate counts at least --min-count: drift counts drifted resources, drift:reverts the ones the plan reverts (--mode full only), errors the failed units. It is 1 when a unit or a repo failed and no gate matched, and 0 otherwise. terraform's -detailed-exitcode (2 for changes) is read internally and never returned.
Usage
tfcensus drift [paths...] [flags]Arguments
| Argument | Required | Repeatable |
|---|---|---|
paths | no | yes |
Flags
| Flag | Description | Type | Default | Values | Config key | Notes |
|---|---|---|---|---|---|---|
--collapse | group identical changes across units: shape, strict or none (config drift.collapse) | string | shape | shape: same type, action and attribute pathsstrict: shape, and the same before and after valuesnone: one group per change | drift.collapse | |
--fail-on | exit 3 when these gates match: drift, drift:reverts or errors | list, repeatable | drift: any unit drifteddrift:reverts: a full plan would revert drifterrors: a unit failed | |||
--filter | terragrunt filter expression, passed to terragrunt find unchanged (repeatable) | string, repeatable | not with --from-json-out-dir | |||
--from-json-out-dir | read the plans of an earlier terragrunt run --json-out-dir instead of running terragrunt | string | not with --filter; not with --generate-stacks | |||
--generate-stacks | run terragrunt stack generate first, so units in stacks are listed (config discovery.generate_stacks) | bool | discovery.generate_stacks | not with --from-json-out-dir | ||
--md-max-chars | cut Markdown output to this many characters at a row or section boundary; 0 means no limit | int | 60000 | |||
--min-count | count a --fail-on gate needs before it exits 3 | int | 1 | |||
--mode | plan mode: refresh-only or full; full also tells reverted drift from kept drift (config drift.mode) | string | refresh-only | refresh-only: plan -refresh-only: drift onlyfull: plan: drift, and whether the plan reverts it | drift.mode | |
--out | also write the report to a file as format=path (repeatable); format is one of plain, md, json, sarif or github | string, repeatable | plain: table without colormd: Markdownjson: JSON envelope for scriptssarif: SARIF 2.1.0 for code scanninggithub: GitHub Actions annotations | |||
--render | when to use terragrunt render: auto, always or never (config discovery.render) | string | auto | auto: parse terragrunt.hcl, render the units it can't resolvealways: run terragrunt render for every unitnever: never run terragrunt render | discovery.render | |
--report-file | the JSON --report-file of that run | string | ||||
--show-attributes | show before and after values; sensitive and unknown values stay masked | bool |
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:
| Value | Matches |
|---|---|
drift | any unit drifted |
drift:reverts | a full plan would revert drift |
errors | a unit failed |
Exit codes
| Code | Meaning |
|---|---|
| 0 | The command finished. With --fail-on, nothing matched. |
| 1 | The command failed: a read, a write, a child process or a check failed. |
| 2 | Wrong usage: an unknown command or flag, a bad value or argument, an invalid config file, or a prompt with no terminal. |
| 3 | A --fail-on gate matched. The report is still written. |
| 130 | Interrupted by Ctrl-C (SIGINT) or a cancelled context. |
All codes are listed on the exit codes page.
Examples
tfcensus drift ~/src/infra/acme-live --filter './live/prod/**' --fail-on drift
tfcensus drift --mode full --fail-on drift:reverts --format md > drift.md
tfcensus drift --from-json-out-dir out --report-file out/report.json --format github \
--out sarif=drift.sarif --out md=drift.md --fail-on drift