Skip to content

Commit

Permalink
terraform_plan: Add terraform_version op
Browse files Browse the repository at this point in the history
  • Loading branch information
refeed committed Nov 14, 2023
1 parent d11a2dd commit 39d3f5f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/tirith/providers/terraform_plan/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ def provide(provider_inputs, input_data):
direct_dependencies_operator(input_data, provider_inputs, outputs)
elif input_type == "direct_references":
direct_references_operator(input_data, provider_inputs, outputs)
elif input_type == "terraform_version":
get_terraform_version_op(input_data, provider_inputs, outputs)
else:
outputs.append(
{
Expand All @@ -173,6 +175,17 @@ def provide(provider_inputs, input_data):
return outputs


def get_terraform_version_op(input_data: dict, provider_inputs: dict, outputs: list):
"""
Operation type handler to get the terraform version from the input_data
:param input_data: The input data
:param provider_inputs: The provider inputs
:param outputs: The outputs
"""
outputs.append({"value": input_data.get("terraform_version"), "meta": input_data})


def direct_dependencies_operator(input_data: dict, provider_inputs: dict, outputs: list):
config_resources = input_data.get("configuration", {}).get("root_module", {}).get("resources", [])
resource_type = provider_inputs.get("terraform_resource_type")
Expand Down
8 changes: 8 additions & 0 deletions tests/providers/terraform_plan/test_terraform_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,11 @@ def test_direct_references():
assert len(result) == 2
assert result[0]["value"] == ["aws_security_group"]
assert result[1]["value"] == []


def test_get_terraform_version():
provider_args_dict = {"operation_type": "terraform_version"}
result = handler.provide(provider_args_dict, load_terraform_plan_json("input_instance_deps_s3.json"))

assert len(result) == 1
assert result[0]["value"] == "1.4.5"

0 comments on commit 39d3f5f

Please sign in to comment.