tfcensus units
units lists the Terragrunt units and plain Terraform/OpenTofu root modules under each path, with where each one keeps its state and which AWS account and region it manages.
A path with a terragrunt.hcl, root.hcl or terragrunt.stack.hcl anywhere below it is a Terragrunt repo: terragrunt find lists its units. Any other path is searched for root modules, which are directories whose .tf files have a backend or cloud block.
tfcensus evaluates remote_state itself (the fast path). get_aws_account_id there returns the account of the default AWS credentials (AWS_PROFILE, environment credentials or an instance role), looked up once with sts:GetCallerIdentity and only when state needs it. With --render auto, units the fast path can't evaluate, for example because they call run_cmd or set iam_role, go to terragrunt render --json. Units that neither method resolves are listed with the reason. Without paths, units uses discovery.roots from the config, or the working directory.
Usage
tfcensus units [paths...] [flags]Arguments
| Argument | Required | Repeatable |
|---|---|---|
paths | no | yes |
Flags
| Flag | Description | Type | Default | Values | Config key | Notes |
|---|---|---|---|---|---|---|
--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 | |||
--md-max-chars | cut Markdown output to this many characters at a row or section boundary; 0 means no limit | int | 60000 | |||
--out | also write the report to a file as format=path (repeatable); format is one of plain, md or json | string, repeatable | plain: table without colormd: Markdownjson: JSON envelope for scripts | |||
--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. 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. |
| 130 | Interrupted by Ctrl-C (SIGINT) or a cancelled context. |
All codes are listed on the exit codes page.
Examples
tfcensus units ~/src/infra/acme-live
tfcensus units --filter './live/prod/**' --format json
tfcensus units --render never --generate-stacks