这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions checkov/terraform/tag_providers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,20 @@ def get_resource_tags(resource_type: str, entity_config: Dict[str, Any]) -> Opti
if not isinstance(entity_config, dict):
return None

if "_" not in resource_type:
return None # probably not a resource block
provider = resource_type[: resource_type.index("_")]
provider_tag_function = provider_tag_mapping.get(provider)
provider_tag = get_provider_tag(resource_type)
provider_tag_function = provider_tag_mapping.get(provider_tag) if provider_tag else None
if provider_tag_function:
return provider_tag_function(entity_config)
else:
return None


def get_provider_tag(resource_type: str) -> Optional[str]:
provider_tag = None
if 'aws' in resource_type:
provider_tag = "aws"
elif 'azure' in resource_type:
provider_tag = "azure"
elif 'gcp' in resource_type or 'google' in resource_type:
provider_tag = "gcp"
return provider_tag
13 changes: 13 additions & 0 deletions tests/terraform/test_provider_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pytest

from checkov.terraform.tag_providers import get_provider_tag


@pytest.mark.parametrize("resource_type, expected", [
("aws_instance.example", "aws"),
("module.test.aws_instance.example", "aws"),
("azure_instance.example", "azure"),
("google_instance.example", "gcp"),
])
def test_get_provider_tag(resource_type, expected) -> None:
assert get_provider_tag(resource_type) == expected
Loading