-
Notifications
You must be signed in to change notification settings - Fork 1.3k
fix(terraform): Handled git external module loading with sub-directory but without protocol #7272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,8 +105,12 @@ def _parse_module_source(self, module_params: ModuleParams) -> ModuleSource: | |
version = "HEAD" | ||
|
||
if len(module_source_components) < 3: | ||
root_module = module_source_components[-1] | ||
inner_module = "" | ||
if len(module_source_components) == 2 and "git::git" in module_source_components[0]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be helpful if we had a comment here (and in other places in this method) which would explain which use case it solves. i.e. in this case if I got it right it would be
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added :) |
||
root_module = module_source_components[-2] | ||
inner_module = module_source_components[-1] | ||
else: | ||
root_module = module_source_components[-1] | ||
inner_module = "" | ||
elif len(module_source_components) == 3: | ||
root_module = module_source_components[1] | ||
inner_module = module_source_components[2] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import pytest | ||
|
||
from checkov.terraform.module_loading.loaders.git_loader import GenericGitLoader | ||
from checkov.terraform.module_loading.module_params import ModuleParams | ||
|
||
|
||
@pytest.mark.parametrize("source, expected_root_module, expected_inner_module", [ | ||
("git::git@github.com:test-inner-module/out-module//inner-module?ref=main", | ||
"github.com:test-inner-module/out-module", "inner-module"), | ||
("git::https://github.com:test-inner-module/out-module//inner-module?ref=main", | ||
"github.com:test-inner-module/out-module", "inner-module"), | ||
("git::https://github.com:test-only-outer-module/out-module", | ||
"github.com:test-only-outer-module/out-module", ""), | ||
("git::ssh://github.com:test-only-outer-module/out-module", | ||
"github.com:test-only-outer-module/out-module", ""), | ||
("https://github.com:test-only-outer-module/out-module", | ||
"github.com:test-only-outer-module/out-module", ""), | ||
("https://github.com:test-with-inner-module-no-git-prefix/out-module//in-module", | ||
"github.com:test-with-inner-module-no-git-prefix/out-module", "in-module") | ||
] | ||
) | ||
def test__parse_module_source(source: str, expected_root_module: str, expected_inner_module: str) -> None: | ||
git_loader = GenericGitLoader() | ||
module_params = ModuleParams( | ||
root_dir="test", | ||
current_dir="test", | ||
source=source, | ||
source_version="source_version", | ||
dest_dir="test", | ||
external_modules_folder_name="test", | ||
inner_module="", | ||
tf_managed=False | ||
) | ||
module_source = git_loader._parse_module_source(module_params) | ||
assert module_source.root_module == expected_root_module | ||
assert module_source.inner_module == expected_inner_module |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this import moved due to an import loop of
env_var_config
andhttp_utils