feat: opt-in published Terraform modules from approved sources (iteration 8)

Infrastructure code is plain resources by default. An Execution may opt in
with terraform_modules; the deployment default is TERRAFORM_MODULES, off.

- A module is accepted only from the registry namespaces the provider bundle
  lists (terraform-google-modules), at one exact version. Any other source is
  refused before Terraform runs; until now nothing stopped generated code
  naming any source for terraform init to download.
- terraform_module looks up a module's inputs, outputs and submodules from
  the registry and says when it cannot be used with the pinned provider.
- skills/google-cloud-iac-modules: when a module fits, and four modules with
  examples a test validates against hashicorp/google 8.6.0.
- Opted in, the IaC author and validator get the Skill and the lookup. Not
  opted in, they get neither and a module block is refused in code.
- A Change request follows its Baseline. execution.json records the choice.
- case-07 runs case 03's request with modules opted into.

Azure (aztfm) and AWS (terraform-aws-modules) sources are recorded in the
plan for when those Cloud providers are added. No case has run with this.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-09 22:09:29 +01:00
parent a8ed21b89d
commit ef37f59bad
35 changed files with 1482 additions and 7 deletions

View File

@@ -72,6 +72,12 @@ class ProviderBundle:
# The Terraform providers generated code is written for, pinned so the schema
# lookup, the patterns and validation agree: {name: {source, version}}.
terraform_providers: Mapping[str, Mapping[str, str]] = field(default_factory=dict)
# Registry namespaces generated code may take a Terraform module from. Empty
# means no module is accepted.
terraform_module_namespaces: tuple[str, ...] = ()
# The Skill that says which modules to use and when. It reaches a Specialist
# only in an Execution that opted into modules.
terraform_modules_skill: str | None = None
# The Skill approved lessons are published in (ADR-0004); None when the provider
# has none. A Specialist is given it once it holds lessons for its Deliverable.
lessons_skill: str | None = None
@@ -155,6 +161,21 @@ def load_provider(name: str, root: Path | None = None) -> ProviderBundle:
"version": pin["version"],
}
module_namespaces = ((config.get("terraform") or {}).get("modules") or {}).get(
"namespaces"
) or []
if not isinstance(module_namespaces, list) or not all(
isinstance(item, str) and item for item in module_namespaces
):
raise fail("'terraform.modules.namespaces' must be a list of names")
modules_skill = ((config.get("terraform") or {}).get("modules") or {}).get(
"skill"
) or None
if modules_skill is not None and modules_skill not in skills:
raise fail(
f"'terraform.modules.skill' references unknown skill {modules_skill!r}"
)
tools = {}
for tier, tool_names in (config.get("tools") or {}).items():
if tier not in TIERS:
@@ -221,5 +242,7 @@ def load_provider(name: str, root: Path | None = None) -> ProviderBundle:
role_skills=role_skills,
pillar_skills=pillar_skills,
terraform_providers=terraform_providers,
terraform_module_namespaces=tuple(module_namespaces),
terraform_modules_skill=modules_skill,
lessons_skill=lessons_skill,
)