Skip to content

tfcensus audit backend ​

audit backend discovers units the way units does, reads their state the way inventory does, and checks:

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

sh
tfcensus audit backend [paths...] [flags]

Arguments ​

ArgumentRequiredRepeatable
pathsnoyes

Flags ​

FlagDescriptionTypeDefaultValuesConfig keyNotes
--concurrencystates read at the same timeint16
--decrypt-with-tofuread OpenTofu encrypted state with tofu init and tofu show -json in the unit, which downloads and runs its providers (config state.decrypt_with_tofu)boolstate.decrypt_with_tofu
--discoveralso audit buckets of each account that match --discover-pattern and that no unit namesbool
--discover-patternbucket name glob for --discover (repeatable; config audit.discover_patterns)string, repeatableaudit.discover_patterns
--fail-onexit 3 when a finding is at least this severe: info, low, medium or highstringinfo: worth knowing, no risk
low: small risk
medium: fix soon
high: fix now
--filterterragrunt filter expression, passed to terragrunt find unchanged (repeatable)string, repeatable
--generate-stacksrun terragrunt stack generate first, so units in stacks are listed (config discovery.generate_stacks)booldiscovery.generate_stacks
--management-profileprofile that lists the organization's accounts, else the default AWS credentials (config accounts.org.management_profile)stringaccounts.org.management_profile
--md-max-charscut Markdown output to this many characters at a row or section boundary; 0 means no limitint60000
--orglist the accounts of the AWS organization and assume --org-role in each (config accounts.org.enabled)boolaccounts.org.enabled
--org-rolerole assumed in each member account (config accounts.org.role)stringOrganizationAccountAccessRoleaccounts.org.role
--outalso write the report to a file as format=path (repeatable); format is one of plain, md, json, csv, sarif or githubstring, repeatableplain: table without color
md: Markdown
json: JSON envelope for scripts
csv: comma-separated values
sarif: SARIF 2.1.0 for code scanning
github: GitHub Actions annotations
--profileAWS profile from ~/.aws/config, or a glob such as 'acme-*' (repeatable; config accounts.profiles)string, repeatableaccounts.profiles
--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

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:

ValueMatches
infoworth knowing, no risk
lowsmall risk
mediumfix soon
highfix now

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