# Checkov in GitHub Actions: Fail PRs on New Terraform Issues

> Originally published on [DevToolHub](https://devtoolhub.com/checkov-in-github-actions-terraform/).

![Flow diagram of Checkov in GitHub Actions: a pull request scans Terraform, compares against a baseline, and fails only on new findings](https://devtoolhub.com/wp-content/uploads/2026/12/2026-12-03-checkov-github-actions-terraform-diagram.webp align="center")

To run Checkov in GitHub Actions, install it with `pip install checkov==3.4.11` and scan the Terraform directory on every pull request that changes it. The catch is the first run. A two-resource file produced 9 failed checks, so a plain gate would fail the first pull request. A baseline file helps with that, but it has a hole I found in testing.

I tested on 30 November 2026 with Checkov 3.4.11, locally in Docker and on a GitHub-hosted runner, using a throwaway Terraform file with an S3 bucket and a security group. On 1 December 2026 I re-ran the baseline cases locally on Checkov 3.4.14 and got the same results.

> **In this guide:**
>
> - Add a Checkov job that fails the pull request on Terraform findings
> - Use a baseline so findings it does not cover fail the build
> - Spot the case where the baseline hides a new, unsafe resource
> - Skip a check on purpose and keep the reason in the code

## How do you run Checkov in GitHub Actions?

Trigger a job on pull requests that touch your Terraform, install a pinned Checkov, and scan the directory. Checkov exits 1 when any check fails, which fails the job. This is the `pip` job from the workflow I ran, with the baseline flag explained in the next section:

```yaml
name: Terraform scan
on:
  pull_request:
    paths:
      - "infra/**"
permissions:
  contents: read
jobs:
  checkov:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
        with:
          persist-credentials: false
      - uses: actions/setup-python@v7
        with:
          python-version: "3.13"
      - name: Install Checkov
        run: pip install checkov==3.4.11
      - name: Scan Terraform against the baseline
        run: |
          checkov -d infra --framework terraform --compact --quiet \
            --baseline infra/.checkov.baseline
```

Workflow-only edits do not match the `infra/**` filter. Add the workflow file's own path to `paths` if you want those validated too; I did not test that variant.

The official [`bridgecrewio/checkov-action`](https://github.com/bridgecrewio/checkov-action) does the same in one step. In my runs the Action job took 19, 28 and 23 seconds, and the `pip` job took 29, 42 and 30 seconds, with identical pass and fail results. The Action runs a prebuilt container, so it skips the Python setup.

> **Note:** GitHub's "latest release" for the Action still points to `v12.1347.0` from March 2022. The tags go on to `v12.3147.0`, a commit from 25 November 2026 that uses the Checkov 3.4.11 image. Pin the commit SHA, not "latest": `bridgecrewio/checkov-action@b782b35c8411ff565b881fba67ceebdb426d7dc4`

For more on pinning and token scope, see the [security best practices guide](https://devtoolhub.com/github-actions-security-best-practices/).

## Why does Checkov in GitHub Actions fail on day one?

Because the default policy set is broad, and Checkov in GitHub Actions treats every finding as a failure. My test file had an S3 bucket with a name and nothing else, plus a security group open on port 80. Checkov ran 19 checks, passed 10 and failed 9. Seven of the failures were on the bucket alone:

```text
Passed checks: 10, Failed checks: 9, Skipped checks: 0

Check: CKV_AWS_260: "Ensure no security groups allow ingress from 0.0.0.0:0 to port 80"
Check: CKV_AWS_145: "Ensure that S3 buckets are encrypted with KMS by default"
Check: CKV2_AWS_6: "Ensure that S3 bucket has a Public Access block"
Check: CKV_AWS_144: "Ensure that S3 bucket has cross-region replication enabled"
```

Some of these matter, like the public access block. Others, like cross-region replication on a log bucket, are a judgment call. A real repository has dozens of resources, so the first scan can show hundreds of findings. That is a lot to fix in one pull request.

## How do you fail only on new Checkov findings?

Record today's findings in a baseline file, then pass it to every scan. Checkov reports only failed checks that are not in the baseline. Create it once, locally:

```bash
checkov -d infra --framework terraform --compact --quiet --create-baseline
```

That wrote `infra/.checkov.baseline` inside the scanned directory, and the command itself exited 1 because the scan still had failures. The file records each finding by file, resource address and check ID:

```json
{
  "failed_checks": [
    {
      "file": "/main.tf",
      "findings": [
        {
          "resource": "aws_security_group.web",
          "check_ids": ["CKV2_AWS_5", "CKV_AWS_260"]
        }
      ]
    }
  ]
}
```

Commit it. With the baseline in place the same scan reported no failures and exited 0. I then ran these cases:

| Change in the pull request | Result |
| --- | --- |
| Comment added, no real change | passes |
| New bucket `aws_s3_bucket.uploads`, no settings | fails: 7 new findings |
| `acl = "public-read"` on the baselined `logs` bucket | fails: new check `CKV_AWS_20` only |
| New resource inserted at the top of the file | old findings stay hidden; the new resource fails |
| `logs` renamed to `app_logs` | fails: the 7 old findings return for the new name |

The baseline stores no line numbers, and inserting a resource above the old ones did not resurface their findings. It also catches a check ID that was not baselined on an old resource, as `CKV_AWS_20` showed, because the baseline stores check IDs per resource. A worse setting under an already baselined check ID gets no such protection. Renaming a resource resets it, which is usually what you want for a refactor you have to review anyway.

On the runner I opened pull requests for the no-op, the new bucket and the public ACL. They passed, failed with 7 findings and failed with `CKV_AWS_20`, in that order. Both the `pip` job and the Action job agreed each time.

## What does the Checkov baseline miss?

It can hide a brand-new resource when the resource address matches a baselined one in another file. I added `infra/modules/other/main.tf` with a bucket named `aws_s3_bucket.logs`, the same address as the baselined bucket in `infra/main.tf`. Without a baseline, Checkov reported 7 failures for the new file. With the baseline it reported nothing and exited 0. The pull request on the runner went green too.

> **Warning:** The baseline file lists a file, a resource address and check IDs. In my tested layout it still hid a new resource in a different file that reused the address, so that resource effectively inherited the old exemptions. Distinct resource names across modules may avoid this, but I did not test that. A safer habit is to run one scan without the baseline whenever you add a module, and to review every addition to the baseline file as carefully as code.

I found this because a third-party issue thread suggested it, then reproduced it myself. It is a real limit of a baseline on a repository that repeats names like `this` or `main` across modules.

## How do you skip a Checkov check on purpose?

Put a `checkov:skip` comment inside the resource block with the check ID and a reason. The [Checkov docs](https://www.checkov.io/2.Basics/Suppressing%20and%20Skipping%20Policies.html) say the reason is optional, and my test agreed:

```hcl
resource "aws_s3_bucket" "logs" {
  #checkov:skip=CKV_AWS_144:Replication is not needed for access logs
  #checkov:skip=CKV_AWS_18
  bucket = "example-logs-bucket"
}
```

Checkov reported both as `SKIPPED`. The first printed `Suppress comment: Replication is not needed for access logs`, and the second printed `No comment provided`. Treat a skip without a reason as a review smell, because a reader cannot tell whether someone decided or just silenced it.

Three flags control the exit code without editing code:

| Flag | What I saw |
| --- | --- |
| `--check CKV_AWS_260,CKV_AWS_145,CKV_AWS_21` | runs only those 3 checks, all 3 failed, exit 1 |
| `--soft-fail` | 9 failed checks reported, exit 0 |
| `--soft-fail --hard-fail-on CKV_AWS_260` | 9 failed checks reported, exit 1 |

The last row is a useful middle ground. Report all findings, but fail the build only for the checks you treat as blocking. The [terraform-docs action guide](https://devtoolhub.com/terraform-docs-github-action/) covers another tool you can add to the same pipeline.

## What I did not test

I scanned one small Terraform file for AWS with Checkov 3.4.11, on one runner image and Python 3.13. Untested: scanning a `terraform plan` JSON file, SARIF upload to code scanning, running with a Prisma Cloud or Bridgecrew API key, external modules, other frameworks such as Kubernetes or Dockerfiles, and large repositories. The baseline hole is tested for one pair of same-address resources, not for every layout. I also did not check how the baseline behaves when a finding moves between two files.

If you manage state for the same code, the [Terraform state guide](https://devtoolhub.com/terraform-state-explained/) covers the other half of the safety net.

## Frequently Asked Questions

**Q: How do I run Checkov in GitHub Actions?** A: Install a pinned version with `pip install checkov==3.4.11` and run `checkov -d infra --framework terraform` in a job that triggers on changes to the Terraform path. Checkov exits 1 on a failed check, which fails the job. The official `bridgecrewio/checkov-action` works too.

**Q: How do I make Checkov fail only on new issues?** A: Create a baseline with `checkov -d infra --create-baseline`, commit `.checkov.baseline`, and scan with `--baseline infra/.checkov.baseline`. Only failed checks that are not in the baseline fail the job. It tracks file, resource address and check ID, not line numbers.

**Q: Can a Checkov baseline hide a new misconfigured resource?** A: Yes, in the layout I tested. A new bucket with the same address as a baselined bucket in another module passed with exit 0, although the same file failed 7 checks without the baseline. Keep resource addresses unique across modules.

**Q: How do I skip a Checkov check in Terraform?** A: Add `#checkov:skip=CKV_AWS_144:reason` inside the resource block. The reason is optional but worth writing. For a whole run, use `--skip-check` or `--check` on the command line.

**Quick Summary:**

- Checkov exits 1 on any failed check, so a plain scan fails on day one: 9 failures on a two-resource file
- A `--baseline` file stores findings by file, resource address and check ID, so findings the baseline does not cover fail the build
- A new check on an old resource fails, and a renamed resource resurfaces its old findings
- A new resource that reuses a baselined address in another file is hidden, and my runner pull request passed
- `#checkov:skip` works with or without a reason, so require a reason in review
- `--soft-fail --hard-fail-on <ID>` reports the scan's findings and fails only on the checks you name
- Pin the Action by commit SHA, because its "latest release" is from 2022

Run your first scan and create the baseline in the same pull request, then review every later change to the baseline file like code. Give new module resources unique names too, although I did not test whether that avoids the hole. That is how you keep Checkov in GitHub Actions switched on after day one.
