Skip to content

Commit

Permalink
properly parse source key in modules
Browse files Browse the repository at this point in the history
  • Loading branch information
borland667 authored and Osvaldo Demo committed Apr 19, 2024
1 parent 0162afa commit ac32c98
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions leverage/checker/version_parser.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import os
import re
from typing import Dict, Any, Union, List
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit ac32c98

Please sign in to comment.