I have a following terraform code
import logging
from checkov.common.models.enums import CheckResult
from checkov.terraform.checks.resource.base_resource_value_check import
BaseResourceValueCheck
def get_resource_message(conf):
dataset_id = conf.get("dataset_id")
return f"Dataset '{dataset_id}' is missing 'cost_center' label"
class BigQueryDatasetCostCenterCheck(BaseResourceValueCheck):
def __init__(self):
name = "Ensure BigQuery datasets have mandatory cost_center labels"
id = "CKV_CUSTOM_1"
supported_resources = ["google_bigquery_dataset"]
categories = ["Data"]
logging.info("hello")
super().__init__(
name=name,
id=id,
categories=categories,
supported_resources=supported_resources,
)
def get_inspected_key(self):
return "labels"
def get_expected_value(self):
return {"cost_center": "Present"}
def scan_resource_conf(self, conf):
labels = conf.get(self.get_inspected_key(), {})
if "cost_center" not in labels:
return CheckResult.FAILED #, get_resource_message(conf)
return CheckResult.PASSED#, "gadfdfd"
check = BigQueryDatasetCostCenterCheck()
I have my init.py file as well.
import glob
from os.path import basename, dirname, isfile, join
modules = glob.glob(join(dirname(__file__), "*.py"))
__all__ = [
basename(f)[:-3] for f in modules if isfile(f) and not f.endswith("__init__.py")
]
however when I run this on my terraform code or tfplan.json. it doesn’t scan for this custom policy.
checkov --skip-check CKV_GCP_81,CKV_GCP_15 --external-checks-dir=./python ─╯
_ _
___| |__ ___ ___| | _______ __
/ __| '_ / _ / __| |/ / _ / /
| (__| | | | __/ (__| < (_) V /
___|_| |_|___|___|_|____/ _/
By Prisma Cloud | version: 3.2.171