def process_terraform_logs()

in modules/python/terraform/extract_terraform_operation_metadata.py [0:0]


def process_terraform_logs(log_path, _command_type, _scenario_type, _scenario_name):
    log_file = os.path.join(log_path, f"terraform_{_command_type}.log")
    run_id = os.getenv("RUN_ID", "")
    results = []

    if not os.path.isfile(log_file):
        print(f"[WARNING] Log file not found: {log_file}")
        return results

    try:
        with open(log_file, "r", encoding='utf-8') as f:
            for line in f:
                match = PATTERN.search(line)
                if match:
                    full_path, time_str = match.groups()
                    seconds = time_to_seconds(time_str)
                    module, submodule, resource = parse_module_path(full_path)

                    results.append({
                        "timestamp": datetime.datetime.now().isoformat(),
                        "run_id": run_id,
                        "scenario_type": _scenario_type,
                        "scenario_name": _scenario_name,
                        "module_name": module,
                        "submodule_name": submodule,
                        "resource_name": resource,
                        "action": _command_type,
                        "time_taken_seconds": seconds
                    })
    except Exception as e:
        print(f"[ERROR] Failed to process log file '{log_file}': {e}")

    return results