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
tfcensus rules test <rules.yaml> [flags]Arguments
| Argument | Required | Repeatable |
|---|---|---|
rules.yaml | yes | no |
Flags
| Flag | Description | Type | Default | Values | Config key | Notes |
|---|---|---|---|---|---|---|
--resource | JSON file with a resource or an array of resources to evaluate | string |
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
| 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 rules test rules.yaml
tfcensus rules test rules.yaml --resource sample.json