Skip to content

Instantly share code, notes, and snippets.

@MooreDerek
Last active April 21, 2022 22:30
Show Gist options
  • Save MooreDerek/7d9bc0a51c658657ca37bb261f54bb56 to your computer and use it in GitHub Desktop.
Save MooreDerek/7d9bc0a51c658657ca37bb261f54bb56 to your computer and use it in GitHub Desktop.
How to run checkov in VS Code

Recently been trying my hand at fixing some issues on checkov. As I've been trying to pick up some of the more complicated issues, I've found the need to run checkov in order to debug it. Being a relative noob with python and VS Codde, I thought it might be useful to note how I got this working.

Follow the Contributing steps to get your environment set up. The main program that runs checkov is checkov/main.py - funny that.

So steps to run it are:

  1. In VS Code open main.py
  2. Select `Run -> Add Configuration
  3. Select Python from the dropdown
  4. Select Python File
  5. This will open a launch.json looking like
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Python: Current File",
      "type": "python",
      "request": "launch",
      "program": "${file}",
      "console": "integratedTerminal",
      "justMyCode": true
    }
  ]
}
  1. Add the following entries to the files
      "env": { "PYTHONPATH": "${workspaceRoot}"},
      "args": [ "-d", "<directory>", "--framework", "terraform"]

The env solves the issue with Module not found The args are, well, the args you'd normally pass on the command line 7. Give your launch profile a more useful name

     "name": "Checkov Debug"
  1. Set the main.py as the program to launch
    "program": "${workspaceRoot}/checkov/main.py"
  1. You can now start checkov, by going to the Run and Debug view -> Ctrl + Shift + D
  2. F5 to start debugging or press the green play button to the left of the Checkov Debug at the top left of the view

Final launch.json should look like this:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Checkov Debug",
      "type": "python",
      "request": "launch",
      "program": "${workspaceRoot}/checkov/main.py",
      "console": "integratedTerminal",
      "justMyCode": true,
      "env": { "PYTHONPATH": "${workspaceRoot}"},
      "args": [ "-d", "<directory>", "--framework", "terraform"]
    }
  ]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment