Skip to content

Commit d22c723

Browse files
authored
fix(terraform_plan): .*. expression should raise the resources that don't have the attribute
Closes #256
1 parent 9774f0f commit d22c723

File tree

4 files changed

+447
-37
lines changed

4 files changed

+447
-37
lines changed

src/tirith/providers/terraform_plan/handler.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,28 @@ def _get_exp_attribute(split_expressions, input_data):
2929
for i, expression in enumerate(split_expressions):
3030
intermediate_val = pydash.get(input_data, expression, default=PydashPathNotFound)
3131
if isinstance(intermediate_val, list) and i < len(split_expressions) - 1:
32+
# For each item in the list, recursively get attributes
33+
# Track if at least one item had the attribute
3234
for val in intermediate_val:
33-
final_attributes = _get_exp_attribute(split_expressions[1:], val)
34-
for final_attribute in final_attributes:
35-
final_data.append(final_attribute)
35+
final_attributes = _get_exp_attribute(split_expressions[i + 1 :], val)
36+
if final_attributes:
37+
for final_attribute in final_attributes:
38+
final_data.append(final_attribute)
39+
else:
40+
# If no attributes found for this list item, append None
41+
# This ensures list items without the attribute are still evaluated
42+
final_data.append(None)
43+
44+
# We've already processed all remaining expressions for this list
45+
# so we can return early
46+
return final_data
3647
elif i == len(split_expressions) - 1 and intermediate_val is not PydashPathNotFound:
3748
final_data.append(intermediate_val)
38-
elif ".*" in expression:
49+
elif expression.endswith(".*"):
3950
intermediate_exp = expression.split(".*")
4051
intermediate_data = pydash.get(input_data, intermediate_exp[0], default=PydashPathNotFound)
4152
if intermediate_data is not PydashPathNotFound and isinstance(intermediate_data, list):
53+
# For each item in the list, check if it has attributes or append None
4254
for val in intermediate_data:
4355
final_data.append(val)
4456
return final_data

0 commit comments

Comments
 (0)