Exemplo n.º 1
0
 def get_paramter_json_list(self):
     """
     process parameter files and returns parameters json list
     """
     parameter_json_list = []
     for parameter in self.parameter_file:
         if len(parameter.split(".")) > 0 and parameter.split(".")[-1] in [
                 "tf", "tfvars"
         ]:
             json_data = hcl_to_json(parameter)
             if json_data:
                 parameter_json_list.append(
                     {parameter.split(".")[-1]: json_data})
         elif len(parameter.split(".")) > 1 and [
                 ele for ele in [".tfvars.json", ".tf.json"]
                 if (ele in parameter)
         ]:
             json_data = json_from_file(parameter, escape_chars=['$'])
             if json_data:
                 splited_list = parameter.split(".")
                 parameter_json_list.append({
                     '.'.join(splited_list[len(splited_list) - 2:]):
                     json_data
                 })
     return parameter_json_list
Exemplo n.º 2
0
 def is_parameter_file(self, file_path):
     """
     check for valid variable file for parse terraform template
     """
     if len(file_path.split(".")) > 0 and file_path.split(".")[-1] in ["tf", "tfvars"]:
         json_data = hcl_to_json(file_path)
         return True if (json_data and not "resource" in json_data) else False
     elif len(file_path.split(".")) > 1 and [ele for ele in [".tfvars.json", ".tf.json"] if(ele in file_path)]:
         json_data = json_from_file(file_path, escape_chars=['$'])
         return True if (json_data and not "resource" in json_data) else False
     return False
Exemplo n.º 3
0
 def is_template_file(self, file_path):
     """
     check for valid template file for parse terraform template
     """
     if len(file_path.split(".")) > 0 and file_path.split(".")[-1] == "tf":
         json_data = hcl_to_json(file_path)
         return True if (json_data and ("resource" in json_data or "module" in json_data)) else False
     elif len(file_path.split(".")) > 0 and file_path.split(".")[-1] == "json":
         json_data = json_from_file(file_path, escape_chars=['$'])
         return True if (json_data and ("resource" in json_data or "module" in json_data)) else False
     return False
Exemplo n.º 4
0
 def get_template(self):
     """
     return the template json data
     """
     json_data = None
     if len(self.template_file.split(".")) > 0 and self.template_file.split(
             ".")[-1] == "tf":
         json_data = hcl_to_json(self.template_file)
     elif len(self.template_file.split(
             ".")) > 1 and ".tf.json" in self.template_file:
         json_data = json_from_file(self.template_file, escape_chars=['$'])
     return json_data