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
tfcensus inventory [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 | |||
--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 or csv | string, repeatable | plain: table without colormd: Markdownjson: JSON envelope for scriptscsv: comma-separated values | |||
--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 | |
--save-index | write 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
| 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. |
| 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 inventory ~/src/infra/acme-live
tfcensus inventory --profile 'acme-*' --format json > inventory.json
tfcensus inventory --format csv --save-index index.json.zst