How state is read
inventory, scan, audit backend and whois read the state of every unit they find. tfcensus reads the state objects from S3 itself. It runs no terraform or terragrunt for this, takes no lock and writes nothing back. This page covers what it reads, with which credentials, and what can go wrong.
S3 backends only
tfcensus reads state from the s3 backend. A unit with another backend, such as local, remote or a cloud block, is listed with the status skipped and the warning backend <type>: tfcensus reads state from s3 only. A unit whose backend discovery couldn't resolve is skipped too, with the reason.
Credentials per backend
Each state is read with the credentials that reach its bucket, which can differ from the account the unit manages:
- When the backend names a
profile, tfcensus loads that profile. - Otherwise it finds the profile that owns the bucket's account:
accounts.mapfirst, then the accounts that--profileand--orgselected, then the default AWS credentials. The bucket's account is the account of the backend'srole_arn, or the unit's target account when the backend has no role. - When the backend sets
role_arn, tfcensus assumes that role from the profile it found.
Reading one state takes s3:GetObject, and kms:Decrypt when the bucket uses SSE-KMS. Listing workspaces takes s3:ListBucket. The read-only policy has all three. An access-denied error names the action and the S3 location, so you can tell which grant is missing:
tf-fleet/restricted: error: access denied: s3:GetObject on s3://acme-restricted-tfstate/restricted/terraform.tfstate; the backend credentials need s3:GetObject, and kms:Decrypt when the bucket uses SSE-KMSThe accounts guide shows how to select profiles and map accounts.
No lock
tfcensus reads the state object with s3:GetObject and never touches the lock file or the DynamoDB lock table. A read never blocks a terraform apply, and an apply in progress doesn't block the read. When an apply writes the state during a run, the report shows the version that was current when tfcensus read it.
Workspaces
The s3 backend keeps the default workspace at the backend key, and every other workspace at <workspace_key_prefix>/<workspace>/<key>, with env: as the default prefix. tfcensus lists that prefix with s3:ListBucket and reads every workspace it finds, each as its own row. When the listing is denied, the default workspace is still read, and the unit gets the warning workspaces not listed.
What is kept
tfcensus reads state files of format version 4, which terraform 0.12 and later and every OpenTofu release write. The parser keeps resource addresses, types, provider addresses, IDs, ARNs and identity attributes, and drops every other attribute value. Security group rules are kept only as hashes, for matching. No output, log, cache or saved index holds an attribute value (safety model).
Raw state names the providers a unit uses but not their versions. tfcensus reads the versions from the unit's .terraform.lock.hcl when it has one.
inventory also says which tool applied a state when something shows it: an encrypted state or a provider from registry.opentofu.org means OpenTofu, then a .opentofu-version or .terraform-version file from the unit up to the repo root, then a tofu binary in --tf-path for a Terragrunt unit.
Read statuses
Each row of inventory has one status:
| Status | Meaning |
|---|---|
ok | the state was read |
absent | the state object doesn't exist: the unit was never applied |
encrypted | OpenTofu client-side encryption; only serial and lineage are readable (read encrypted state) |
unsupported | a state format older than version 4, written by terraform before 0.12 |
error | the read failed, for example access denied; the reason is under the table |
skipped | no s3 backend to read |
A failed read is reported for its unit and the run goes on with the others. inventory then exits 1, or 4 when every read failed on credentials (exit codes).
REPO UNIT WORKSPACE STATUS SERIAL VERSION RESOURCES SIZE MODIFIED PROVIDERS
tf-fleet app default ok 7 1.12.2 7 5.0 KiB 2026-11-09 08:30 hashicorp/aws 6.20.0, hashicorp/random 3.7.2
tf-fleet edge default ok 19 1.10.6 (opentofu) 2 1.2 KiB 2026-11-09 08:30 hashicorp/aws
tf-fleet edge staging ok 3 1.10.6 (opentofu) 1 726 B 2026-11-09 08:30 hashicorp/aws
tf-fleet legacy default unsupported 88 0.11.14 - 469 B 2026-11-09 08:30 -
tf-fleet network default ok 42 1.5.7 (terraform) 7 5.3 KiB 2026-11-09 08:30 hashicorp/aws
tf-fleet planned default absent - - - - - -
tf-fleet restricted default error - - - - - -
tf-fleet secure default encrypted 12 - - 236 B 2026-11-09 08:30 -
tf-fleet shared default ok 2 1.11.4 0 181 B 2026-11-09 08:30 -
tf-fleet/legacy: unsupported state format version 3: tfcensus reads version 4 (Terraform 0.12 and later)
tf-fleet/restricted: error: access denied: s3:GetObject on s3://acme-restricted-tfstate/restricted/terraform.tfstate; the backend credentials need s3:GetObject, and kms:Decrypt when the bucket uses SSE-KMS
tf-fleet/restricted: workspaces not listed: access denied: s3:ListBucket on s3://acme-restricted-tfstate/env:/; the backend credentials need s3:ListBucket
tf-fleet/secure: state is encrypted with OpenTofu client-side encryption, so only serial and lineage are readable; --decrypt-with-tofu reads it with tofu show -json in the unit
double-managed aws_security_group account_id=111111111111,id=sg-0123456789abcdef0,region=eu-west-1 by tf-fleet/app (aws_security_group.legacy_web) and tf-fleet/network (aws_security_group.web) (matched on identity)
9 states: 5 ok, 1 absent, 1 encrypted, 1 unsupported, 1 error, 0 skipped; 17 resource instances, 1 double-managedStates are read 16 at a time. inventory --concurrency changes that.
The identifier index
inventory --save-index <file> writes every managed resource's identifiers to a file: unit, workspace, address, type, provider, ID, ARN, identity, account and region. whois --index, scan --index and mcp --index read it later without AWS credentials. A name ending in .zst is compressed with zstd, and .gz with gzip. The whois guide shows how to use it offline.
Feed relgap
relgap is a sibling tool that reports which tool versions your repositories pin. Its drift command finds version drift across repos, and with --from-tfcensus it takes the list of roots from the JSON that tfcensus inventory --format json prints:
tfcensus inventory ~/src/infra/acme-live --format json > inventory.jsonrelgap's guide to drift --from-tfcensus shows the rest.