1212
1313
1414# =====================================================================================================================
15+ from cloudshell .iac .terraform .models .exceptions import TerraformAutoTagsError
16+
1517
1618class 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+
122125def 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"\n list(\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
560562def 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
0 commit comments