Repository: bridgecrewio/checkov

Issue:
 [WARNI]  Could not get the package version from pkg_resource
I execute a ADO pipeline that checks a terraform directory with subdirectories that have 4 modules locally.

![image](https://user-images.githubusercontent.com/22588533/220620198-ffaf26a1-1b1d-472f-922a-30565df2cfe2.png)


Checkov version:
docker.io/bridgecrew/checkov:latest

Path of the Terraform maint.tf and directory that checks chekov: PoC\platform\main.tf


Execution:
LOG_LEVEL=DEBUG;docker run --volume $(pwd):/tf bridgecrew/checkov --directory /tf --framework terraform --output junitxml --soft-fail > $(pwd)/CheckovReport.xml
Result:
2023-02-22 12:23:07,252 [MainThread  ] [WARNI]  Could not get the package version from pkg_resources



I did a list of the files and I can see the checkovReport.xml but it doesn't have enough data to be published:
No Result Found to Publish '/home/vsts/work/1/s/PoC/platform/CheckovReport.xml'.


=====================List all the files of main folder============================
/home/vsts/work/1/s/PoC/platform
total 40
-rw-r--r--  1 vsts docker 3728 Feb 22 12:22 main.tf
drwxr-xr-x 10 vsts docker 4096 Feb 22 12:22 azure-tfmodule
-rw-r--r--  1 vsts docker 2563 Feb 22 12:22 README.md
-rw-r--r--  1 vsts docker  962 Feb 22 12:22 .gitignore
drwxr-xr-x  3 vsts docker 4096 Feb 22 12:22 ..
-rw-r--r--  1 vsts docker 1256 Feb 22 12:22 versions.tf
-rw-r--r--  1 vsts docker 1477 Feb 22 12:22 variables.tf
-rw-r--r--  1 vsts docker 1292 Feb 22 12:22 terraform.tfvars
drwxr-xr-x  3 vsts docker 4096 Feb 22 12:23 .
-rw-r--r--  1 vsts docker 2191 Feb 22 12:23 CheckovReport.xml


This is an example of one of the modules with the WARNI, on the main.tf, where workingDirectory: "./PoC/platform"
module "azurerm_log_analytics_workspace" {
  source              = "./azure-tfmodule/azure-loganalytics-workspace"
  law_name                = module.naming_standard.standard.log-analytics-workspace
  location            = var.location
  resource_group_name = var.resource_group_name
  law_sku             = var.law_sku
  retention_in_days   = var.law_retention_in_days
  tags                = var.tags 

   depends_on = [
    module.naming_standard
  ]
}

If I try to check a terraform plan in json format not the main.tf I get the same warning. 
If I execute same pipeline in the terraform directory without modules it works, the problem is when I try to execute the checkov  and review a local modules or the terraform plan output that calls local modules. Is not on this example but I tested too.


This is my yml pipeline stage:
pool:
  vmImage: ubuntu-latest

stages:
- stage: "runCheckov"
  displayName: "Checkov - Scan Terraform files"
  jobs:
   - job: "runCheckov"
     displayName: "Checkov > Pull, run and publish results of Checkov scan"
     steps:
      - bash: |
                docker pull bridgecrew/checkov
        workingDirectory: "./PoC/platform"
        displayName: "Pull > bridgecrew/checkov"
      - bash: |
                LOG_LEVEL=DEBUG;docker run --volume $(pwd):/tf bridgecrew/checkov --directory /tf --framework terraform --output junitxml --soft-fail > $(pwd)/CheckovReport.xml
        workingDirectory: "./PoC/platform"
        displayName: "Run > checkov"
      - script: |
                      echo "=====================List all the files of main folder============================"
                      cd ./PoC/platform
                      pwd
                      ls -ltra
      - task: PublishTestResults@2
        inputs:
            testRunTitle: "Checkov Results"
            failTaskOnFailedTests: true
            testResultsFormat: "JUnit"
            testResultsFiles: "CheckovReport.xml"
            searchFolder: "./PoC/platform"
            displayName: "Publish > Checkov scan results"
            mergeTestResults: false
            publishRunAttachments: true



Discussion:
Same here, but looks like it's even outputting the warning even without usage of modules (at least for me). Yesterday's release [2.3.29](https://github.com/bridgecrewio/checkov/releases/tag/2.3.29) works like a charm though.
So, I checked the last commits and nothing indicates the origin of the warning message. Probably coming from a 3rd party dependency.

To understand why scanning is not working you need to enable at least `INFO` log level or even `DEBUG` you have to pass the env var directly to the container 
```shell
 docker run --volume $(pwd):/tf -e LOG_LEVEL=INFO bridgecrew/checkov --directory /tf --framework terraform --output junitxml --soft-fail
```
my bet, I found the commit which added this log message 🙈 

Resolving patch:
diff --git a/checkov/common/util/stopit/__init__.py b/checkov/common/util/stopit/__init__.py
--- a/checkov/common/util/stopit/__init__.py
+++ b/checkov/common/util/stopit/__init__.py
@@ -12,18 +12,10 @@
 Public resources from ``stopit``
 """
 
-import pkg_resources
-
-from .utils import LOG, TimeoutException
+from .utils import TimeoutException
 from .threadstop import ThreadingTimeout, async_raise, threading_timeoutable
 from .signalstop import SignalTimeout, signal_timeoutable
 
-# PEP 396 style version marker
-try:
-    __version__ = pkg_resources.get_distribution(__name__).version
-except Exception:
-    LOG.warning("Could not get the package version from pkg_resources")
-    __version__ = 'unknown'
 
 __all__ = (
     'ThreadingTimeout', 'async_raise', 'threading_timeoutable',
diff --git a/checkov/common/util/stopit/utils.py b/checkov/common/util/stopit/utils.py
--- a/checkov/common/util/stopit/utils.py
+++ b/checkov/common/util/stopit/utils.py
@@ -26,7 +26,7 @@ def emit(self, record):
             pass
 
         def createLock(self):
-            self.lock = None  # noqa
+            self.lock = None
 else:
     from logging import NullHandler
 
@@ -140,7 +140,7 @@ def wrapper(*args, **kwargs):
             timeout = kwargs.pop(self.timeout_param, None)
             if timeout:
                 with self.to_ctx_mgr(timeout, swallow_exc=True):
-                    result = self.default  # noqa
+                    result = self.default
                     # ``result`` may not be assigned below in case of timeout
                     result = func(*args, **kwargs)
                 return result


Test patch: