Skip to content

Commit

Permalink
fix(terraform): stop CKV_GCP_43 crashing when not a string (#5561)
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesWoolfenden authored Oct 4, 2023
1 parent 37743fa commit 1ef5b91
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def scan_resource_conf(self, conf: Dict[str, List[Any]]) -> CheckResult:

self.evaluated_keys = ["rotation_period"]
rotation = conf.get("rotation_period")
if rotation and rotation[0]:
if rotation and rotation[0] and isinstance(rotation[0], str):
time = force_int(rotation[0][:-1])
if time and ONE_DAY <= time <= NINETY_DAYS:
return CheckResult.PASSED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,9 @@ resource "google_kms_crypto_key" "asymmetric" {
key_ring = "google_kms_key_ring.keyring.id"
purpose = "ASYMMETRIC_SIGN"
}

resource "google_kms_crypto_key" "fail" {
name = "crypto-key-example"
key_ring = "google_kms_key_ring.keyring.id"
rotation_period = 90
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ def test(self):
failing_resources = {
"google_kms_crypto_key.default",
"google_kms_crypto_key.half_year",
"google_kms_crypto_key.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"], 2)
self.assertEqual(summary["failed"], 2)
self.assertEqual(summary["passed"], len(passing_resources))
self.assertEqual(summary["failed"], len(failing_resources))
self.assertEqual(summary["skipped"], 0)
self.assertEqual(summary["parsing_errors"], 0)
self.assertEqual(summary["resource_count"], 5) # 1 unknown
self.assertEqual(summary["resource_count"], 6) # 1 unknown

self.assertEqual(passing_resources, passed_check_resources)
self.assertEqual(failing_resources, failed_check_resources)
Expand Down

0 comments on commit 1ef5b91

Please sign in to comment.