feat: module follow-ups, and L-07 reworded

- A Check met through a module is met by a value in the code: the modules
  Skill tells the author to set every input a Check depends on.
- scripts/check-terraform-modules.py reports catalogued modules with a newer
  version, and watched modules that can now be used with the pinned provider.
- L-07 no longer mentions a low-carbon location, which led to a Check about a
  region's carbon score that code cannot show. Reworded with the owner's
  approval.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-10 13:34:45 +01:00
parent 81ac135cd9
commit 135401e41b
8 changed files with 141 additions and 6 deletions

View File

@@ -0,0 +1,96 @@
#!/usr/bin/env python3
"""Review the published Terraform modules a provider bundle's modules Skill uses.
For each module the Skill's examples call: the version pinned there, the latest in
the registry, and whether the latest still works with the pinned provider. For each
module the bundle lists under `terraform.modules.watch`, which could not be used
when last looked at: whether its latest version now can.
It reads the public registry and changes nothing. Raising a pinned version is a
change to the Skill's example, which `tests/test_iac_modules.py` then validates.
Usage: .venv/bin/python scripts/check-terraform-modules.py [provider]
"""
from __future__ import annotations
import asyncio
import re
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from app.adk.runtime import ToolResult
from app.providers import load_provider
from app.tools.modules import ModuleLookup, admits, module_calls
_HCL = re.compile(r"^```hcl\n(.*?)^```", re.MULTILINE | re.DOTALL)
def _blocked(part: dict, pinned: dict[str, str]) -> list[str]:
"""The provider requirements of a module that the pinned versions do not meet."""
return [
f"{need.get('name')} {need.get('version')}"
for need in part.get("provider_dependencies") or []
if need.get("name") in pinned
and need.get("version")
and not admits(need["version"], pinned[need["name"]])
]
async def main(provider: str) -> int:
bundle = load_provider(provider)
if not bundle.terraform_modules_skill:
print(f"The {provider} bundle names no modules Skill.")
return 0
pinned = {name: pin["version"] for name, pin in bundle.terraform_providers.items()}
lookup = ModuleLookup(namespaces=bundle.terraform_module_namespaces, pinned=pinned)
skill = bundle.skills[bundle.terraform_modules_skill].path
used: dict[str, set[str]] = {}
for reference in sorted((skill / "references").glob("*.md")):
code = "\n".join(_HCL.findall(reference.read_text(encoding="utf-8")))
for call in module_calls({"main.tf": code}):
used.setdefault(call.source.split("//")[0], set()).add(call.version)
stale = 0
print(f"Pinned providers: {pinned}\n\nModules the Skill uses:")
for module, versions in sorted(used.items()):
data = await lookup._fetch(module, "")
if isinstance(data, ToolResult):
print(f" {module}: {data.message}")
continue
latest = str(data.get("version", "?"))
blocked = _blocked(data.get("root") or {}, pinned)
note = "up to date" if versions == {latest} else f"latest is {latest}"
if versions != {latest}:
stale += 1
if blocked:
note += f"; the latest needs {', '.join(blocked)}, so stay on the pin"
print(f" {module} {', '.join(sorted(versions))}: {note}")
print("\nModules that could not be used when last looked at:")
usable = 0
for name in bundle.terraform_modules_watch:
data = await lookup._fetch(name, "")
if isinstance(data, ToolResult):
print(f" {name}: {data.message}")
continue
blocked = _blocked(data.get("root") or {}, pinned)
if blocked:
print(f" {name} {data.get('version')}: still needs {', '.join(blocked)}")
else:
usable += 1
print(
f" {name} {data.get('version')}: NOW USABLE with the pinned provider"
)
print(
f"\n{stale} pinned module(s) have a newer version; {usable} watched "
"module(s) can now be used."
)
return 0
if __name__ == "__main__":
sys.exit(asyncio.run(main(sys.argv[1] if len(sys.argv) > 1 else "gcp")))