Skip to content
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

fix(terraform_plan): Add provisioners to TF Plan parser #5622

Merged
merged 6 commits into from
Oct 22, 2023
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: 17 additions & 0 deletions checkov/terraform/plan_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
TF_PLAN_RESOURCE_ADDRESS = CustomAttributes.TF_RESOURCE_ADDRESS
TF_PLAN_RESOURCE_CHANGE_ACTIONS = "__change_actions__"
TF_PLAN_RESOURCE_CHANGE_KEYS = "__change_keys__"
TF_PLAN_RESOURCE_PROVISIONERS = "provisioners"

RESOURCE_TYPES_JSONIFY = {
"aws_batch_job_definition": "container_properties",
Expand Down Expand Up @@ -165,6 +166,10 @@ def _prepare_resource_block(
resource_conf[TF_PLAN_RESOURCE_CHANGE_ACTIONS] = changes.get("change", {}).get("actions") or []
resource_conf[TF_PLAN_RESOURCE_CHANGE_KEYS] = changes.get(TF_PLAN_RESOURCE_CHANGE_KEYS) or []

provisioners = conf.get(TF_PLAN_RESOURCE_PROVISIONERS) if conf else None
if provisioners:
resource_conf["provisioner"] = _get_provisioner(provisioners)

resource_block[resource_type][resource.get("name", "default")] = resource_conf
prepared = True
return resource_block, block_type, prepared
Expand Down Expand Up @@ -342,3 +347,15 @@ def _clean_simple_type_list(value_list: List[Any]) -> List[Any]:
if lower_case_value == "false":
value_list[i] = False
return value_list


def _get_provisioner(input_data: List[Any]) -> List[Any]:
result = []
for item in input_data:
key = item['type']
command_value = item['expressions']['command']
if not isinstance(command_value, list):
command_value = [command_value]
transformed_item = {key: {'command': command_value}}
result.append(transformed_item)
return result
Loading