-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added CKV_AWS_282 check for setting inside terraform
- Loading branch information
Showing
3 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
checkov/terraform/checks/resource/aws/RedshiftServerlessNamespaceKMSKey.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from checkov.terraform.checks.resource.base_resource_value_check import BaseResourceValueCheck | ||
from checkov.common.models.enums import CheckCategories | ||
from checkov.common.models.consts import ANY_VALUE | ||
|
||
|
||
class RedshiftServerlessNamespaceKMSKey(BaseResourceValueCheck): | ||
def __init__(self) -> None: | ||
name = "Ensure that Redshift serverless namespace is encrypted by KMS" | ||
id = "CKV_AWS_282" | ||
supported_resources = ['aws_redshiftserverless_namespace'] | ||
categories = [CheckCategories.ENCRYPTION] | ||
super().__init__(name=name, id=id, categories=categories, supported_resources=supported_resources) | ||
|
||
def get_inspected_key(self) -> str: | ||
return "kms_key_id" | ||
|
||
def get_expected_value(self) -> str: | ||
return ANY_VALUE | ||
|
||
|
||
check = RedshiftServerlessNamespaceKMSKey() |
8 changes: 8 additions & 0 deletions
8
tests/terraform/checks/resource/aws/example_RedshiftServerlessNamespaceKMSKey/main.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
resource "aws_redshiftserverless_namespace" "fail" { | ||
namespace_name = "test-fail-namespace" | ||
} | ||
|
||
resource "aws_redshiftserverless_namespace" "pass" { | ||
namespace_name = "test-pass-namespace" | ||
kms_key_id = aws_kms_key.example.arn | ||
} |
40 changes: 40 additions & 0 deletions
40
tests/terraform/checks/resource/aws/test_RedshiftServerlessNamespaceKMSKey.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import os | ||
import unittest | ||
|
||
from checkov.runner_filter import RunnerFilter | ||
from checkov.terraform.checks.resource.aws.RedshiftServerlessNamespaceKMSKey import check | ||
from checkov.terraform.runner import Runner | ||
|
||
|
||
class TestRedshiftServerlessNamespaceKMSKey(unittest.TestCase): | ||
def test(self) -> None: | ||
runner = Runner() | ||
current_dir = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
test_files_dir = current_dir + "/example_RedshiftServerlessNamespaceKMSKey" | ||
report = runner.run( | ||
root_folder=test_files_dir, runner_filter=RunnerFilter(checks=[check.id]) | ||
) | ||
summary = report.get_summary() | ||
|
||
passing_resources = { | ||
"aws_redshiftserverless_namespace.pass", | ||
} | ||
failing_resources = { | ||
"aws_redshiftserverless_namespace.fail", | ||
} | ||
|
||
passed_check_resources = {c.resource for c in report.passed_checks} | ||
failed_check_resources = {c.resource for c in report.failed_checks} | ||
|
||
self.assertEqual(summary["passed"], 1) | ||
self.assertEqual(summary["failed"], 1) | ||
self.assertEqual(summary["skipped"], 0) | ||
self.assertEqual(summary["parsing_errors"], 0) | ||
|
||
self.assertEqual(passing_resources, passed_check_resources) | ||
self.assertEqual(failing_resources, failed_check_resources) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |