Skip to content

tfcensus drift ​

drift runs a plan in every Terragrunt unit and reports the resources that changed outside terraform, attribute by attribute. It runs

text
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-exitcode

in 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 ​

sh
tfcensus drift [paths...] [flags]

Arguments ​

ArgumentRequiredRepeatable
pathsnoyes

Flags ​

FlagDescriptionTypeDefaultValuesConfig keyNotes
--collapsegroup identical changes across units: shape, strict or none (config drift.collapse)stringshapeshape: same type, action and attribute paths
strict: shape, and the same before and after values
none: one group per change
drift.collapse
--fail-onexit 3 when these gates match: drift, drift:reverts or errorslist, repeatabledrift: any unit drifted
drift:reverts: a full plan would revert drift
errors: a unit failed
--filterterragrunt filter expression, passed to terragrunt find unchanged (repeatable)string, repeatablenot with --from-json-out-dir
--from-json-out-dirread the plans of an earlier terragrunt run --json-out-dir instead of running terragruntstringnot with --filter; not with --generate-stacks
--generate-stacksrun terragrunt stack generate first, so units in stacks are listed (config discovery.generate_stacks)booldiscovery.generate_stacksnot with --from-json-out-dir
--md-max-charscut Markdown output to this many characters at a row or section boundary; 0 means no limitint60000
--min-countcount a --fail-on gate needs before it exits 3int1
--modeplan mode: refresh-only or full; full also tells reverted drift from kept drift (config drift.mode)stringrefresh-onlyrefresh-only: plan -refresh-only: drift only
full: plan: drift, and whether the plan reverts it
drift.mode
--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
--renderwhen to use terragrunt render: auto, always or never (config discovery.render)stringautoauto: parse terragrunt.hcl, render the units it can't resolve
always: run terragrunt render for every unit
never: never run terragrunt render
discovery.render
--report-filethe JSON --report-file of that runstring
--show-attributesshow before and after values; sensitive and unknown values stay maskedbool

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
driftany unit drifted
drift:revertsa full plan would revert drift
errorsa unit failed

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.
130Interrupted by Ctrl-C (SIGINT) or a cancelled context.

All codes are listed on the exit codes page.

Examples ​

sh
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