Skip to content

tfcensus inventory ​

inventory discovers units the way units does, then reads each unit's state from its s3 backend with s3:GetObject. It takes no lock, so it is safe to run during an apply. Other workspaces of a unit are found with s3:ListBucket under workspace_key_prefix (default env:) and listed as their own rows.

inventory prints identifiers and counts only: never attribute values. Raw state records which providers a unit uses but not their versions, so provider versions come from the unit's .terraform.lock.hcl when the repo has one.

State is read with the backend's credentials: the backend's profile when it names one, else the profile that owns the bucket's account (accounts.map, then the --profile and --org accounts, then the default credentials), with the backend's role_arn assumed from it. The bucket's account is the role's account, or the unit's target account when there is no role.

A state that can't be read (access denied, a parse error) is reported for its unit and the run continues; inventory then exits 1, or 4 when every read failed on credentials. An OpenTofu state with client-side encryption shows only its serial and lineage, unless --decrypt-with-tofu is set: then tofu init and tofu show -json run in the unit with the unit's key configuration or TF_ENCRYPTION, and a state they can't read fails its unit. --save-index writes the identifier index that whois and scan read, compressed with zstd for a .zst name and gzip for .gz.

Usage ​

sh
tfcensus inventory [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
--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 or csvstring, repeatableplain: table without color
md: Markdown
json: JSON envelope for scripts
csv: comma-separated values
--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
--save-indexwrite the identifier index to this file (.zst: zstd, .gz: gzip, else plain JSON)string

The global flags work with every command.

Output formats ​

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

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.
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 inventory ~/src/infra/acme-live
tfcensus inventory --profile 'acme-*' --format json > inventory.json
tfcensus inventory --format csv --save-index index.json.zst