Skip to content

Commit a2f9bf5

Browse files
committed
fixses per Alex PR remarks
1 parent 1b2f4f0 commit a2f9bf5

6 files changed

Lines changed: 24 additions & 15 deletions

File tree

package/cloudshell/iac/terraform/models/exceptions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,9 @@ class TerraformExecutionError(Exception):
22
def __init__(self, message, std_out=""):
33
self.message = message + std_out
44
super().__init__(self.message)
5+
6+
7+
class TerraformAutoTagsError(Exception):
8+
def __init__(self, message, std_out=""):
9+
self.message = message + std_out
10+
super().__init__(self.message)

package/cloudshell/iac/terraform/services/object_factory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ObjectFactory:
2222
def create_tf_proc_executer(config: TerraformShellConfig,
2323
sandbox_data_handler: SandboxDataHandler,
2424
shell_helper: ShellHelperObject,
25-
tf_working_dir: str):
25+
tf_working_dir: str) -> TfProcExec:
2626
backend_handler = BackendHandler(shell_helper, tf_working_dir, sandbox_data_handler.get_tf_uuid())
2727
input_output_service = InputOutputService(shell_helper, config.inputs_map, config.outputs_map)
2828
tf_proc_executer = TfProcExec(shell_helper, sandbox_data_handler, backend_handler, input_output_service)

package/cloudshell/iac/terraform/tagging/tag_terraform_resources.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313

1414
# =====================================================================================================================
15+
from cloudshell.iac.terraform.models.exceptions import TerraformAutoTagsError
16+
1517

1618
class Constants:
1719
TAGS = "tags" # used for tag aws and azure resources in terraform
@@ -119,6 +121,7 @@ def write_error(msg: str, code_line: int = None):
119121

120122
# =====================================================================================================================
121123

124+
122125
def parse_comma_separated_string(params_string: str = None) -> dict:
123126
res = {}
124127

@@ -230,7 +233,6 @@ def _init_colony_autoScaling_tags_flat_maps_list(self):
230233
list_of_maps_value = " ,\n\t\t".join(colony_tags_to_list)
231234
self.colony_autoScaling_tags_flat_maps_list = f"\nlist(\n\t\t{list_of_maps_value}\n)"
232235

233-
234236
def _get_basic_override_tags_template(self, resource_type: str, resource_name: str, tags: str) -> str:
235237
tags_label = Constants.LABELS if resource_type.startswith("kubernetes_") else Constants.TAGS
236238
return """
@@ -559,7 +561,7 @@ def _get_untaggable_resources_types_from_plan_output(text: str) -> List[str]:
559561

560562
def start_tagging_terraform_resources(main_dir_path: str, logger, tags_dict: dict, inputs_dict: dict = dict()):
561563
if not os.path.exists(main_dir_path):
562-
raise ValueError(f"Path {main_dir_path} does not exist")
564+
raise TerraformAutoTagsError(f"Path {main_dir_path} does not exist")
563565
tfs_folder_path = main_dir_path
564566
# log_path = Constants.get_override_log_path(main_dir_path)
565567
# colony_tags_file_path = Constants.get_colony_tags_path(main_dir_path)
@@ -580,7 +582,7 @@ def start_tagging_terraform_resources(main_dir_path: str, logger, tags_dict: dic
580582

581583
# Had to change exit(3) to "raise" so exception can be handled outside
582584
#exit(3)
583-
raise ValueError("Exit before the override procedure began because the init/plan failed")
585+
raise TerraformAutoTagsError("Validation errors during Terraform Init/Plan when applying automated tags")
584586
LoggerHelper.write_info(f"terraform init & plan passed successfully")
585587

586588
tags_templates_creator = OverrideTagsTemplatesCreator(tags_dict)
@@ -648,14 +650,15 @@ def start_tagging_terraform_resources(main_dir_path: str, logger, tags_dict: dic
648650
LoggerHelper.write_error("Tagging terraform resources operation has FAILED !!!!!")
649651
# Had to change exit(1) to "raise" so exception can be handled outside
650652
# exit(1)
651-
raise ValueError("Errors were found in the last validation check")
653+
raise TerraformAutoTagsError("Errors were found in the last validation check")
652654

653655
else:
654656
LoggerHelper.write_warning("No untaggable resources were found, but errors in plan file do exists")
655657
LoggerHelper.write_error("Tagging terraform resources operation has FAILED !!!!!")
656658
# Had to change exit(1) to "raise" so exception can be handled outside
657659
# exit(1)
658-
raise ValueError("No untaggable resources were found, but errors in plan file do exists")
660+
raise TerraformAutoTagsError("No untaggable resources were found, but there is an error in Terraform "
661+
"Plan when applying automated tags. Please check the logs for more details")
659662
else:
660663
LoggerHelper.write_info("No errors founds in plan output")
661664

shells/generic_terraform_service/tests/integration_tests/helper_objects/integration_context.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ def _set_context(self):
4848
self.context.reservation.domain = self._env_vars.cs_domain
4949

5050
def set_context_resource_attributes(self, the_only_attribute_to_update=""):
51-
services = self.real_api.GetReservationDetails(self._env_vars.cs_res_id, disableCache=True).ReservationDescription.Services
51+
services = self.real_api.GetReservationDetails(self._env_vars.cs_res_id, disableCache=True)\
52+
.ReservationDescription.Services
5253
for service in services:
5354
if service.Alias == self._env_vars.sb_service_alias:
5455
for attribute in service.Attributes:

shells/generic_terraform_service/tests/integration_tests/int_test_tf_execute_destroy.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import function as function
21
from cloudshell.api.cloudshell_api import AttributeNameValue
32
from dotenv import load_dotenv
43
from tests.integration_tests.constants import SHELL_NAME
4+
from typing import Callable
55

66
from tests.integration_tests.helper_objects.integration_context import IntegrationData
77

@@ -16,19 +16,19 @@ def setUp(self) -> None:
1616
self.integration_data2 = IntegrationData(os.environ.get("SB_SERVICE_ALIAS2"))
1717

1818
def run_execute_and_destroy(
19-
self, pre_exec_function: function,
20-
pre_destroy_function: function,
19+
self, pre_exec_function: Callable,
20+
pre_destroy_function: Callable,
2121
integration_data: IntegrationData
2222
):
2323
self.clear_sb_data()
2424
self.run_execute(pre_exec_function, integration_data)
2525
self.run_destroy(pre_destroy_function, integration_data)
2626

27-
def run_execute(self, pre_exec_function: function, integration_data: IntegrationData):
27+
def run_execute(self, pre_exec_function: Callable, integration_data: IntegrationData):
2828
self.pre_exec_prep(pre_exec_function, integration_data)
2929
integration_data.driver.execute_terraform(integration_data.context)
3030

31-
def run_destroy(self,pre_destroy_function: function, integration_data: IntegrationData):
31+
def run_destroy(self,pre_destroy_function: Callable, integration_data: IntegrationData):
3232
self.pre_destroy_prep(pre_destroy_function, integration_data)
3333
integration_data.driver.destroy_terraform(integration_data.context)
3434

@@ -104,10 +104,10 @@ def test_execute_and_destroy_azure_vault_without_remote(self):
104104

105105
'''------------------------------ Functions : general _pre prep functions ---------------------------------'''
106106

107-
def pre_exec_prep(self, pre_exec_function: function, integration_data: IntegrationData):
107+
def pre_exec_prep(self, pre_exec_function: Callable, integration_data: IntegrationData):
108108
pre_exec_function(integration_data)
109109

110-
def pre_destroy_prep(self, pre_destroy_function: function, integration_data: IntegrationData):
110+
def pre_destroy_prep(self, pre_destroy_function: Callable, integration_data: IntegrationData):
111111
pre_destroy_function(integration_data)
112112

113113
def clear_sb_data(self):
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
cloudshell-iac-terraform==0.1.0
2-
function==1.2.0
32
python-dotenv==0.18.0

0 commit comments

Comments
 (0)