-
Notifications
You must be signed in to change notification settings - Fork 41
enhance: evaluation result handling- include resource key address #262
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
base: main
Are you sure you want to change the base?
Changes from 12 commits
99b46bd
afb9e1a
4806062
85dd547
e3a1fe7
625701e
52a1875
866f20c
ce9960a
fbf9aa1
c40ff7b
8786453
539bfdd
ac4bd7e
e63e462
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 |
|---|---|---|
|
|
@@ -8,7 +8,7 @@ | |
|
|
||
| # input->(list ["a.b","c", "d"],value of resource) | ||
| # returns->[any, any, any] | ||
| from typing import Iterable, Tuple | ||
| from typing import Iterable, Tuple, List, Union, Any | ||
| import pydash | ||
|
|
||
| from ..common import ProviderError | ||
|
|
@@ -56,6 +56,18 @@ | |
| return final_data | ||
|
|
||
|
|
||
| def _ensure_list_of_strings(value: Union[str, List[str], None]) -> List[str]: | ||
| """Convert a string or None value to a list of strings""" | ||
| if value is None: | ||
| return [] | ||
| elif isinstance(value, str): | ||
| return [value] | ||
| elif isinstance(value, list): | ||
| return [str(item) for item in value] | ||
| else: | ||
| return [str(value)] | ||
|
|
||
|
|
||
|
refeed marked this conversation as resolved.
Outdated
|
||
| def provide(provider_inputs, input_data): | ||
| # """Provides the value of the attribute from the input_data""" | ||
| outputs = [] | ||
|
|
@@ -97,24 +109,39 @@ | |
| is_attribute_found = True | ||
| local_is_found_attribute = True | ||
| attribute_value = input_resource_change_attrs[attribute] | ||
| outputs.append( | ||
| { | ||
| "value": attribute_value, | ||
| "meta": resource_change, | ||
| "err": None, | ||
| } | ||
| ) | ||
| address = resource_change.get("address") | ||
|
refeed marked this conversation as resolved.
Outdated
|
||
| result = { | ||
| "value": attribute_value, | ||
| "meta": resource_change, | ||
| "err": None, | ||
| "addresses": [address] if address is not None else [], | ||
| } | ||
| outputs.append(result) | ||
| elif "." in attribute or "*" in attribute: | ||
| evaluated_outputs = _wrapper_get_exp_attribute(attribute, input_resource_change_attrs) | ||
| if evaluated_outputs: | ||
| is_attribute_found = True | ||
| local_is_found_attribute = True | ||
| for evaluated_output in evaluated_outputs: | ||
| outputs.append({"value": evaluated_output, "meta": resource_change, "err": None}) | ||
| address = resource_change.get("address") | ||
| result = { | ||
| "value": evaluated_output, | ||
| "meta": resource_change, | ||
| "err": None, | ||
| "addresses": [address] if address is not None else [], | ||
| } | ||
| outputs.append(result) | ||
|
|
||
| # If we didn't find the attribute in this resource, add a None value so it still gets evaluated | ||
| if not local_is_found_attribute: | ||
| outputs.append({"value": None, "meta": resource_change, "err": None}) | ||
| address = resource_change.get("address") | ||
| result = { | ||
| "value": None, | ||
| "meta": resource_change, | ||
| "err": None, | ||
| "addresses": [address] if address is not None else [], | ||
| } | ||
| outputs.append(result) | ||
| else: | ||
| outputs.append( | ||
| { | ||
|
|
@@ -154,13 +181,14 @@ | |
| if resource_type in (resource_change["type"], "*"): | ||
| is_resource_type_found = True | ||
| for action in resource_change["change"]["actions"]: | ||
| outputs.append( | ||
| { | ||
| "value": action, | ||
| "meta": resource_change, | ||
| "err": None, | ||
| } | ||
| ) | ||
| address = resource_change.get("address") | ||
| result = { | ||
| "value": action, | ||
| "meta": resource_change, | ||
| "err": None, | ||
| "addresses": [address] if address is not None else [], | ||
| } | ||
| outputs.append(result) | ||
| if not is_resource_type_found: | ||
| outputs.append( | ||
| { | ||
|
|
@@ -175,6 +203,7 @@ | |
| elif input_type == "count": | ||
| count = 0 | ||
| resource_meta = {} | ||
| addresses = [] | ||
| resource_type = provider_inputs["terraform_resource_type"] | ||
| for resource_change in resource_changes: | ||
| # Skip if resource type is in exclude_resource_types when using wildcard | ||
|
|
@@ -184,15 +213,13 @@ | |
| # No need to check if the resource is not found | ||
| # because the count of a resource can be zero | ||
| resource_meta = resource_change | ||
| # Add the address to our list of addresses if available | ||
| if "address" in resource_change: | ||
| addresses.append(resource_change["address"]) | ||
| count += 1 | ||
|
|
||
| outputs.append( | ||
| { | ||
| "value": count, | ||
| "meta": resource_meta, | ||
| "err": None, | ||
| } | ||
| ) | ||
| result = {"value": count, "meta": resource_meta, "err": None, "addresses": addresses} | ||
| outputs.append(result) | ||
| return outputs | ||
| # CASE 4 | ||
| elif input_type == "direct_dependencies": | ||
|
|
@@ -252,7 +279,6 @@ | |
| continue | ||
|
|
||
| is_provider_full_name_found = True | ||
|
|
||
| attribute_value = None | ||
|
|
||
| if attribute_to_get == "version_constraint": | ||
|
|
@@ -271,12 +297,9 @@ | |
| } | ||
| ) | ||
| return | ||
| outputs.append( | ||
| { | ||
| "value": attribute_value, | ||
| "meta": provider_config_dict, | ||
| } | ||
| ) | ||
|
|
||
| result = {"value": attribute_value, "meta": provider_config_dict, "addresses": [terraform_provider_full_name]} | ||
| outputs.append(result) | ||
|
|
||
| if not is_provider_full_name_found: | ||
| outputs.append( | ||
|
|
@@ -297,7 +320,10 @@ | |
| :param provider_inputs: The provider inputs | ||
| :param outputs: The outputs | ||
| """ | ||
| outputs.append({"value": input_data.get("terraform_version"), "meta": input_data}) | ||
| # For terraform_version, there's no specific address as it applies to the entire plan | ||
| outputs.append( | ||
| {"value": input_data.get("terraform_version"), "meta": input_data, "addresses": ["terraform_version"]} | ||
| ) | ||
|
|
||
|
|
||
| def direct_dependencies_operator(input_data: dict, provider_inputs: dict, outputs: list): | ||
|
|
@@ -316,12 +342,16 @@ | |
| is_resource_found = False | ||
|
|
||
| for resource in config_resources: | ||
|
|
||
| if resource.get("type") != resource_type: | ||
| continue | ||
| is_resource_found = True | ||
| deps_resource_type = {resource_id.split(".")[0] for resource_id in resource.get("depends_on", [])} | ||
| outputs.append({"value": list(deps_resource_type), "meta": config_resources}) | ||
| result = {"value": list(deps_resource_type), "meta": config_resources} | ||
| # Add addresses if available | ||
| address = resource.get("address") | ||
| if address: | ||
| result["addresses"] = [address] | ||
| outputs.append(result) | ||
|
|
||
| if not is_resource_found: | ||
| outputs.append( | ||
|
|
@@ -347,7 +377,7 @@ | |
| resource_changes = input_data.get("resource_changes", []) | ||
| referenced_by = provider_inputs.get("referenced_by") | ||
|
|
||
| reference_target_addresses = set() | ||
| reference_target_address = set() | ||
|
refeed marked this conversation as resolved.
Outdated
|
||
| is_resource_found = False | ||
|
|
||
| # Loop for adding reference_target | ||
|
|
@@ -356,7 +386,7 @@ | |
| "destroy" | ||
| ]: | ||
| continue | ||
| reference_target_addresses.add(resource_change.get("address")) | ||
| reference_target_address.add(resource_change.get("address")) | ||
| is_resource_found = True | ||
|
|
||
| if not is_resource_found: | ||
|
|
@@ -384,15 +414,19 @@ | |
| reference_address = relative_reference_address | ||
| else: | ||
| reference_address = f"{module_path}.{relative_reference_address}" | ||
| if reference_address in reference_target_addresses: | ||
| reference_target_addresses.remove(reference_address) | ||
| outputs.append( | ||
| {"value": True, "meta": {"address": reference_address, "referenced_by": resource_config}} | ||
| ) | ||
| if reference_address in reference_target_address: | ||
| reference_target_address.remove(reference_address) | ||
| result = {"value": True, "meta": {"referenced_by": resource_config}} | ||
| # Add addresses to the output as a simple list | ||
| result["addresses"] = [reference_address] | ||
|
refeed marked this conversation as resolved.
Outdated
|
||
| outputs.append(result) | ||
|
|
||
| # For all of the reference_target_addresses that don't have a reference | ||
| for reference_target_address in reference_target_addresses: | ||
| outputs.append({"value": False, "meta": {"address": reference_target_address, "referenced_by": {}}}) | ||
| # For all of the reference_target_address that don't have a reference | ||
| for reference_target_address_item in reference_target_address: | ||
| result = {"value": False, "meta": {"referenced_by": {}}} | ||
| # Add addresses as a simple list | ||
| result["addresses"] = [reference_target_address_item] | ||
| outputs.append(result) | ||
|
|
||
|
|
||
| def get_module_resources_by_type_recursive(module: dict, resource_type: str, current_module_path: str = "") -> iter: | ||
|
|
@@ -478,7 +512,10 @@ | |
| return | ||
|
|
||
| is_all_resource_type_references_to = resource_type_count == reference_count | ||
| outputs.append({"value": is_all_resource_type_references_to, "meta": config_resources}) | ||
| result = {"value": is_all_resource_type_references_to, "meta": config_resources} | ||
| # Simple list with resource type | ||
| result["addresses"] = [resource_type] | ||
| outputs.append(result) | ||
|
refeed marked this conversation as resolved.
|
||
|
|
||
|
|
||
| def direct_references_operator(input_data: dict, provider_inputs: dict, outputs: list): | ||
|
|
@@ -530,7 +567,12 @@ | |
| # Only get the resource type | ||
| resource_references.add(reference.split(".")[0]) | ||
|
Member
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. Please use the address from the addresses.append(reference)
Collaborator
Author
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. @refeed I am unable to understand why do we need to do this?
Member
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. Because that's the real addresses the optype is processing. The |
||
|
|
||
| outputs.append({"value": list(resource_references), "meta": resource}) | ||
| result = {"value": list(resource_references), "meta": resource} | ||
| # Add addresses if available as a simple list | ||
| address = resource.get("address") | ||
| if address: | ||
| result["addresses"] = [address] | ||
| outputs.append(result) | ||
|
|
||
| if not is_resource_found: | ||
| outputs.append( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.