Skip to content

tfcensus rules test ​

rules test compiles the built-in packs and the rules in a YAML file (a list under rules:, the same shape as the config key) and reports the first error with the rule name and column.

With --resource, it evaluates every rule against each resource in a JSON file (one object or an array) and prints the trace: each rule's outcome and the category of the first match. A resource has the fields a rule sees as resource: account, region, type, source_type, tf_types, arn, id, name, tags, attrs, layer, sources, parents, relationships and created. scan --explain --format json prints resources in this shape.

Packs, never_hide and the config's rules come from the loaded config; the file's rules run after the config's. rules test makes no AWS calls. Expired rules show as expired.

Usage ​

sh
tfcensus rules test <rules.yaml> [flags]

Arguments ​

ArgumentRequiredRepeatable
rules.yamlyesno

Flags ​

FlagDescriptionTypeDefaultValuesConfig keyNotes
--resourceJSON file with a resource or an array of resources to evaluatestring

The global flags work with every command.

Output formats ​

--format accepts tty, plain, 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 rules test rules.yaml
tfcensus rules test rules.yaml --resource sample.json