From ac32c983594b9f6cb1a3247c1fd322eec805c227 Mon Sep 17 00:00:00 2001 From: Osvaldo Demo Date: Fri, 19 Apr 2024 11:02:21 -0300 Subject: [PATCH] properly parse source key in modules --- leverage/checker/version_parser.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/leverage/checker/version_parser.py b/leverage/checker/version_parser.py index b085c6e..ea03523 100644 --- a/leverage/checker/version_parser.py +++ b/leverage/checker/version_parser.py @@ -1,3 +1,4 @@ +import json import os import re from typing import Dict, Any, Union, List @@ -46,13 +47,14 @@ def extract_provider_versions(providers: Dict[str, Any], versions: Dict[str, Dic def extract_module_versions(tf_config: Dict[str, Any], versions: Dict[str, Dict[str, str]]): module_version_pattern = re.compile(r"\?ref=v([\d\.]+)$") for module in tf_config.get("module", []): - if isinstance(module, dict) and "source" in module: - source = module["source"] - match = module_version_pattern.search(source) - if match: - versions[f"Module: {module['source']}"] = {"type": "module", "version": match.group(1)} - elif "version" in module: - versions[f"Module: {module['source']}"] = {"type": "module", "version": module["version"]} + if isinstance(module, dict) and len(module) == 1: + for name, data in module.items(): + source = data["source"] + match = module_version_pattern.search(source) + if match: + versions[name] = {"type": "module", "version": match.group(1), "repo": source.split("?")[0]} + elif "version" in module: + versions[name] = {"type": "module", "version": data["version"]} class TerraformFileParser: