Skip to content

Publish reports with notify ​

This guide sets up tfcensus notify in CI, so that drift, unmanaged resources and backend audit findings reach Slack, GitHub issues, a GitHub or Bitbucket pull request, or a file. It also covers what happens on re-runs and how to recover from mistakes. Every flag is on the notify CLI page.

How it works ​

notify reads the JSON that scan, drift and audit backend print with --format json. It never collects anything itself, so you run the collecting command first and pass its output with --from.

Each report is split into scopes: one per unit for drift, one per account for scan and backend audit. Audit findings that name no account go to the fleet scope. Every scope the run covered is listed, including the ones with nothing to report, and those count as resolved.

NotifierWritesRe-run with no change
github-issuesone issue per scopeno request except the list
github-pr-commentone comment per report on one GitHub pull requestno request except the list
bitbucket-pr-commentone comment per report on one Bitbucket Cloud pull requestno request except the list
slackone message per report to an incoming webhooksends again, see Slack
filetfcensus-<kind>.md and tfcensus-<kind>.jsonleaves the files alone

Issue bodies and comments start with a hidden HTML comment:

text
<!-- tfcensus:v1 {"kind":"drift","scope":"acme-live/prod/vpc","hash":"sha256:..."} -->

kind and scope let the next run find the issue again, and hash covers the rest of the body, so an unchanged scope gets no write. tfcensus overwrites manual edits to the body on the next change.

Secrets ​

Secrets come from environment variables only. The config names the variables, never the values:

NotifierVariable (default)Config key
slackSLACK_WEBHOOK_URLnotify.slack.webhook_env
github-issuesGITHUB_TOKENnotify.github_issues.token_env
github-pr-commentGITHUB_TOKENnotify.github_pr_comment.token_env
bitbucket-pr-commentBITBUCKET_TOKEN, and the email variable for basic authnotify.bitbucket_pr_comment.token_env, notify.bitbucket_pr_comment.email_env

tfcensus doesn't log them. With -vvv the request headers are logged with Authorization redacted, and the Slack webhook path, which is the secret, shows as [redacted].

Configure ​

Add a notify: section to .tfcensus.yaml. Every key is optional. These are the defaults, with enabled filled in:

yaml
notify:
  enabled: [github-issues, slack]
  categories: [double-managed, unmanaged]   # scan categories to report
  min_severity: low                         # lowest audit severity to report
  top: 10                                   # findings listed in a Slack message
  slack:
    webhook_env: SLACK_WEBHOOK_URL
    when: findings          # or always
    link: ""                # URL of the full report, such as a CI artifact
  github_issues:
    repo: ""                # owner/name; empty means GITHUB_REPOSITORY
    api_url: ""             # empty means GITHUB_API_URL, else https://api.github.com
    token_env: GITHUB_TOKEN
    labels: []              # added to new issues, besides tfcensus and tfcensus:<kind>
    max_open: 10
    close_resolved: true
    summary: false
  github_pr_comment:
    repo: ""                # owner/name; empty means GITHUB_REPOSITORY
    api_url: ""             # empty means GITHUB_API_URL, else https://api.github.com
    pull_request: 0         # 0 means the pull request of the GITHUB_EVENT_PATH event
    token_env: GITHUB_TOKEN
  bitbucket_pr_comment:
    workspace: ""           # empty means BITBUCKET_WORKSPACE
    repo: ""                # empty means BITBUCKET_REPO_SLUG
    pull_request: 0         # 0 means BITBUCKET_PR_ID
    api_url: https://api.bitbucket.org/2.0
    token_env: BITBUCKET_TOKEN
    email_env: ""           # set to send an API token with basic auth
  file:
    dir: .
    formats: [md, json]

--notify slack,github-issues replaces notify.enabled for one run. tfcensus config show --sources shows the merged values, and the configuration reference describes each key.

Try it without writing ​

sh
tfcensus drift --format json > drift.json
tfcensus notify --from drift.json --notify github-issues --dry-run-notify

--dry-run-notify lists the open issues and comments with GET requests and prints what would happen to each scope: create, update, close, unchanged, or skipped when max_open is reached. Slack and file print what they would send or write. Nothing is written. The dry run still needs a token that can read issues.

GitHub Actions ​

The token needs issues: write. The workflow's GITHUB_TOKEN works for the same repository:

yaml
permissions:
  contents: read
  issues: write
steps:
  # drift exits 1 when a plan failed; the JSON still lists every unit.
  - run: tfcensus drift --format json > drift.json || true
  - run: tfcensus notify --from drift.json --notify github-issues
    env:
      GITHUB_TOKEN: ${{ github.token }}

GITHUB_REPOSITORY and GITHUB_API_URL come from the runner, so no repository setting is needed. Check drift in CI has full drift workflows.

GitHub issue lifecycle ​

On each run, github-issues lists the open issues with the tfcensus label, 100 per page, and reads their markers. It ignores pull requests and issues without a marker. Then, for every scope in the report:

  1. A scope with findings and no issue gets a new issue, unless max_open open issues of that report kind already exist. Then the scope is listed as skipped in the run output, and in the summary issue when summary: true.
  2. A scope with findings and an issue gets its title and body updated when the hash changed.
  3. A scope without findings and with an issue gets the comment "Resolved: ..." and is closed with state_reason: completed, when close_resolved is on.
  4. A second open issue with the same marker, which a failed create can leave behind, is closed as a duplicate of the oldest one.

Issues for scopes the run didn't cover stay as they are. A drift run filtered to production doesn't close staging issues, and a unit whose plan was skipped (early exit or excluded) keeps its issue. A unit whose plan failed gets an issue that says so, because its drift is unknown.

tfcensus creates the labels it needs the first time it opens an issue. Writes are spaced one second apart, as GitHub's REST API guidance asks, and a 429 or a secondary rate limit is retried after Retry-After. A create that fails with a server error is not retried, so it can't open two issues.

GitHub pull request comment ​

github-pr-comment writes one comment per report kind on the pull request a workflow runs for. In GitHub Actions the repository comes from GITHUB_REPOSITORY and the pull request number from the event file in GITHUB_EVENT_PATH, which pull_request, pull_request_target and issue_comment events on a pull request carry. Other events need notify.github_pr_comment.pull_request.

The job needs permissions: pull-requests: write and GITHUB_TOKEN in the step's environment. Pull requests from forks get a read-only token, and the comment then fails with exit 4. Write the Markdown to the step summary as well, as docs/ci/drift-pr.yml does.

The comment carries the same marker with "scope":"pull-request". A re-run edits it only when the hash changed. When nothing is left to report, an existing comment is edited to "Nothing to report" and no new comment is created. Comments longer than 60,000 characters are cut at a table row or section, with a footer that says what was cut.

Bitbucket pull request comment ​

Bitbucket Cloud removed its issue tracker API on 2026-08-20, so bitbucket-pr-comment writes one comment per report kind on a pull request instead. In Bitbucket Pipelines the workspace, repository and pull request ID come from BITBUCKET_WORKSPACE, BITBUCKET_REPO_SLUG and BITBUCKET_PR_ID.

Use a repository access token with pull request write access as BITBUCKET_TOKEN, which tfcensus sends as a bearer token. For a personal API token, also set notify.bitbucket_pr_comment.email_env to the name of a variable that holds the Atlassian account email, and tfcensus uses basic auth.

The comment is edited in place on later runs. When nothing is left to report, it is edited to say so. A comment can't be closed.

Slack ​

An incoming webhook can't edit or delete a message, so Slack has no lifecycle. With when: findings (the default) a message goes out only when some scope has findings. With always every run sends one. The message has a header, counts, the first top findings and a link to notify.slack.link when set. Point the link at the HTML report that tfcensus report html builds.

Proxies and private certificate authorities ​

notify's HTTPS requests honor HTTPS_PROXY, HTTP_PROXY and NO_PROXY. When a proxy or a GitHub Enterprise server presents a certificate from a private certificate authority, set SSL_CERT_FILE to a PEM file with that certificate:

sh
SSL_CERT_FILE=/etc/ssl/corp-ca.pem tfcensus notify --from drift.json --notify github-issues

tfcensus trusts the certificates in that file on top of the system pool, on Linux, macOS and Windows. A file that holds no PEM certificate stops notify with an error that names SSL_CERT_FILE. Run against an emulator or through a proxy covers the AWS side.

Exit codes ​

CodeMeaning
0every notifier succeeded
1a notifier failed, such as a network error or an HTTP error from the API
2no notifier is enabled, a notifier is unknown or isn't configured (no repository, pull request or token), or a --from file isn't a scan, drift or audit report
4every failure was a refused token (HTTP 401 or 403)

Notifiers run one after the other, and a failure in one doesn't stop the next.

Recover ​

  • An issue was closed by mistake: reopen it. The next run that finds the scope open updates it, and one that finds it resolved closes it again.
  • Labels were removed from an issue: tfcensus no longer sees it and opens a new one. Close the old one by hand.
  • Too many issues at once: lower max_open, or set summary: true to get one overview issue, and close the extra issues by hand. tfcensus doesn't close issues because of max_open.
  • Stop all notifications: remove the notifier from notify.enabled, or drop the notify step. Existing issues stay open until you close them.