tfcensus notify
notify reads the JSON that scan, drift and audit print with --format json and publishes it. It never collects anything itself.
slack one message per report to an incoming webhook, with counts and the top
findings; sent only when there is something to report (notify.slack.when)
github-issues one issue per scope: per unit for drift, per account for scan and audit.
A re-run updates the body only when it changed, and closes the issue when
the run covered the scope and found nothing. notify.github_issues.max_open
caps new issues
github-pr-comment one comment per report on a GitHub pull request, edited in place. The
pull request comes from GITHUB_EVENT_PATH; a report with nothing open
turns the comment into "Nothing to report"
bitbucket-pr-comment one comment per report on a Bitbucket Cloud pull request, edited in place
file tfcensus-<kind>.md and .json in notify.file.dir, rewritten only on changeEvery issue body and comment starts with a hidden marker that names the report kind, the scope and a hash of the body, so runs find their own issues and skip unchanged ones. Only issues with the tfcensus label are read.
Secrets come from the environment only: the variables named by notify.slack.webhook_env, notify.github_issues.token_env, notify.github_pr_comment.token_env and notify.bitbucket_pr_comment.token_env. They are never logged; -vvv shows request headers with Authorization redacted.
--dry-run-notify reads the existing issues and comments with GET requests and prints what would change, writing nothing.
Exit codes: 0 when every notifier succeeded, 2 when no notifier is enabled, a notifier is unknown or not configured, or a --from file is not a tfcensus report, 4 when every failure was a refused token, and 1 for any other failure.
Usage
tfcensus notify [flags]Flags
| Flag | Description | Type | Default | Values | Config key | Notes |
|---|---|---|---|---|---|---|
--dry-run-notify | print what would change; read with GET only and write nothing | bool | ||||
--from | scan, drift or audit JSON file (repeatable) | string, repeatable | ||||
--notify | notifiers to run instead of notify.enabled: slack, github-issues, github-pr-comment, bitbucket-pr-comment or file | list, repeatable | slack: one message per report to an incoming webhookgithub-issues: one GitHub issue per scopegithub-pr-comment: one comment per report on a GitHub pull requestbitbucket-pr-comment: one comment per report on one pull requestfile: tfcensus-<kind>.md and .json files |
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. |
| 4 | Credentials were missing or rejected for every source the command needed. |
| 130 | Interrupted by Ctrl-C (SIGINT) or a cancelled context. |
All codes are listed on the exit codes page.
Examples
tfcensus drift --format json > drift.json; tfcensus notify --from drift.json --notify github-issues
tfcensus notify --from scan.json --from audit.json --dry-run-notify
tfcensus notify --from drift.json --notify github-pr-comment # in a pull_request workflow
GITHUB_TOKEN=... tfcensus notify --from drift.json --notify github-issues,slack