Skip to content

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 ​

sh
tfcensus units [paths...] [flags]

Arguments ​

ArgumentRequiredRepeatable
pathsnoyes

Flags ​

FlagDescriptionTypeDefaultValuesConfig keyNotes
--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
--md-max-charscut Markdown output to this many characters at a row or section boundary; 0 means no limitint60000
--outalso write the report to a file as format=path (repeatable); format is one of plain, md or jsonstring, repeatableplain: table without color
md: Markdown
json: JSON envelope for scripts
--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. 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.
130Interrupted by Ctrl-C (SIGINT) or a cancelled context.

All codes are listed on the exit codes page.

Examples ​

sh
tfcensus units ~/src/infra/acme-live
tfcensus units --filter './live/prod/**' --format json
tfcensus units --render never --generate-stacks