-
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.
support scanning of Terraform managed modules instead of downloading …
…them
- Loading branch information
Showing
8 changed files
with
216 additions
and
23 deletions.
There are no files selected for viewing
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
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
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
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
10 changes: 10 additions & 0 deletions
10
tests/terraform/module_loading/data/tf_managed_modules/.terraform/modules/modules.json
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,10 @@ | ||
{ | ||
"Modules": [ | ||
{ | ||
"Key": "log_group", | ||
"Source": "registry.terraform.io/terraform-aws-modules/cloudwatch/aws//modules/log-group", | ||
"Version": "4.1.0", | ||
"Dir": ".terraform/modules/log_group/modules/log-group" | ||
} | ||
] | ||
} |
14 changes: 14 additions & 0 deletions
14
tests/terraform/module_loading/data/tf_managed_modules/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,14 @@ | ||
module "log_group" { | ||
source = "terraform-aws-modules/cloudwatch/aws//modules/log-group" | ||
|
||
name_prefix = "my-log-group-" | ||
retention_in_days = 7 | ||
} | ||
|
||
module "log_group_v4" { | ||
source = "terraform-aws-modules/cloudwatch/aws//modules/log-group" | ||
version = "~> 4.0" | ||
|
||
name_prefix = "my-log-group-" | ||
retention_in_days = 7 | ||
} |
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,52 @@ | ||
import os | ||
from pathlib import Path | ||
from unittest import mock | ||
|
||
from checkov.runner_filter import RunnerFilter | ||
from checkov.terraform.runner import Runner | ||
|
||
|
||
@mock.patch.dict(os.environ, {"CHECKOV_EXPERIMENTAL_TERRAFORM_MANAGED_MODULES": "True"}) | ||
def test_runner_with_tf_managed_modules(): | ||
# given | ||
root_dir = Path(__file__).parent / "data/tf_managed_modules" | ||
|
||
# when | ||
result = Runner().run( | ||
root_folder=str(root_dir), | ||
runner_filter=RunnerFilter(checks=["CKV_AWS_338"], framework=["terraform"], download_external_modules=False), | ||
) | ||
|
||
# then | ||
summary = result.get_summary() | ||
|
||
assert summary["passed"] == 0 | ||
assert summary["failed"] == 1 | ||
assert summary["skipped"] == 0 | ||
assert summary["parsing_errors"] == 0 | ||
|
||
failed_resources = [check.resource for check in result.failed_checks] | ||
expected_failed_resources = ["module.log_group.aws_cloudwatch_log_group.this[0]"] | ||
|
||
assert failed_resources == expected_failed_resources | ||
|
||
|
||
# test can be removed after setting this flow as default | ||
@mock.patch.dict(os.environ, {"CHECKOV_EXPERIMENTAL_TERRAFORM_MANAGED_MODULES": "False"}) | ||
def test_runner_without_tf_managed_modules(): | ||
# given | ||
root_dir = Path(__file__).parent / "data/tf_managed_modules" | ||
|
||
# when | ||
result = Runner().run( | ||
root_folder=str(root_dir), | ||
runner_filter=RunnerFilter(checks=["CKV_AWS_338"], framework=["terraform"], download_external_modules=False), | ||
) | ||
|
||
# then | ||
summary = result.get_summary() | ||
|
||
assert summary["passed"] == 0 | ||
assert summary["failed"] == 0 | ||
assert summary["skipped"] == 0 | ||
assert summary["parsing_errors"] == 0 |
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