У меня есть следующий код Terraform:
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()
У меня также есть файл init.py.
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")
]
Однако, когда я запускаю это в своем коде Terraform или tfplan.json. Он не сканирует эту специальную политику.
checkov --skip-check CKV_GCP_81,CKV_GCP_15 --external-checks-dir=./python ─╯
_ _
___| |__ ___ ___| | _______ __
/ __| '_ \ / _ \/ __| |/ / _ \ \ / /
| (__| | | | __/ (__| < (_) \ V /
\___|_| |_|\___|\___|_|\_\___/ \_/
By Prisma Cloud | version: 3.2.171
Подробнее здесь: https://stackoverflow.com/questions/787 ... ot-working
Checkov — пользовательская политика Python для Terraform не работает ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение