tfcensus audit backend
audit backend discovers units the way units does, reads their state the way inventory does, and checks:
- every s3 bucket the units' backends name (versioning, encryption and key policy, public
access block, TLS-only bucket policy, object ownership, replication, lifecycle, logging),
- every DynamoDB lock table (point-in-time recovery, KMS, stale locks, orphaned digests),
- the fleet: states no unit resolves to, units with no state, empty states, copied lineages,
double-managed resources, old terraform and provider versions, large states, and attribute
names that look like secrets.Each finding names its check (rule), severity, target and reason. Output never contains attribute values: FL-SECRET lists attribute names only. Every call is a read. audit takes no lock.
--discover also lists the buckets of each account (s3:ListAllMyBuckets) and audits those matching --discover-pattern that no unit names; their state keys show up as FL-ORPHAN.
Suppress accepted findings in config with audit.suppress entries: check, bucket, unit and key are globs, reason is required, and after expires (YYYY-MM-DD) the entry stops matching and a warning names it.
The exit code is 3 when an unsuppressed finding is at or above --fail-on, 1 when a check couldn't run, and 4 when every failure was a credential problem.
Usage
tfcensus audit backend [paths...] [flags]Arguments
| Argument | Required | Repeatable |
|---|---|---|
paths | no | yes |
Flags
| Flag | Description | Type | Default | Values | Config key | Notes |
|---|---|---|---|---|---|---|
--concurrency | states read at the same time | int | 16 | |||
--decrypt-with-tofu | read OpenTofu encrypted state with tofu init and tofu show -json in the unit, which downloads and runs its providers (config state.decrypt_with_tofu) | bool | state.decrypt_with_tofu | |||
--discover | also audit buckets of each account that match --discover-pattern and that no unit names | bool | ||||
--discover-pattern | bucket name glob for --discover (repeatable; config audit.discover_patterns) | string, repeatable | audit.discover_patterns | |||
--fail-on | exit 3 when a finding is at least this severe: info, low, medium or high | string | info: worth knowing, no risklow: small riskmedium: fix soonhigh: fix now | |||
--filter | terragrunt filter expression, passed to terragrunt find unchanged (repeatable) | string, repeatable | ||||
--generate-stacks | run terragrunt stack generate first, so units in stacks are listed (config discovery.generate_stacks) | bool | discovery.generate_stacks | |||
--management-profile | profile that lists the organization's accounts, else the default AWS credentials (config accounts.org.management_profile) | string | accounts.org.management_profile | |||
--md-max-chars | cut Markdown output to this many characters at a row or section boundary; 0 means no limit | int | 60000 | |||
--org | list the accounts of the AWS organization and assume --org-role in each (config accounts.org.enabled) | bool | accounts.org.enabled | |||
--org-role | role assumed in each member account (config accounts.org.role) | string | OrganizationAccountAccessRole | accounts.org.role | ||
--out | also write the report to a file as format=path (repeatable); format is one of plain, md, json, csv, sarif or github | string, repeatable | plain: table without colormd: Markdownjson: JSON envelope for scriptscsv: comma-separated valuessarif: SARIF 2.1.0 for code scanninggithub: GitHub Actions annotations | |||
--profile | AWS profile from ~/.aws/config, or a glob such as 'acme-*' (repeatable; config accounts.profiles) | string, repeatable | accounts.profiles | |||
--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 |
The global flags work with every command.
Output formats
--format accepts tty, plain, md, json, csv, 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 |
|---|---|
info | worth knowing, no risk |
low | small risk |
medium | fix soon |
high | fix now |
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. |
| 4 | Credentials were missing or rejected for every source the command needed. |
| 130 | Interrupted by Ctrl-C (SIGINT) or a cancelled context. |
All codes are listed on the exit codes page.
Examples
tfcensus audit backend ~/src/infra/acme-live
tfcensus audit backend --fail-on high --format sarif > audit.sarif
tfcensus audit backend --profile 'acme-*' --discover --format json