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:
@@ -13,6 +13,7 @@ One directory per iteration of this agent. Each holds the plan for that iteratio
|
||||
| 5 | `iter-05-jev-decisions/` | the router, intake, the reviews, pillar selection, Skill routing, the guardrail, meaning-aware change summaries and an assessment of every Execution are built (steps 2–5, 8, 10–12, 14, 15, 19), the newest ran in cases 05 and 06 on 2026-10-09; a lighter model for a first attempt was built, measured and left off (6); context selection and compaction were decided against on the numbers (7, 9); the cloud-read guard and readings as a node are planned (13, 18) | Jev (a hosted decision model) for the agent's closed decisions: checks, routing, context selection. |
|
||||
| 6 | `iter-06-target-architecture-graph/` | complete: all four cases pass with real models, each run twice on 2026-10-08; thresholds set | The Target architecture as one explicit graph of Elements, Relationships and Checks, established before infrastructure code, with validation as a verdict per Check. |
|
||||
| 7 | `iter-07-change-requests/` | complete (2026-10-09): the change case ran with real models and passed | A user restates a request to say how requirements changed; a new Execution starts from a Baseline Execution of the same Customer case and delivers the updated architecture with what changed. |
|
||||
| 8 | `iter-08-terraform-modules/` | steps 1–5 built on 2026-10-09; no case has run with them; steps 6 and 7 wait on Azure and AWS provider bundles | Infrastructure code is plain resources by default. An Execution may opt into published Terraform modules: only from registry namespaces the provider bundle lists, at one exact version, with a lookup of what a module accepts and a Skill of four Google modules tested against the pinned provider. |
|
||||
|
||||
Numbers record when an iteration was planned, not the order to build in. Build iteration 6 before the remaining steps of iteration 4 (10 to 14) and before iteration 5: it changes the Deliverables, Phases and validation format they build on. Its `MAP.md` lists the effect on each of their steps.
|
||||
|
||||
|
||||
43
.agents/plans/iter-08-terraform-modules/MAP.md
Normal file
43
.agents/plans/iter-08-terraform-modules/MAP.md
Normal file
@@ -0,0 +1,43 @@
|
||||
# Plan Map
|
||||
|
||||
**Iteration:** 8, Terraform modules
|
||||
**Intent:** Let generated infrastructure code call a published Terraform module where one replaces several resources that must be wired together, without losing the Requirements chain or opening a way for arbitrary code to be downloaded.
|
||||
**Status:** steps 1 to 5 built on 2026-10-09; a case run each way is outstanding; steps 6 and 7 wait on those Cloud providers
|
||||
**This directory covers:** steps 1 to 7
|
||||
|
||||
## The owner's request (2026-10-09)
|
||||
|
||||
Use modules, when necessary, from three organisations:
|
||||
|
||||
| Cloud provider | Source | Here |
|
||||
|---|---|---|
|
||||
| Google Cloud | https://github.com/terraform-google-modules | built: the `terraform-google-modules` registry namespace is allowed in `providers/gcp.yaml` |
|
||||
| Azure | https://github.com/aztfm | recorded for step 6: there is no Azure provider bundle |
|
||||
| AWS | https://github.com/terraform-aws-modules | recorded for step 7: there is no AWS provider bundle |
|
||||
|
||||
The owner's decision, 2026-10-09: **plain resources by default, with an opt-in to known approved sources.**
|
||||
|
||||
- **Opt-in per Execution.** A caller sets `terraform_modules`; the deployment's default is `TERRAFORM_MODULES`, off. A Change request does as its Baseline did unless told otherwise.
|
||||
- **Approved sources are the provider bundle's list.** Opted in, a module is still used only from the tested catalogue and only where it replaces three or more resources that depend on each other.
|
||||
- **Google now.** The tooling names no Cloud provider; the bundle and a Skill do (ADR-0002).
|
||||
|
||||
## What was found first
|
||||
|
||||
- `terraform init` downloads and evaluates whatever a `source` names. Before this iteration nothing stopped generated code naming any Git URL.
|
||||
- A module carries its own provider requirements. Of 23 modules in the Google organisation looked at, these require `google` below 8 and cannot be used with the pinned 8.6.0: `lb-http`, `pubsub`, `bigquery`, `kubernetes-engine`, `log-export`, `event-function`, `scheduled-function`, `bastion-host`. So a catalogue has to be tested, whichever rule decides when a module is used.
|
||||
- Code using two modules validated in 11 seconds against the pinned provider, modules downloaded.
|
||||
|
||||
## Status
|
||||
|
||||
| Step | What | Status |
|
||||
|---|---|---|
|
||||
| 1 | Allow modules only from namespaces the bundle lists, at one exact version | built: `check_module_sources` in `app/tools/modules.py`, run before every validate and plan |
|
||||
| 2 | A lookup of what a module accepts | built: the `terraform_module` tool, from the public registry, for the IaC author and the validator |
|
||||
| 3 | A Skill with the catalogue and the rule for when to use one | built: `skills/google-cloud-iac-modules/`, four references, each validated by a test |
|
||||
| 4 | Checks through a module | built as guidance: `implementation.json` names the module input; the validator confirms what the input sets |
|
||||
| 5 | Opt-in per Execution, plain resources by default | built: `terraform_modules` on a start, `/generate`, A2A metadata and an evaluation case; recorded in `execution.json` |
|
||||
| 5a | Run a case each way and see what the agents do with it | not run |
|
||||
| 6 | Azure: `aztfm` | waits on an Azure provider bundle |
|
||||
| 7 | AWS: `terraform-aws-modules` | waits on an AWS provider bundle |
|
||||
|
||||
Detail: `steps/step-1-to-5.md`.
|
||||
62
.agents/plans/iter-08-terraform-modules/steps/step-1-to-5.md
Normal file
62
.agents/plans/iter-08-terraform-modules/steps/step-1-to-5.md
Normal file
@@ -0,0 +1,62 @@
|
||||
# Steps 1 to 5 — Implementation Detail
|
||||
|
||||
Built on 2026-10-09. **No Execution has run with it.**
|
||||
|
||||
## 1. Which modules
|
||||
|
||||
`terraform.modules.namespaces` in the provider bundle lists the registry namespaces a module may come from; for Google Cloud, `terraform-google-modules`. `TerraformRunner.validate` and `.plan` refuse, before Terraform runs:
|
||||
|
||||
- a `source` that is not `<allowed namespace>/<name>/<provider>`, optionally with `//path`: so any Git or HTTP URL, a GitHub shorthand, a local path, or another namespace;
|
||||
- a `version` that is not one exact version;
|
||||
- a module written in `.tf.json`.
|
||||
|
||||
With no namespace listed every module call is refused. The evaluation's own validation uses the same list, and only for a case that opts in.
|
||||
|
||||
The source the owner gave is a GitHub organisation; the registry namespace of the same name is what Terraform is pointed at, because the registry serves a fixed archive for a version and `terraform init` needs no Git.
|
||||
|
||||
## 2. What a module accepts
|
||||
|
||||
`terraform_module(source, version, find)` reads the public Terraform registry: a module's or submodule's inputs (required first, with type and description), its outputs and its submodules. It compares the module's provider requirements with the versions the bundle pins and says "NOT USABLE" when they exclude it. Only allowed namespaces can be looked up. Answers are cached for the life of the process.
|
||||
|
||||
It makes one new outbound call, to `registry.terraform.io`, which `terraform init` already reaches.
|
||||
|
||||
## 3. The Skill
|
||||
|
||||
`skills/google-cloud-iac-modules/`: when to use a module (it is in the table, it replaces three or more dependent resources, and every Check on the Elements it covers can be met through an input), and four references with a validated example each.
|
||||
|
||||
| For | Module | Version |
|
||||
|---|---|---|
|
||||
| VPC, subnets, firewall rules, Cloud NAT | `network`, `cloud-nat` | 18.3.1, 7.1.0 |
|
||||
| Cloud SQL for PostgreSQL on a private address | `sql-db//modules/postgresql`, `//modules/private_service_access` | 28.3.0 |
|
||||
| A Cloud Storage bucket with retention, lifecycle, encryption, grants | `cloud-storage//modules/simple_bucket` | 12.4.1 |
|
||||
| A key ring, keys and grants | `kms` | 4.2.1 |
|
||||
|
||||
`tests/test_iac_modules.py` runs each example through `terraform validate` with the patterns Skill's versions file, and checks that every module call is from an allowed namespace at the version the table gives. It needs the network and is skipped without it.
|
||||
|
||||
The Skill is named in the bundle under `terraform.modules.skill`, not among any role's Skills. See step 5 for who is given it.
|
||||
|
||||
## 4. Checks through a module
|
||||
|
||||
A Check stays worded about the resource. `implementation.json` gives the module and the input that meets it, such as `module.database.ip_configuration.ipv4_enabled`. When no input sets what a Check needs, the module does not fit and the resources are written directly. The validator reads the input's value and confirms with the lookup what it sets, or what its default is.
|
||||
|
||||
This is instruction, in the Skills and the two role files. Nothing in code verifies that a module input does what a Check says: that would need a plan against a real project.
|
||||
|
||||
## 5. Opt-in per Execution
|
||||
|
||||
Infrastructure code is plain resources unless the Execution opts in.
|
||||
|
||||
- `ExecutionEngine.start(terraform_modules=...)`: true, false, or unset. Unset, a Change request does as its Baseline did, and any other Execution takes `TERRAFORM_MODULES` (off). Opting in is refused when the provider's bundle lists no sources.
|
||||
- Callers: `terraform_modules` in the `/generate` body, in A2A message metadata, and on an evaluation case.
|
||||
- **Opted in:** the roles that carry the `terraform_module` tool (the IaC author and the validator) are given the modules Skill, and their context says `terraform_modules: true`.
|
||||
- **Not opted in:** those roles get neither the Skill nor the tool, and any `module` block is refused by `terraform_validate` and `terraform_plan` with a message saying to write the resources directly. The refusal is in code (`MODULES_OPTED_IN` in `app/tools/modules.py`, set when a Specialist starts), not only in instructions.
|
||||
- `execution.json` records `terraform_modules`.
|
||||
|
||||
Reference routing (iteration 5 step 8) does not choose within the modules Skill, because it is not among a role's Skills at start-up.
|
||||
|
||||
## Known limits
|
||||
|
||||
- Modules also bring providers the bundle does not pin (`google-beta`, `random`, `null`), at whatever version their constraints allow.
|
||||
- The schema review and the target architect's lookups still describe resources. A Check's wording is unaffected by whether a module later creates the resource.
|
||||
- A module version in the catalogue goes stale; nothing flags a newer one.
|
||||
|
||||
Tests: `tests/tools/test_modules.py` (24), `tests/test_iac_modules.py` (6), `tests/execution/test_terraform_modules.py` (7).
|
||||
@@ -35,6 +35,10 @@ TERRAFORM_TIMEOUT_SECONDS=300
|
||||
# Relative to the repository root; set it empty to disable.
|
||||
TF_PLUGIN_CACHE_DIR=.cache/terraform-plugins
|
||||
|
||||
# Use published Terraform modules when a caller does not say. Off writes plain
|
||||
# resources; a caller opts in per Execution with terraform_modules.
|
||||
TERRAFORM_MODULES=false
|
||||
|
||||
# Hierarchical Execution Engine
|
||||
ORCHESTRATOR=router # router | model
|
||||
ORCHESTRATOR_BUDGET=40
|
||||
|
||||
@@ -38,6 +38,7 @@ Behaviour lives in Agent Skills (agentskills.io format) at the repository root,
|
||||
- `skills/google-cloud-lessons/`: lessons learned from earlier Executions, written by the lessons loop (`app/learning/`, `eval/curate_lessons.py`) from proposals a person approved ([ADR-0004](docs/adr/0004-lessons-and-overlays-arrive-as-skills.md)). Set `LESSONS_ENABLED=false` to run without them.
|
||||
- `skills/overlays/`: overlay Skills, each an organisation's standards or one engagement's constraints. An Execution names the ones it wants; `DEFAULT_OVERLAY_SKILLS` names the ones every Execution loads. The one here is an example, not anyone's policy.
|
||||
- `skills/google-cloud-iac-patterns/`: Terraform patterns for Google Cloud products, each validated by a test against the provider version `providers/gcp.yaml` pins.
|
||||
- `skills/google-cloud-iac-modules/`: published modules from `terraform-google-modules` that work with that provider version, and the rule for when one fits better than plain resources. Generated code is plain resources by default. An Execution opts in with `terraform_modules: true`, and may then take a module only from the registry namespaces `providers/gcp.yaml` lists, at one exact version.
|
||||
|
||||
`app/skills/agent_skills.py` discovers and validates them; the ADK runtime (`app/adk/adk_runtime.py`) loads them on demand. `providers/gcp.yaml` assigns Skills, tools, MCP servers and models to each role in `agents/`.
|
||||
|
||||
@@ -56,7 +57,7 @@ The container starts the hierarchical Execution engine (ADR-0003) behind an A2A
|
||||
- `POST /a2a`: A2A JSON-RPC for interactive, multi-turn Executions with Approvals.
|
||||
- `GET /.well-known/agent-card.json`: A2A agent card.
|
||||
- `GET /health`: Health signal, the Cloud provider and any MCP discovery gaps.
|
||||
- `POST /generate`: One-shot, pre-approved Execution for batch and evaluation callers. Pass `customer_case` to group it with the case's other Executions, `baseline` (an Execution id in that case) to make it a Change request, and `overlay_skills` (a list of names) to apply overlay Skills. Over A2A, send the same fields in the message metadata.
|
||||
- `POST /generate`: One-shot, pre-approved Execution for batch and evaluation callers. Pass `customer_case` to group it with the case's other Executions, `baseline` (an Execution id in that case) to make it a Change request, `overlay_skills` (a list of names) to apply overlay Skills, and `terraform_modules: true` to allow published Terraform modules from the approved sources. Over A2A, send the same fields in the message metadata.
|
||||
|
||||
The original linear pipeline and its REST routes (`/card`, `/validate`, `/sessions/{session_id}`) were removed on 2026-10-06; see `.agents/plans/iter-03-kab-layout/`.
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
---
|
||||
role: iac-author
|
||||
deliverable: deployment_guidance
|
||||
tools: [terraform_fmt, terraform_validate, terraform_schema]
|
||||
tools: [terraform_fmt, terraform_validate, terraform_schema, terraform_module]
|
||||
budget: 40
|
||||
includes: [specialist-protocol]
|
||||
---
|
||||
@@ -9,6 +9,7 @@ You produce the **deployment guidance** Deliverable: the Skill's task for genera
|
||||
|
||||
- Write Terraform that implements the Target architecture: every Element, every Relationship and every Check, and nothing it does not ask for.
|
||||
- Before you write a resource, load the infrastructure-as-code patterns Skill when you have one, and start from its pattern for that product and its provider versions file.
|
||||
- Write plain resources unless `terraform_modules` is true in your context. When it is, you have an infrastructure-as-code modules Skill: load it. It says when a published module fits an Element better than plain resources, which modules are approved, and how a Check is met through a module's input. Use a module only as it says.
|
||||
- Keep the files in your working copy. Write each file once with `write_file`, and make every later change with `edit_file`, changing only the lines that need it. Never write a file again to fix part of it.
|
||||
- Format and validate with `terraform_fmt` and `terraform_validate` when they are available. They run on your working copy, so pass them no files. Fix everything they report.
|
||||
- When validation says an argument or block is not expected, look the resource type up with `terraform_schema` instead of guessing where it belongs.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
---
|
||||
role: validator
|
||||
deliverable: validation_results
|
||||
tools: [terraform_validate, terraform_plan, terraform_schema]
|
||||
tools: [terraform_validate, terraform_plan, terraform_schema, terraform_module]
|
||||
budget: 30
|
||||
includes: [specialist-protocol]
|
||||
---
|
||||
@@ -10,6 +10,7 @@ You produce the **validation results** Deliverable: the Skill's pre-deployment v
|
||||
- Run the deployment dry-run with your tools: validate the Terraform, and preview it with a plan when you have permission to read live cloud resources. The tools already hold the submitted files, so pass them no files.
|
||||
- Give a verdict on every Check in the Target architecture, from the infrastructure code: pass, fail or not verifiable, each with the evidence you read. The Checks are the whole bar: judge the code against them and nothing else.
|
||||
- Before you fail a Check because the code lacks a setting, confirm with `terraform_schema` that the resource type has that setting, when the tool is available. When it does not, the Check cannot be met by any code: give it not verifiable, with what the schema shows as the evidence. Give the same verdict to a Check that `implementation.json` records as unimplementable.
|
||||
- When `terraform_modules` is true the code may call approved published modules. Then judge a Check on a resource the module creates from the module input that sets it: read the value in the code, and confirm with `terraform_module` what that input sets or what its default is. The modules Skill, when you have one, says how.
|
||||
- Review the Target architecture's coverage once, completely. Go through every requirement and every design recommendation in turn; for each, list the conditions its text states and the Elements it applies to, and record a proposed addition for each one no Check verifies, naming the requirement or recommendation it serves. Report every gap in this pass: each later pass that finds one more costs a whole Revision of the design, the code and this validation. Propose nothing for what a requirement or recommendation lists under `outside_code`: that is application behaviour, an outcome measured in operation, or a process, and no Check on infrastructure code can verify it. Name those under your analysis heading as things to verify after deployment. A proposed addition is not a failure of the code.
|
||||
- When `feedback` or your earlier verdicts show the Target architecture was revised for your proposed additions, propose only what the revision still leaves uncovered. Never propose what a Check already verifies in other words.
|
||||
- Record your verdicts with `verdict_put`, a few Checks per call, as you reach them: the Checks of one Element, then the next. Record the dry-run's result and each proposed addition the same way. Short calls are what keep your replies from timing out, and what you record is kept if your run is cut short. `verdict_read` shows which Checks still have none.
|
||||
|
||||
@@ -108,6 +108,7 @@ class SolutionArchitectExecutor(AgentExecutor):
|
||||
customer_case=options.get("customer_case"),
|
||||
baseline=options.get("baseline"),
|
||||
overlay_skills=options.get("overlay_skills") or (),
|
||||
terraform_modules=options.get("terraform_modules"),
|
||||
execution_id=task_id,
|
||||
pre_approved=bool(options.get("pre_approved", False)),
|
||||
allow_cloud_read=options.get("allow_cloud_read"),
|
||||
|
||||
@@ -13,6 +13,7 @@ from pathlib import Path
|
||||
from app.adk.runtime import RoleSpec
|
||||
from app.providers import ProviderBundle
|
||||
from app.skills.agent_skills import SkillFormatError, split_frontmatter
|
||||
from app.tools.modules import MODULE_TOOL
|
||||
from app.workflows.deliverables import DEPENDENCY_GRAPH, DeliverableKind
|
||||
|
||||
ORCHESTRATOR = "orchestrator"
|
||||
@@ -83,6 +84,12 @@ def load_roles(
|
||||
f"'models.first_attempt' names {name!r}, which is not a role"
|
||||
)
|
||||
roles[name] = dataclasses.replace(roles[name], first_attempt_model=model)
|
||||
if bundle.terraform_modules_skill:
|
||||
for name, role in roles.items():
|
||||
if MODULE_TOOL in role.tools:
|
||||
roles[name] = dataclasses.replace(
|
||||
role, modules_skill=bundle.terraform_modules_skill
|
||||
)
|
||||
unexpected = sorted(set(roles) - required - optional)
|
||||
if unexpected:
|
||||
raise RoleConfigError(
|
||||
|
||||
@@ -37,6 +37,9 @@ class RoleSpec:
|
||||
# A lighter model for the first attempt at a Deliverable, when the bundle
|
||||
# names one and model tiers are on (iteration 5 step 6).
|
||||
first_attempt_model: str | None = None
|
||||
# The Skill on published Terraform modules, for a role that may call them. It
|
||||
# is added to the role's Skills only in an Execution that opted into modules.
|
||||
modules_skill: str | None = None
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
|
||||
30
app/agent.py
30
app/agent.py
@@ -103,6 +103,8 @@ class ExecutionEngine:
|
||||
skill_references: Mapping[str, Mapping[str, Mapping[str, str]]] | None = None,
|
||||
skill_threshold: float = 1.25,
|
||||
assess_at_end: bool = False,
|
||||
modules_available: bool = False,
|
||||
default_modules: bool = False,
|
||||
) -> None:
|
||||
required = {
|
||||
ORCHESTRATOR,
|
||||
@@ -112,6 +114,10 @@ class ExecutionEngine:
|
||||
if missing:
|
||||
raise ValueError(f"Missing roles: {', '.join(missing)}")
|
||||
self._max_revisions = max_revisions
|
||||
# Whether the Cloud provider approves any module sources, and whether an
|
||||
# Execution uses them when its caller does not say.
|
||||
self._modules_available = modules_available
|
||||
self._default_modules = default_modules and modules_available
|
||||
self._output_root = output_root
|
||||
# Overlay Skills an Execution may name, with the version of each (ADR-0004).
|
||||
self._overlays = dict(overlays or {})
|
||||
@@ -153,6 +159,7 @@ class ExecutionEngine:
|
||||
scripted_answers: Sequence[Sequence[str]] = (),
|
||||
baseline: str | None = None,
|
||||
overlay_skills: Sequence[str] = (),
|
||||
terraform_modules: bool | None = None,
|
||||
) -> Interaction:
|
||||
"""Start an Execution. `scripted_answers` are (regex, answer[, asker]) entries a
|
||||
pre-approved Execution uses to answer questions, for evaluation runs.
|
||||
@@ -166,6 +173,12 @@ class ExecutionEngine:
|
||||
this engagement's constraints. Each must be one the deployment has
|
||||
configured; an unknown name refuses the start. Every Specialist loads them
|
||||
with the ones the deployment loads by default.
|
||||
|
||||
`terraform_modules` opts the Execution into published Terraform modules
|
||||
from the sources the Cloud provider approves. Left unset, a Change request
|
||||
does as its Baseline did and any other Execution takes the deployment's
|
||||
default, which is plain resources. Opting in is refused when the provider
|
||||
approves no sources.
|
||||
"""
|
||||
customer_case = check_customer_case(customer_case)
|
||||
execution_id = execution_id or str(uuid.uuid4())
|
||||
@@ -187,6 +200,19 @@ class ExecutionEngine:
|
||||
if baseline
|
||||
else None
|
||||
)
|
||||
if terraform_modules is None:
|
||||
terraform_modules = (
|
||||
bool(loaded.get("terraform_modules"))
|
||||
if loaded
|
||||
else self._default_modules
|
||||
)
|
||||
if not isinstance(terraform_modules, bool):
|
||||
# A ValueError is what callers turn into a refused start.
|
||||
raise ValueError("terraform_modules must be true or false") # noqa: TRY004
|
||||
if terraform_modules and not self._modules_available:
|
||||
raise ValueError(
|
||||
"terraform_modules: this Cloud provider has no approved module sources"
|
||||
)
|
||||
if pre_approved and allow_cloud_read is None:
|
||||
allow_cloud_read = False
|
||||
session_id = session_id or str(uuid.uuid4())
|
||||
@@ -208,6 +234,7 @@ class ExecutionEngine:
|
||||
"baseline": loaded,
|
||||
# Overlay Skills this Execution loads, each with the version it had.
|
||||
"overlay_skills": {name: self._overlays[name] for name in chosen},
|
||||
"terraform_modules": terraform_modules,
|
||||
"risks": [],
|
||||
"pre_approved": pre_approved,
|
||||
"allow_cloud_read": allow_cloud_read,
|
||||
@@ -404,6 +431,7 @@ async def open_assembly(
|
||||
timeout_seconds=settings.TERRAFORM_TIMEOUT_SECONDS,
|
||||
plugin_cache_dir=settings.terraform_plugin_cache(),
|
||||
providers=bundle.terraform_providers,
|
||||
module_namespaces=bundle.terraform_module_namespaces,
|
||||
)
|
||||
offered = [name for names in bundle.tools.values() for name in names]
|
||||
# One cap for Specialists and the pillar advisors they fan out to.
|
||||
@@ -482,6 +510,8 @@ async def open_assembly(
|
||||
else None,
|
||||
skill_threshold=settings.JEV_SKILL_THRESHOLD,
|
||||
assess_at_end=settings.JEV_ASSESS_EXECUTIONS,
|
||||
modules_available=bool(bundle.terraform_module_namespaces),
|
||||
default_modules=settings.TERRAFORM_MODULES,
|
||||
overlays={
|
||||
name: skill_version(meta.path) for name, meta in overlays.items()
|
||||
},
|
||||
|
||||
@@ -101,6 +101,8 @@ def load_baseline(
|
||||
"customer_case": customer_case,
|
||||
"workflow_request": manifest.get("workflow_request", ""),
|
||||
"baseline": manifest.get("baseline"), # what it was itself changed from
|
||||
# Whether its code was allowed published modules; a Change request follows.
|
||||
"terraform_modules": bool(manifest.get("terraform_modules")),
|
||||
"deliverables": deliverables,
|
||||
# Working material worth starting from again, such as pillar advice.
|
||||
"working": working,
|
||||
|
||||
@@ -61,6 +61,11 @@ class Settings(BaseSettings):
|
||||
# Overlay Skills every Execution loads, comma-separated.
|
||||
DEFAULT_OVERLAY_SKILLS: str = ""
|
||||
|
||||
# Whether an Execution may use published Terraform modules when its caller does
|
||||
# not say. Off: infrastructure code is plain resources, and a caller opts in
|
||||
# per Execution with `terraform_modules`. The sources are the provider bundle's.
|
||||
TERRAFORM_MODULES: bool = False
|
||||
|
||||
# Give Specialists the lessons Skill. Off runs without anything learned, which
|
||||
# is how the evaluation shows whether a lesson helps.
|
||||
LESSONS_ENABLED: bool = True
|
||||
|
||||
@@ -71,6 +71,7 @@ def create_app(
|
||||
customer_case=body.get("customer_case"),
|
||||
baseline=body.get("baseline"),
|
||||
overlay_skills=body.get("overlay_skills") or (),
|
||||
terraform_modules=body.get("terraform_modules"),
|
||||
pre_approved=True,
|
||||
allow_cloud_read=bool(body.get("allow_cloud_read", False)),
|
||||
)
|
||||
|
||||
@@ -53,6 +53,7 @@ from app.tools.assessment import assess
|
||||
from app.tools.execution import ORCHESTRATOR, OrchestratorToolbox, specialist_tools
|
||||
from app.tools.guardrail import EXECUTION_SCOPE, instructs_agent
|
||||
from app.tools.meaning import settle_meaning
|
||||
from app.tools.modules import MODULE_TOOL, MODULES_OPTED_IN
|
||||
from app.tools.pillars import ADVICE_KEY, KEPT_FOR_CHANGES, pillars_touched
|
||||
from app.tools.skill_routing import read_first
|
||||
from app.workflows.chain import (
|
||||
@@ -458,6 +459,15 @@ def make_execution_nodes(
|
||||
role = dataclasses.replace(
|
||||
role, skills=(*role.skills, *(n for n in named if n not in role.skills))
|
||||
)
|
||||
opted_in = bool(task_input.get("terraform_modules"))
|
||||
MODULES_OPTED_IN.set(opted_in)
|
||||
if opted_in and role.modules_skill:
|
||||
role = dataclasses.replace(role, skills=(*role.skills, role.modules_skill))
|
||||
elif MODULE_TOOL in role.tools:
|
||||
# Plain resources: no modules Skill and no module lookup.
|
||||
role = dataclasses.replace(
|
||||
role, tools=tuple(tool for tool in role.tools if tool != MODULE_TOOL)
|
||||
)
|
||||
if role.first_attempt_model and task_input.get("first_attempt"):
|
||||
logger.info(
|
||||
"[%s] %s takes %s for a first attempt",
|
||||
@@ -874,6 +884,8 @@ def _specialist_input(
|
||||
"first_attempt": not ledger.feedback(kind)
|
||||
and (attempt == 1 or kind.value in deliverables),
|
||||
"allow_cloud_read": state.get("allow_cloud_read"),
|
||||
# Whether this Execution opted into published Terraform modules.
|
||||
"terraform_modules": bool(state.get("terraform_modules")),
|
||||
"working": dict(state.get("working", {}).get(kind.value, {})),
|
||||
# Whether the user has been shown a draft of this Deliverable. Answering some
|
||||
# other question about it, such as what to do after it stopped, is not that.
|
||||
@@ -903,6 +915,9 @@ def _specialist_input(
|
||||
# Skills carrying the organisation's standards or this engagement's
|
||||
# constraints. Where one disagrees with general guidance, it wins.
|
||||
"overlay_skills": sorted(state.get("overlay_skills") or {}),
|
||||
# False: infrastructure code is plain resources. True: a published
|
||||
# module may be used where the modules Skill says one fits.
|
||||
"terraform_modules": bool(state.get("terraform_modules")),
|
||||
# The pillars a change touches, when that could be judged: the design
|
||||
# advisor consults those and keeps its earlier advice for the rest.
|
||||
"pillars_to_consult": (hints or {}).get(kind.value),
|
||||
@@ -1267,6 +1282,8 @@ def _write_outputs(
|
||||
"baseline": (state.get("baseline") or {}).get("execution_id"),
|
||||
# The overlay Skills it loaded, with the version of each.
|
||||
"overlay_skills": dict(state.get("overlay_skills") or {}),
|
||||
# Whether its infrastructure code was allowed published modules.
|
||||
"terraform_modules": bool(state.get("terraform_modules")),
|
||||
"status": status,
|
||||
"warnings": list(state.get("warnings", [])),
|
||||
# Flags a person should look at; nothing was done about them.
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
|
||||
@@ -58,6 +58,7 @@ class ExecutionState(TypedDict, total=False):
|
||||
workflow_request: str
|
||||
risks: list[dict[str, Any]] # flags on what the user wrote, for a person to see
|
||||
overlay_skills: dict[str, str] # overlay Skills this Execution loads -> version
|
||||
terraform_modules: bool # opted into published Terraform modules
|
||||
baseline: dict[str, Any] | None # a Change request's Baseline, read from its files
|
||||
pre_approved: bool
|
||||
allow_cloud_read: bool | None
|
||||
|
||||
@@ -30,6 +30,7 @@ from pathlib import Path, PurePosixPath
|
||||
from typing import Any
|
||||
|
||||
from app.adk.runtime import FILES_SCHEMA, ToolResult, ToolSpec, files_from_argument
|
||||
from app.tools.modules import ModuleLookup, allowed_namespaces, check_module_sources
|
||||
|
||||
_MAX_OUTPUT = 8_000
|
||||
_MAX_OUTLINE = 4_000 # one resource type, when several are looked up together
|
||||
@@ -98,6 +99,10 @@ class TerraformRunner:
|
||||
# The providers the schema lookup answers for, as the provider bundle pins them:
|
||||
# {local name: {"source": ..., "version": ...}}.
|
||||
providers: Mapping[str, Mapping[str, str]] = field(default_factory=dict)
|
||||
# Registry namespaces a `module` may come from, as the provider bundle lists
|
||||
# them. `terraform init` downloads and evaluates whatever a source names, so
|
||||
# with none listed every module call is refused.
|
||||
module_namespaces: tuple[str, ...] = ()
|
||||
# Terraform's plugin cache is not safe for concurrent installs.
|
||||
_init_lock: asyncio.Lock = field(default_factory=asyncio.Lock, repr=False)
|
||||
_schema_lock: asyncio.Lock = field(default_factory=asyncio.Lock, repr=False)
|
||||
@@ -138,7 +143,9 @@ class TerraformRunner:
|
||||
)
|
||||
|
||||
async def validate(self, files: Mapping[str, str]) -> ToolResult:
|
||||
refusal = _check_files(files)
|
||||
refusal = _check_files(files) or check_module_sources(
|
||||
files, allowed_namespaces(self.module_namespaces)
|
||||
)
|
||||
if refusal:
|
||||
return refusal
|
||||
with tempfile.TemporaryDirectory(prefix="tf-validate-") as tmp:
|
||||
@@ -153,7 +160,9 @@ class TerraformRunner:
|
||||
async def plan(
|
||||
self, files: Mapping[str, str], variables: Mapping[str, str] | None = None
|
||||
) -> ToolResult:
|
||||
refusal = _check_files(files)
|
||||
refusal = _check_files(files) or check_module_sources(
|
||||
files, allowed_namespaces(self.module_namespaces)
|
||||
)
|
||||
if refusal:
|
||||
return refusal
|
||||
variables = dict(variables or {})
|
||||
@@ -582,6 +591,16 @@ LOCAL_TOOLS: dict[str, tuple[str, str]] = {
|
||||
"cloud_read",
|
||||
"Preview Terraform against the live cloud environment with a plan. Never applies.",
|
||||
),
|
||||
"terraform_module": (
|
||||
"general",
|
||||
(
|
||||
"Look up a published Terraform module: its inputs, outputs and "
|
||||
"submodules, and whether it works with the pinned provider. Give "
|
||||
"`source` as <namespace>/<name>/<provider>, with //modules/<name> for "
|
||||
"a submodule. `version` is optional and defaults to the latest. `find` "
|
||||
"narrows the inputs to those matching the words given."
|
||||
),
|
||||
),
|
||||
"terraform_schema": (
|
||||
"general",
|
||||
(
|
||||
@@ -651,6 +670,32 @@ def local_tools(
|
||||
"terraform_plan": lambda: checks(
|
||||
"terraform_plan", _with_files(runner.plan, working_copy)
|
||||
),
|
||||
"terraform_module": lambda: ToolSpec(
|
||||
"terraform_module",
|
||||
LOCAL_TOOLS["terraform_module"][1],
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"source": {
|
||||
"type": "string",
|
||||
"description": (
|
||||
"For example terraform-google-modules/network/google"
|
||||
),
|
||||
},
|
||||
"version": {"type": "string", "description": "Such as 18.3.1"},
|
||||
"find": {
|
||||
"type": "string",
|
||||
"description": "Words to look for in input names, comma-separated",
|
||||
},
|
||||
},
|
||||
"required": ["source"],
|
||||
},
|
||||
ModuleLookup(
|
||||
namespaces=runner.module_namespaces,
|
||||
pinned={name: pin["version"] for name, pin in runner.providers.items()},
|
||||
).describe,
|
||||
tier="general",
|
||||
),
|
||||
"terraform_schema": lambda: ToolSpec(
|
||||
"terraform_schema",
|
||||
LOCAL_TOOLS["terraform_schema"][1],
|
||||
|
||||
300
app/tools/modules.py
Normal file
300
app/tools/modules.py
Normal file
@@ -0,0 +1,300 @@
|
||||
"""Terraform modules from a public registry (iteration 8).
|
||||
|
||||
Generated code may call a published module where one replaces several resources that
|
||||
must be wired together. Two things keep that safe and checkable, and neither names a
|
||||
Cloud provider: the provider bundle does.
|
||||
|
||||
- **Which modules.** `terraform init` downloads whatever a `source` names and
|
||||
Terraform then evaluates it. So a module is accepted only from a registry
|
||||
namespace the bundle lists, at one exact version. Anything else, a Git URL, a
|
||||
local path or a version range, is refused before Terraform runs.
|
||||
- **What a module accepts.** A module hides the resources a Check is about. The
|
||||
lookup returns a module's inputs, outputs and submodules from the registry, and
|
||||
says whether its provider requirements admit the version the bundle pins.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import contextvars
|
||||
import json
|
||||
import logging
|
||||
import re
|
||||
from collections.abc import Mapping, Sequence
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Any
|
||||
|
||||
import httpx
|
||||
|
||||
from app.adk.runtime import ToolResult
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
REGISTRY = "https://registry.terraform.io/v1/modules"
|
||||
MODULE_TOOL = "terraform_module"
|
||||
# Whether the Execution a Specialist is running in opted into modules. Set when a
|
||||
# Specialist starts. Unset, outside an Execution, the runner's own list applies.
|
||||
MODULES_OPTED_IN: contextvars.ContextVar[bool | None] = contextvars.ContextVar(
|
||||
"terraform_modules_opted_in", default=None
|
||||
)
|
||||
NOT_OPTED_IN = (
|
||||
"Refused: this Execution writes plain resources. Published modules are used "
|
||||
"only when the Execution opts into them. Write the resources directly."
|
||||
)
|
||||
|
||||
|
||||
def allowed_namespaces(configured: Sequence[str]) -> tuple[str, ...]:
|
||||
"""The namespaces a module may come from, here and now: none when the Execution
|
||||
did not opt in."""
|
||||
return () if MODULES_OPTED_IN.get() is False else tuple(configured)
|
||||
|
||||
|
||||
_MODULE = re.compile(r'^\s*module\s+"([^"]+)"\s*\{', re.MULTILINE)
|
||||
_SOURCE = re.compile(r'^\s*source\s*=\s*"([^"]*)"', re.MULTILINE)
|
||||
_VERSION = re.compile(r'^\s*version\s*=\s*"([^"]*)"', re.MULTILINE)
|
||||
_EXACT = re.compile(r"^\d+\.\d+\.\d+$")
|
||||
# namespace/name/provider, with an optional //path/to/submodule
|
||||
_REGISTRY_SOURCE = re.compile(
|
||||
r"^([A-Za-z0-9_-]+)/([A-Za-z0-9_-]+)/([a-z0-9]+)(?://([\w./-]+))?$"
|
||||
)
|
||||
_MAX_INPUTS = 80
|
||||
_DESCRIPTION = 140
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class ModuleCall:
|
||||
name: str
|
||||
source: str
|
||||
version: str
|
||||
|
||||
|
||||
def module_calls(files: Mapping[str, str]) -> list[ModuleCall]:
|
||||
"""Every `module` block in the files, with the source and version it names."""
|
||||
calls = []
|
||||
for text in files.values():
|
||||
for match in _MODULE.finditer(text):
|
||||
body = _block(text, match.end())
|
||||
source = _SOURCE.search(body)
|
||||
version = _VERSION.search(body)
|
||||
calls.append(
|
||||
ModuleCall(
|
||||
match.group(1),
|
||||
source.group(1) if source else "",
|
||||
version.group(1) if version else "",
|
||||
)
|
||||
)
|
||||
return calls
|
||||
|
||||
|
||||
def _block(text: str, start: int) -> str:
|
||||
"""The text of a block whose opening brace ends at `start`, nested blocks
|
||||
removed, so only its own arguments are read."""
|
||||
depth, own, index = 1, [], start
|
||||
while index < len(text) and depth:
|
||||
char = text[index]
|
||||
if char == "{":
|
||||
depth += 1
|
||||
elif char == "}":
|
||||
depth -= 1
|
||||
elif depth == 1:
|
||||
own.append(char)
|
||||
index += 1
|
||||
return "".join(own)
|
||||
|
||||
|
||||
def check_module_sources(
|
||||
files: Mapping[str, str], namespaces: Sequence[str]
|
||||
) -> ToolResult | None:
|
||||
"""Refuse a module that is not from an allowed registry namespace at one exact
|
||||
version. None when every module call is acceptable, or there are none."""
|
||||
if any(
|
||||
name.endswith(".tf.json") and '"module"' in text for name, text in files.items()
|
||||
):
|
||||
return ToolResult("Refused: write module calls in .tf files, not .tf.json.")
|
||||
calls = module_calls(files)
|
||||
if calls and MODULES_OPTED_IN.get() is False:
|
||||
return ToolResult(NOT_OPTED_IN)
|
||||
problems = []
|
||||
for call in calls:
|
||||
parsed = _REGISTRY_SOURCE.match(call.source)
|
||||
if not parsed or parsed.group(1) not in namespaces:
|
||||
allowed = ", ".join(namespaces) or "none are configured"
|
||||
problems.append(
|
||||
f'module "{call.name}": source "{call.source}" is not allowed. A '
|
||||
"module comes only from these registry namespaces, as "
|
||||
f"<namespace>/<name>/<provider>: {allowed}"
|
||||
)
|
||||
elif not _EXACT.match(call.version):
|
||||
problems.append(
|
||||
f'module "{call.name}": set `version` to one exact version, such '
|
||||
f'as "1.2.3"; got "{call.version}"'
|
||||
)
|
||||
if problems:
|
||||
return ToolResult("Refused: " + "; ".join(problems) + ".")
|
||||
return None
|
||||
|
||||
|
||||
# --- what a module accepts --------------------------------------------------------------
|
||||
|
||||
|
||||
def admits(constraint: str, version: str) -> bool:
|
||||
"""Whether a Terraform version constraint, such as ">= 6.2, < 8", admits an
|
||||
exact version. An unreadable term is taken to admit it."""
|
||||
wanted = _numbers(version)
|
||||
for term in constraint.split(","):
|
||||
match = re.match(r"^\s*(>=|<=|>|<|=|!=|~>)?\s*v?([\d.]+)", term)
|
||||
if not match:
|
||||
continue
|
||||
operator, bound = match.group(1) or "=", _numbers(match.group(2))
|
||||
if operator == "~>":
|
||||
# ~> 3.0 admits 3.x; ~> 3.1.2 admits 3.1.x from 3.1.2.
|
||||
upper = [*bound[:-1]]
|
||||
if upper:
|
||||
upper[-1] += 1
|
||||
ok = wanted >= bound and (not upper or wanted < upper)
|
||||
else:
|
||||
ok = {
|
||||
">=": wanted >= bound,
|
||||
"<=": wanted <= bound,
|
||||
">": wanted > bound,
|
||||
"<": wanted < bound,
|
||||
"=": wanted[: len(bound)] == bound,
|
||||
"!=": wanted[: len(bound)] != bound,
|
||||
}[operator]
|
||||
if not ok:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def _numbers(version: str) -> list[int]:
|
||||
return [int(part) for part in version.split(".") if part.isdigit()]
|
||||
|
||||
|
||||
@dataclass
|
||||
class ModuleLookup:
|
||||
"""Reads a module's inputs and outputs from the registry."""
|
||||
|
||||
namespaces: tuple[str, ...] = ()
|
||||
# The provider versions generated code is pinned to: {local name: version}.
|
||||
pinned: Mapping[str, str] = field(default_factory=dict)
|
||||
timeout_seconds: float = 20
|
||||
_cache: dict[str, dict[str, Any]] = field(default_factory=dict, repr=False)
|
||||
|
||||
async def describe(
|
||||
self, source: str = "", version: str = "", find: str = ""
|
||||
) -> ToolResult:
|
||||
parsed = _REGISTRY_SOURCE.match(source.strip())
|
||||
if not parsed or parsed.group(1) not in self.namespaces:
|
||||
allowed = ", ".join(self.namespaces) or "none are configured"
|
||||
return ToolResult(
|
||||
f'Refused: "{source}" is not a module from an allowed registry '
|
||||
f"namespace. Give <namespace>/<name>/<provider>, optionally with "
|
||||
f"//modules/<submodule>. Allowed namespaces: {allowed}."
|
||||
)
|
||||
namespace, name, provider, path = parsed.groups()
|
||||
if version and not _EXACT.match(version):
|
||||
return ToolResult(
|
||||
'Refused: `version` is one exact version, such as "1.2.3".'
|
||||
)
|
||||
data = await self._fetch(f"{namespace}/{name}/{provider}", version)
|
||||
if isinstance(data, ToolResult):
|
||||
return data
|
||||
part = data.get("root") or {}
|
||||
if path:
|
||||
wanted = path.strip("/")
|
||||
part = next(
|
||||
(
|
||||
item
|
||||
for item in data.get("submodules") or []
|
||||
if item.get("path", "").strip("/") == wanted
|
||||
),
|
||||
None,
|
||||
)
|
||||
if part is None:
|
||||
listed = ", ".join(
|
||||
item.get("path", "") for item in data.get("submodules") or []
|
||||
)
|
||||
return ToolResult(
|
||||
f"{namespace}/{name}/{provider} {data.get('version')} has no "
|
||||
f"submodule at {path}. Its submodules: {listed or 'none'}."
|
||||
)
|
||||
return ToolResult(self._render(data, part, source, find))
|
||||
|
||||
async def _fetch(self, module: str, version: str) -> dict[str, Any] | ToolResult:
|
||||
key = f"{module}/{version}" if version else module
|
||||
if key in self._cache:
|
||||
return self._cache[key]
|
||||
try:
|
||||
async with httpx.AsyncClient(timeout=self.timeout_seconds) as client:
|
||||
response = await client.get(f"{REGISTRY}/{key}")
|
||||
except httpx.HTTPError as exc:
|
||||
return ToolResult(
|
||||
f"The module registry could not be reached ({type(exc).__name__}). "
|
||||
"Write the resources directly, from the patterns and the schema."
|
||||
)
|
||||
if response.status_code == 404:
|
||||
return ToolResult(f"The registry has no module {module} {version}.".strip())
|
||||
if response.status_code != 200:
|
||||
return ToolResult(
|
||||
f"The module registry answered {response.status_code} for {module}."
|
||||
)
|
||||
try:
|
||||
data = response.json()
|
||||
except json.JSONDecodeError:
|
||||
return ToolResult(f"The registry's answer for {module} was not readable.")
|
||||
self._cache[key] = data
|
||||
return data
|
||||
|
||||
def _render(
|
||||
self,
|
||||
data: Mapping[str, Any],
|
||||
part: Mapping[str, Any],
|
||||
source: str,
|
||||
find: str,
|
||||
) -> str:
|
||||
version = data.get("version", "")
|
||||
lines = [f'{source} version "{version}"']
|
||||
for dependency in part.get("provider_dependencies") or []:
|
||||
name, constraint = dependency.get("name", ""), dependency.get("version", "")
|
||||
pin = self.pinned.get(name)
|
||||
if pin and constraint and not admits(constraint, pin):
|
||||
lines.append(
|
||||
f"NOT USABLE: it requires {name} {constraint}, and the code is "
|
||||
f"pinned to {name} {pin}. Write the resources directly."
|
||||
)
|
||||
elif not pin and name:
|
||||
lines.append(
|
||||
f"It also uses the {name} provider ({constraint or 'any version'});"
|
||||
" Terraform installs it."
|
||||
)
|
||||
inputs = sorted(
|
||||
part.get("inputs") or [],
|
||||
key=lambda item: (not item.get("required"), item.get("name", "")),
|
||||
)
|
||||
if find:
|
||||
wanted = [word.strip().lower() for word in find.split(",") if word.strip()]
|
||||
inputs = [
|
||||
item
|
||||
for item in inputs
|
||||
if any(
|
||||
word
|
||||
in f"{item.get('name', '')} {item.get('description', '')}".lower()
|
||||
for word in wanted
|
||||
)
|
||||
]
|
||||
lines.append(f"Inputs matching {find}: {len(inputs) or 'none'}")
|
||||
else:
|
||||
lines.append(f"Inputs ({len(inputs)}; required first):")
|
||||
for item in inputs[:_MAX_INPUTS]:
|
||||
need = "required" if item.get("required") else "optional"
|
||||
kind = " ".join(str(item.get("type", "")).split())[:60]
|
||||
about = " ".join(str(item.get("description", "")).split())[:_DESCRIPTION]
|
||||
lines.append(f"- {item.get('name')} ({need}, {kind}): {about}")
|
||||
if len(inputs) > _MAX_INPUTS:
|
||||
lines.append(f"[{len(inputs) - _MAX_INPUTS} more; use `find`]")
|
||||
outputs = [item.get("name", "") for item in part.get("outputs") or []]
|
||||
if outputs and not find:
|
||||
lines.append("Outputs: " + ", ".join(outputs))
|
||||
submodules = [item.get("path", "") for item in data.get("submodules") or []]
|
||||
if submodules and not find:
|
||||
lines.append("Submodules: " + ", ".join(submodules))
|
||||
return "\n".join(lines)
|
||||
@@ -468,5 +468,78 @@
|
||||
"require": "\"?cost[-_]centre\"?\\s*="
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "case-07-approved-modules",
|
||||
"name": "Internal booking web application, with published Terraform modules opted into",
|
||||
"workflow_request": "Design an internal web application on Google Cloud for staff to book meeting rooms and equipment, backed by a managed relational database, available only to employees signed in with the corporate identity provider, with application secrets kept out of code and configuration.",
|
||||
"required_products": [
|
||||
"Cloud Run",
|
||||
"Cloud SQL",
|
||||
"Secret Manager"
|
||||
],
|
||||
"scripted_answers": [
|
||||
[
|
||||
"region|location|geograph",
|
||||
"A single region, europe-west1 (Belgium). All users are in the EU."
|
||||
],
|
||||
[
|
||||
"user|staff|employee|how many|concurren|traffic|volume|scale|peak|requests per|rps",
|
||||
"About 4,000 employees; 300 concurrent users at the 09:00 peak, around 20 requests per second."
|
||||
],
|
||||
[
|
||||
"availability|uptime|sla|rto|rpo|disaster|recover|backup",
|
||||
"99.5% during business hours (07:00-19:00 CET). RTO 4 hours, RPO 1 hour. Daily backups kept 14 days."
|
||||
],
|
||||
[
|
||||
"latency|response time|performance",
|
||||
"Pages should load within 1 second at p95."
|
||||
],
|
||||
[
|
||||
"identity|sign.?in|login|sso|auth|idp|access",
|
||||
"Employees sign in with Google Workspace accounts; no access from outside the company. Admins are a Google group."
|
||||
],
|
||||
[
|
||||
"security|compliance|encrypt|privacy|gdpr|secret|credential|password",
|
||||
"GDPR applies to employee names and emails. Google-managed keys are fine. Database passwords and API keys must live in a secrets store and rotate every 90 days."
|
||||
],
|
||||
[
|
||||
"data|database|schema|relational|postgres|mysql|size|storage",
|
||||
"PostgreSQL. Under 20 GB of data in the first three years; bookings, rooms, equipment and audit history."
|
||||
],
|
||||
[
|
||||
"cost|budget|spend",
|
||||
"Under 600 EUR a month; the database can be small."
|
||||
],
|
||||
[
|
||||
"current|existing|today|on-prem|migrat|legacy",
|
||||
"Bookings are kept in a shared spreadsheet today; there is no data to migrate."
|
||||
],
|
||||
[
|
||||
"depend|integrat|calendar|email|notif|downstream|upstream",
|
||||
"Send booking confirmation emails through the existing SMTP relay; no calendar integration in phase one."
|
||||
],
|
||||
[
|
||||
"operat|monitor|logging|alert|team|support|deploy|ci|pipeline",
|
||||
"Two developers own it, deploy containers from Cloud Build with Terraform, and want Cloud Monitoring alerts to a Google Chat space."
|
||||
],
|
||||
[
|
||||
"network|vpc|private|internet|egress|ingress",
|
||||
"No public database endpoint; the database must use private IP only."
|
||||
],
|
||||
[
|
||||
"sustainab|carbon",
|
||||
"No specific requirement."
|
||||
],
|
||||
[
|
||||
"retention|audit|archive|delete",
|
||||
"Keep booking history 2 years, then delete; keep audit logs 1 year."
|
||||
],
|
||||
[
|
||||
"approve|confirm|proceed|look right|any changes|happy",
|
||||
"Approved. Please proceed."
|
||||
]
|
||||
],
|
||||
"terraform_modules": true
|
||||
}
|
||||
]
|
||||
|
||||
@@ -71,6 +71,8 @@ class CaseSpec:
|
||||
change: str = ""
|
||||
# Overlay Skills the case's Executions name (ADR-0004).
|
||||
overlay_skills: tuple[str, ...] = ()
|
||||
# Whether the case's Executions opt into published Terraform modules.
|
||||
terraform_modules: bool = False
|
||||
# What the infrastructure code must and must not contain, as regular
|
||||
# expressions over all of it: how a case checks that standards from an overlay
|
||||
# Skill reached the code. Each is {"name", "require"} or {"name", "forbid"}.
|
||||
@@ -118,6 +120,7 @@ def load_cases(path: Path) -> list[CaseSpec]:
|
||||
thresholds=dict(item.get("thresholds", {})),
|
||||
change=str(item.get("change", "")),
|
||||
overlay_skills=tuple(item.get("overlay_skills", ())),
|
||||
terraform_modules=bool(item.get("terraform_modules", False)),
|
||||
code_standards=tuple(item.get("code_standards", ())),
|
||||
)
|
||||
for item in json.loads(path.read_text(encoding="utf-8"))
|
||||
|
||||
@@ -132,6 +132,7 @@ async def run_with_scripted_user(
|
||||
allow_cloud_read=False,
|
||||
execution_id=execution_id,
|
||||
overlay_skills=case.overlay_skills,
|
||||
terraform_modules=case.terraform_modules,
|
||||
)
|
||||
for _ in range(max_user_turns):
|
||||
if interaction.status != "awaiting_user" or interaction.prompt is None:
|
||||
@@ -194,6 +195,7 @@ async def run_case(
|
||||
execution_id=f"{execution_id}-base",
|
||||
scripted_answers=case.scripted_answers,
|
||||
overlay_skills=case.overlay_skills,
|
||||
terraform_modules=case.terraform_modules,
|
||||
)
|
||||
baseline_tokens = token_report(adk_runtime.usage)["total"].get("total")
|
||||
baseline_seconds = round(time.monotonic() - started, 1)
|
||||
@@ -208,6 +210,7 @@ async def run_case(
|
||||
execution_id=execution_id,
|
||||
scripted_answers=case.scripted_answers,
|
||||
overlay_skills=case.overlay_skills,
|
||||
terraform_modules=case.terraform_modules,
|
||||
baseline=base.execution_id,
|
||||
)
|
||||
elif case.interactive:
|
||||
@@ -223,6 +226,7 @@ async def run_case(
|
||||
execution_id=execution_id,
|
||||
scripted_answers=case.scripted_answers,
|
||||
overlay_skills=case.overlay_skills,
|
||||
terraform_modules=case.terraform_modules,
|
||||
)
|
||||
elapsed = time.monotonic() - started
|
||||
write_progress()
|
||||
@@ -237,6 +241,9 @@ async def run_case(
|
||||
binary=settings.TERRAFORM_BINARY,
|
||||
timeout_seconds=settings.TERRAFORM_TIMEOUT_SECONDS,
|
||||
plugin_cache_dir=settings.terraform_plugin_cache(),
|
||||
module_namespaces=bundle.terraform_module_namespaces
|
||||
if case.terraform_modules
|
||||
else (),
|
||||
)
|
||||
result = await score_execution(
|
||||
case,
|
||||
|
||||
@@ -64,7 +64,7 @@ pillar_skills:
|
||||
sustainability: google-cloud-waf-sustainability
|
||||
|
||||
tools:
|
||||
general: [mermaid_check, terraform_fmt, terraform_validate, terraform_schema]
|
||||
general: [mermaid_check, terraform_fmt, terraform_validate, terraform_schema, terraform_module]
|
||||
cloud_read: [terraform_plan]
|
||||
|
||||
# The Terraform providers generated code is written for. One exact version, so the
|
||||
@@ -75,6 +75,15 @@ terraform:
|
||||
google:
|
||||
source: hashicorp/google
|
||||
version: 8.6.0
|
||||
# Published modules. Generated code is plain resources unless an Execution opts
|
||||
# into modules; then a `module` may come only from these registry namespaces, at
|
||||
# one exact version. `terraform init` downloads and evaluates whatever a source
|
||||
# names, so anything else is refused before Terraform runs. `skill` holds the
|
||||
# modules known to work with the provider pinned above, and is given, with the
|
||||
# terraform_module tool, only to an Execution that opted in.
|
||||
modules:
|
||||
namespaces: [terraform-google-modules]
|
||||
skill: google-cloud-iac-modules
|
||||
|
||||
mcp_auth:
|
||||
kind: google_adc # Application Default Credentials bearer token; sends X-Goog-User-Project
|
||||
|
||||
55
skills/google-cloud-iac-modules/SKILL.md
Normal file
55
skills/google-cloud-iac-modules/SKILL.md
Normal file
@@ -0,0 +1,55 @@
|
||||
---
|
||||
name: google-cloud-iac-modules
|
||||
description: >-
|
||||
Published Terraform modules from the terraform-google-modules organisation
|
||||
that are known to validate against the pinned hashicorp/google provider: VPC
|
||||
network with Cloud NAT, private Cloud SQL for PostgreSQL, Cloud Storage
|
||||
buckets and Cloud KMS. Use when writing Terraform for an Element that one of
|
||||
these modules covers, to decide whether a module or plain resources fit and to
|
||||
call the module correctly.
|
||||
metadata:
|
||||
scope: deployment guidance, validation results
|
||||
provider: hashicorp/google 8.6.0
|
||||
modules: terraform-google-modules
|
||||
---
|
||||
|
||||
# Google Cloud IaC modules
|
||||
|
||||
You have this Skill because this Execution opted into published modules: `terraform_modules` is true in your context. Without that, infrastructure code is plain resources and a module call is refused.
|
||||
|
||||
A published module replaces several resources that must be wired together with one call that a team already maintains. It also hides the resources a Check is about. Use one only where the first outweighs the second.
|
||||
|
||||
## When to use a module
|
||||
|
||||
Use a module when **all** of these hold:
|
||||
|
||||
1. It is in the table below. Those are the only modules checked against `hashicorp/google` 8.6.0; a test validates each one's example here.
|
||||
2. It replaces three or more resources that depend on each other, such as a network with its subnets and firewall rules, or a private database with the peering it needs.
|
||||
3. Every Check on the Elements it covers can be met through one of its inputs. Confirm with `terraform_module`.
|
||||
|
||||
Otherwise write the resources directly, from the patterns Skill. A single resource, such as one service account, one topic or one secret, is always written directly.
|
||||
|
||||
| For | Module | Version | Reference |
|
||||
| --- | --- | --- | --- |
|
||||
| VPC, subnets, firewall rules, and Cloud NAT | `terraform-google-modules/network/google` and `terraform-google-modules/cloud-nat/google` | 18.3.1, 7.1.0 | `references/network.md` |
|
||||
| Cloud SQL for PostgreSQL on a private address | `terraform-google-modules/sql-db/google//modules/postgresql` with `//modules/private_service_access` | 28.3.0 | `references/cloud-sql.md` |
|
||||
| A Cloud Storage bucket with retention, lifecycle, encryption and grants | `terraform-google-modules/cloud-storage/google//modules/simple_bucket` | 12.4.1 | `references/cloud-storage.md` |
|
||||
| A key ring, keys and their grants | `terraform-google-modules/kms/google` | 4.2.1 | `references/kms.md` |
|
||||
|
||||
Not usable with this provider version, so write these directly: the load balancer (`lb-http`), Pub/Sub, BigQuery, GKE, log export and the function modules all require `google` below 8. `terraform_module` says so for any module you look up.
|
||||
|
||||
## Rules for every module call
|
||||
|
||||
- `source` is `terraform-google-modules/<name>/google`, with `//modules/<submodule>` when the table gives one. `version` is one exact version. `terraform_validate` refuses any other source, a Git URL, a local path or a version range.
|
||||
- Keep `terraform/versions.tf` from the patterns Skill unchanged. A module's own provider requirements are met by it.
|
||||
- Pass every environment-specific value from a variable, as for resources.
|
||||
- Before using an input the reference does not show, call `terraform_module` with `find` set to its name.
|
||||
- A module takes names, not always ids: read which one an input wants. Pass another module's output where one depends on the other, so Terraform orders them.
|
||||
|
||||
## Checks on an Element a module creates
|
||||
|
||||
A Check is still about the resource: "the instance has no public IP address". The code meets it through a module input.
|
||||
|
||||
- In `implementation.json`, `address` names the module and the input: `module.database.ip_configuration.ipv4_enabled`.
|
||||
- When no input sets what a Check needs, the module does not fit that Element. Write its resources directly; do not mark the Check unimplementable, since the resource type does have the setting.
|
||||
- When validating, read the input's value in the code and confirm with `terraform_module` what that input sets. An input left at its default is judged by the default the lookup shows. A Check is not verifiable only when neither the code nor the module's documentation shows what the resource will get.
|
||||
102
skills/google-cloud-iac-modules/references/cloud-sql.md
Normal file
102
skills/google-cloud-iac-modules/references/cloud-sql.md
Normal file
@@ -0,0 +1,102 @@
|
||||
# Cloud SQL for PostgreSQL on a private address
|
||||
|
||||
A PostgreSQL instance reachable only inside a VPC, with the private services access it needs. Replaces a reserved range, a service networking connection, the instance, its database and its user.
|
||||
|
||||
- The instance must wait for the peering: pass `module.private_access.peering_completed` in `module_depends_on`.
|
||||
- `ip_configuration.ipv4_enabled = false` is what removes the public address. `private_network` is the network's self link.
|
||||
- `availability_type = "REGIONAL"` gives a standby in a second zone.
|
||||
- `deletion_protection` is the Terraform guard; `deletion_protection_enabled` is the guard in the API. Set both from a variable.
|
||||
- With `enable_default_user = true` the module generates a password and exposes it as an output. Prefer IAM database authentication: set `enable_default_user = false`, add the `cloudsql.iam_authentication` flag and list `iam_users`.
|
||||
- `random_instance_name = true` adds a suffix, which lets an instance be recreated: a deleted instance's name is reserved for a week.
|
||||
|
||||
```hcl
|
||||
variable "project_id" {
|
||||
type = string
|
||||
description = "Project to deploy into."
|
||||
}
|
||||
|
||||
variable "region" {
|
||||
type = string
|
||||
description = "Region for regional resources."
|
||||
}
|
||||
|
||||
variable "network_name" {
|
||||
type = string
|
||||
description = "Name of the VPC the database is reached from."
|
||||
}
|
||||
|
||||
variable "network_self_link" {
|
||||
type = string
|
||||
description = "Self link of that VPC."
|
||||
}
|
||||
|
||||
variable "app_service_account_email" {
|
||||
type = string
|
||||
description = "Service account that connects to the database."
|
||||
}
|
||||
|
||||
variable "deletion_protection" {
|
||||
type = bool
|
||||
description = "Whether the instance is protected from deletion."
|
||||
default = true
|
||||
}
|
||||
|
||||
module "private_access" {
|
||||
source = "terraform-google-modules/sql-db/google//modules/private_service_access"
|
||||
version = "28.3.0"
|
||||
|
||||
project_id = var.project_id
|
||||
vpc_network = var.network_name
|
||||
prefix_length = 20
|
||||
}
|
||||
|
||||
module "database" {
|
||||
source = "terraform-google-modules/sql-db/google//modules/postgresql"
|
||||
version = "28.3.0"
|
||||
|
||||
project_id = var.project_id
|
||||
region = var.region
|
||||
name = "workload"
|
||||
random_instance_name = true
|
||||
database_version = "POSTGRES_16"
|
||||
edition = "ENTERPRISE"
|
||||
tier = "db-custom-2-7680"
|
||||
availability_type = "REGIONAL"
|
||||
disk_autoresize = true
|
||||
|
||||
deletion_protection = var.deletion_protection
|
||||
deletion_protection_enabled = var.deletion_protection
|
||||
|
||||
ip_configuration = {
|
||||
ipv4_enabled = false
|
||||
private_network = var.network_self_link
|
||||
ssl_mode = "ENCRYPTED_ONLY"
|
||||
}
|
||||
|
||||
backup_configuration = {
|
||||
enabled = true
|
||||
start_time = "02:00"
|
||||
point_in_time_recovery_enabled = true
|
||||
retained_backups = 14
|
||||
retention_unit = "COUNT"
|
||||
}
|
||||
|
||||
database_flags = [
|
||||
{
|
||||
name = "cloudsql.iam_authentication"
|
||||
value = "on"
|
||||
}
|
||||
]
|
||||
|
||||
db_name = "app"
|
||||
enable_default_user = false
|
||||
iam_users = [
|
||||
{
|
||||
id = "app"
|
||||
email = var.app_service_account_email
|
||||
}
|
||||
]
|
||||
|
||||
module_depends_on = [module.private_access.peering_completed]
|
||||
}
|
||||
```
|
||||
68
skills/google-cloud-iac-modules/references/cloud-storage.md
Normal file
68
skills/google-cloud-iac-modules/references/cloud-storage.md
Normal file
@@ -0,0 +1,68 @@
|
||||
# Cloud Storage bucket
|
||||
|
||||
One bucket with its retention, lifecycle rules, encryption and grants. Use the module when the bucket has several of those; a plain bucket is one resource and is written directly.
|
||||
|
||||
- The module turns on uniform bucket-level access (`bucket_policy_only`) and `public_access_prevention = "enforced"` unless told otherwise.
|
||||
- `retention_policy.retention_period` is in seconds. `is_locked = true` cannot be undone, and the bucket cannot then be deleted until every object has aged out: take it from a variable.
|
||||
- `lifecycle_rules` takes `action` and `condition` as maps; condition values that are lists are given as comma-separated strings.
|
||||
- `encryption.default_kms_key_name` needs the Cloud Storage service agent to hold the encrypter/decrypter role on the key first.
|
||||
- `iam_members` grants on the bucket only, with `_iam_member`, so grants made elsewhere are kept.
|
||||
|
||||
```hcl
|
||||
variable "project_id" {
|
||||
type = string
|
||||
description = "Project to deploy into."
|
||||
}
|
||||
|
||||
variable "region" {
|
||||
type = string
|
||||
description = "Region for regional resources."
|
||||
}
|
||||
|
||||
variable "lock_retention" {
|
||||
type = bool
|
||||
description = "Whether the retention policy is locked. Locking cannot be undone."
|
||||
default = false
|
||||
}
|
||||
|
||||
variable "reader_service_account_email" {
|
||||
type = string
|
||||
description = "Service account that reads the archive."
|
||||
}
|
||||
|
||||
module "archive" {
|
||||
source = "terraform-google-modules/cloud-storage/google//modules/simple_bucket"
|
||||
version = "12.4.1"
|
||||
|
||||
project_id = var.project_id
|
||||
name = "${var.project_id}-archive"
|
||||
location = var.region
|
||||
storage_class = "STANDARD"
|
||||
versioning = true
|
||||
force_destroy = false
|
||||
|
||||
retention_policy = {
|
||||
is_locked = var.lock_retention
|
||||
retention_period = 220752000
|
||||
}
|
||||
|
||||
lifecycle_rules = [
|
||||
{
|
||||
action = {
|
||||
type = "SetStorageClass"
|
||||
storage_class = "ARCHIVE"
|
||||
}
|
||||
condition = {
|
||||
age = 365
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
iam_members = [
|
||||
{
|
||||
role = "roles/storage.objectViewer"
|
||||
member = "serviceAccount:${var.reader_service_account_email}"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
54
skills/google-cloud-iac-modules/references/kms.md
Normal file
54
skills/google-cloud-iac-modules/references/kms.md
Normal file
@@ -0,0 +1,54 @@
|
||||
# Cloud KMS key ring and keys
|
||||
|
||||
A key ring, its keys and the grants that let products use them. Replaces a key ring, each key and each grant.
|
||||
|
||||
- The key ring's `location` must match the resource it protects.
|
||||
- `prevent_destroy` is true unless set otherwise; keys and key rings cannot be deleted from Google Cloud in any case.
|
||||
- `key_rotation_period` is in seconds with an `s`, such as `"7776000s"` for 90 days.
|
||||
- `set_encrypters_for` and `set_decrypters_for` name the keys; `encrypters` and `decrypters` give one comma-separated string of members per key, in the same order.
|
||||
- The member is the product's service agent, not the workload's service account.
|
||||
- `module.kms.keys` is a map from key name to key id.
|
||||
|
||||
```hcl
|
||||
variable "project_id" {
|
||||
type = string
|
||||
description = "Project to deploy into."
|
||||
}
|
||||
|
||||
variable "region" {
|
||||
type = string
|
||||
description = "Region for regional resources."
|
||||
}
|
||||
|
||||
data "google_storage_project_service_account" "this" {
|
||||
project = var.project_id
|
||||
}
|
||||
|
||||
module "kms" {
|
||||
source = "terraform-google-modules/kms/google"
|
||||
version = "4.2.1"
|
||||
|
||||
project_id = var.project_id
|
||||
location = var.region
|
||||
keyring = "workload"
|
||||
keys = ["data"]
|
||||
key_rotation_period = "7776000s"
|
||||
prevent_destroy = true
|
||||
|
||||
set_encrypters_for = ["data"]
|
||||
set_decrypters_for = ["data"]
|
||||
encrypters = ["serviceAccount:${data.google_storage_project_service_account.this.email_address}"]
|
||||
decrypters = ["serviceAccount:${data.google_storage_project_service_account.this.email_address}"]
|
||||
}
|
||||
|
||||
resource "google_storage_bucket" "encrypted" {
|
||||
project = var.project_id
|
||||
name = "${var.project_id}-encrypted"
|
||||
location = var.region
|
||||
uniform_bucket_level_access = true
|
||||
|
||||
encryption {
|
||||
default_kms_key_name = module.kms.keys["data"]
|
||||
}
|
||||
}
|
||||
```
|
||||
68
skills/google-cloud-iac-modules/references/network.md
Normal file
68
skills/google-cloud-iac-modules/references/network.md
Normal file
@@ -0,0 +1,68 @@
|
||||
# VPC network and Cloud NAT
|
||||
|
||||
A custom-mode VPC with its subnets and firewall rules, and outbound internet through Cloud NAT. Replaces a network, its subnetworks, a router, a NAT and each firewall rule.
|
||||
|
||||
- `subnets` is a list of objects whose values are all strings, including `"true"` for `subnet_private_access`.
|
||||
- `network_name` is a name. Other resources want `module.network.network_self_link` or `network_id`; `subnets` is an output map keyed `"<region>/<subnet_name>"`.
|
||||
- `ingress_rules` replaces the deprecated `firewall_rules`.
|
||||
- The NAT module creates its router when `create_router = true`, and then needs `network`.
|
||||
- Set `name` on the NAT. Left unset it gets a random suffix.
|
||||
|
||||
```hcl
|
||||
variable "project_id" {
|
||||
type = string
|
||||
description = "Project to deploy into."
|
||||
}
|
||||
|
||||
variable "region" {
|
||||
type = string
|
||||
description = "Region for regional resources."
|
||||
}
|
||||
|
||||
module "network" {
|
||||
source = "terraform-google-modules/network/google"
|
||||
version = "18.3.1"
|
||||
|
||||
project_id = var.project_id
|
||||
network_name = "workload"
|
||||
routing_mode = "REGIONAL"
|
||||
|
||||
subnets = [
|
||||
{
|
||||
subnet_name = "workload"
|
||||
subnet_ip = "10.10.0.0/24"
|
||||
subnet_region = var.region
|
||||
subnet_private_access = "true"
|
||||
subnet_flow_logs = "true"
|
||||
}
|
||||
]
|
||||
|
||||
ingress_rules = [
|
||||
{
|
||||
name = "allow-health-checks"
|
||||
source_ranges = ["130.211.0.0/22", "35.191.0.0/16"]
|
||||
allow = [
|
||||
{
|
||||
protocol = "tcp"
|
||||
ports = ["8080"]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
module "nat" {
|
||||
source = "terraform-google-modules/cloud-nat/google"
|
||||
version = "7.1.0"
|
||||
|
||||
project_id = var.project_id
|
||||
region = var.region
|
||||
name = "workload-nat"
|
||||
create_router = true
|
||||
router = "workload-router"
|
||||
network = module.network.network_self_link
|
||||
|
||||
log_config_enable = true
|
||||
log_config_filter = "ERRORS_ONLY"
|
||||
}
|
||||
```
|
||||
@@ -22,11 +22,14 @@ The files are your working copy: the files you wrote with `write_file`, or, when
|
||||
- `terraform_plan(variables)`: previews the changes against the live cloud environment. It reads live state, so the first call may pause for the user's permission. Pass every variable the configuration requires.
|
||||
- `terraform_schema(resource_type, block, find, resource_types)`: what a resource type accepts, from the provider's own schema. With `resource_types`, a list, it outlines every argument and block of each in one call; use that when you need several. With `resource_type` alone it lists the top-level arguments and outlines every block. With `block`, such as `template.containers`, it gives that block's arguments in full. With `find`, it says where an argument or block of that name sits, or that the resource type has none; give several names separated by commas to check them in one call.
|
||||
|
||||
- `terraform_module(source, version, find)`, only when the Execution opted into published modules: what a published module accepts, from the registry: its inputs with their types, its outputs and its submodules. It says when a module cannot be used with the pinned provider. `find` narrows the inputs to those matching the words given. Only modules from the namespaces the Cloud provider allows can be looked up or used.
|
||||
|
||||
## When writing deployment guidance
|
||||
|
||||
1. Run `terraform_fmt`, then `terraform_validate`.
|
||||
2. Fix each error with `edit_file`, changing only the lines concerned, and run `terraform_validate` again until it passes.
|
||||
3. On "An argument named X is not expected here" or "Unsupported block type", call `terraform_schema` with `find` set to the name. It is either in a different block, which the reply names, or it does not exist on that resource type. Never move it around by trial.
|
||||
3. A refusal about a module means one of two things. The Execution writes plain resources, so write them directly. Or the module is not from an approved namespace or not pinned to one exact version, so use an approved module at an exact version or write the resources directly.
|
||||
4. On "An argument named X is not expected here" or "Unsupported block type", call `terraform_schema` with `find` set to the name. It is either in a different block, which the reply names, or it does not exist on that resource type. Never move it around by trial.
|
||||
|
||||
## When validating deployment guidance
|
||||
|
||||
|
||||
@@ -117,6 +117,8 @@ One entry per Check in the Target architecture, saying where the code satisfies
|
||||
]
|
||||
```
|
||||
|
||||
When a module creates the resource, `address` is the module and the input that sets what the Check asks for, such as `module.database.ip_configuration.ipv4_enabled`.
|
||||
|
||||
When a Check names a setting its resource type does not have, give it an `unimplementable` entry in place of `file` and `address`, saying what the resource type lacks. Write no code for it. The Target architecture is revised before anything is validated.
|
||||
|
||||
Implement every Element, Relationship and Check, and nothing the Target architecture does not ask for. When you believe the Target architecture is wrong or incomplete, say so with `needs_input`; do not quietly build something else.
|
||||
|
||||
@@ -52,6 +52,7 @@ def test_roles_name_only_the_local_tools_they_need(bundle):
|
||||
"terraform_fmt",
|
||||
"terraform_validate",
|
||||
"terraform_schema",
|
||||
"terraform_module",
|
||||
)
|
||||
# The architect only looks settings up; it writes and runs no code.
|
||||
assert roles["target-architect"].tools == ("terraform_schema",)
|
||||
@@ -59,6 +60,7 @@ def test_roles_name_only_the_local_tools_they_need(bundle):
|
||||
"terraform_validate",
|
||||
"terraform_plan",
|
||||
"terraform_schema",
|
||||
"terraform_module",
|
||||
)
|
||||
assert roles["requirements-analyst"].tools == ()
|
||||
|
||||
|
||||
205
tests/execution/test_terraform_modules.py
Normal file
205
tests/execution/test_terraform_modules.py
Normal file
@@ -0,0 +1,205 @@
|
||||
"""Published Terraform modules are opt-in per Execution (iteration 8).
|
||||
|
||||
Infrastructure code is plain resources by default. An Execution that opts in is
|
||||
given the modules Skill and the module lookup, and only then is a module call from
|
||||
an approved source accepted.
|
||||
"""
|
||||
|
||||
import json
|
||||
|
||||
import pytest
|
||||
from langgraph.checkpoint.memory import InMemorySaver
|
||||
|
||||
from app.adk.fake_runtime import FakeAgentRuntime, sample_submission
|
||||
from app.adk.roles import load_roles
|
||||
from app.adk.runtime import NoDecider, RoleSpec
|
||||
from app.agent import AGENTS_DIR, ExecutionEngine
|
||||
from app.nodes.router import Router, Thresholds
|
||||
from app.providers import load_provider
|
||||
from app.recorder import InMemoryRecorder
|
||||
from app.tools.local import TerraformRunner
|
||||
from app.tools.modules import MODULE_TOOL, MODULES_OPTED_IN, NOT_OPTED_IN
|
||||
from app.workflows.deliverables import DEPENDENCY_GRAPH
|
||||
from app.workflows.deliverables import DeliverableKind as K
|
||||
|
||||
AUTHOR = DEPENDENCY_GRAPH[K.DEPLOYMENT_GUIDANCE].specialist
|
||||
CASE = "acme"
|
||||
MODULE_CALL = """
|
||||
module "network" {
|
||||
source = "approved-modules/network/cloud"
|
||||
version = "1.2.3"
|
||||
}
|
||||
"""
|
||||
ROLES = {
|
||||
"orchestrator": RoleSpec("orchestrator", "Unused.", budget=40),
|
||||
**{
|
||||
spec.specialist: RoleSpec(
|
||||
spec.specialist,
|
||||
"Produce.",
|
||||
budget=15,
|
||||
skills=("base",),
|
||||
tools=(MODULE_TOOL,) if spec.specialist == AUTHOR else (),
|
||||
modules_skill="modules-skill" if spec.specialist == AUTHOR else None,
|
||||
)
|
||||
for spec in DEPENDENCY_GRAPH.values()
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class Recording(FakeAgentRuntime):
|
||||
def __init__(self, turns):
|
||||
super().__init__(turns)
|
||||
self.seen: dict[str, dict] = {}
|
||||
|
||||
async def run(self, role, task, tools):
|
||||
self.seen[role.name] = {
|
||||
"skills": role.skills,
|
||||
"role_tools": role.tools,
|
||||
"context": task.context.get("terraform_modules"),
|
||||
"opted_in": MODULES_OPTED_IN.get(),
|
||||
}
|
||||
return await super().run(role, task, tools)
|
||||
|
||||
|
||||
def engine(tmp_path, **options) -> tuple[ExecutionEngine, Recording]:
|
||||
runtime = Recording(
|
||||
{
|
||||
spec.specialist: [[sample_submission(kind)]] * 2
|
||||
for kind, spec in DEPENDENCY_GRAPH.items()
|
||||
}
|
||||
)
|
||||
built = ExecutionEngine(
|
||||
runtime=runtime,
|
||||
roles=ROLES,
|
||||
recorder=InMemoryRecorder(),
|
||||
checkpointer=InMemorySaver(),
|
||||
output_root=tmp_path,
|
||||
orchestrator=Router(NoDecider(), None, Thresholds()),
|
||||
**options,
|
||||
)
|
||||
return built, runtime
|
||||
|
||||
|
||||
def manifest(tmp_path, execution_id: str) -> dict:
|
||||
folder = tmp_path / "deliverables" / "cases" / CASE / "executions" / execution_id
|
||||
return json.loads((folder / "execution.json").read_text())
|
||||
|
||||
|
||||
async def test_by_default_code_is_plain_resources(tmp_path):
|
||||
built, runtime = engine(tmp_path, modules_available=True)
|
||||
|
||||
await built.start("Ingest", customer_case=CASE, pre_approved=True, execution_id="a")
|
||||
|
||||
author = runtime.seen[AUTHOR]
|
||||
assert author["skills"] == ("base",)
|
||||
assert MODULE_TOOL not in author["role_tools"]
|
||||
assert author["context"] is False and author["opted_in"] is False
|
||||
assert manifest(tmp_path, "a")["terraform_modules"] is False
|
||||
|
||||
|
||||
async def test_an_execution_that_opts_in_is_given_the_skill_and_the_lookup(tmp_path):
|
||||
built, runtime = engine(tmp_path, modules_available=True)
|
||||
|
||||
await built.start(
|
||||
"Ingest",
|
||||
customer_case=CASE,
|
||||
pre_approved=True,
|
||||
execution_id="a",
|
||||
terraform_modules=True,
|
||||
)
|
||||
|
||||
author = runtime.seen[AUTHOR]
|
||||
assert author["skills"] == ("base", "modules-skill")
|
||||
assert MODULE_TOOL in author["role_tools"]
|
||||
assert author["context"] is True and author["opted_in"] is True
|
||||
# A role that writes no code is given neither.
|
||||
assert runtime.seen["requirements-analyst"]["skills"] == ("base",)
|
||||
assert manifest(tmp_path, "a")["terraform_modules"] is True
|
||||
|
||||
|
||||
async def test_the_deployment_may_make_modules_the_default(tmp_path):
|
||||
built, runtime = engine(tmp_path, modules_available=True, default_modules=True)
|
||||
|
||||
await built.start("Ingest", customer_case=CASE, pre_approved=True, execution_id="a")
|
||||
assert runtime.seen[AUTHOR]["opted_in"] is True
|
||||
|
||||
await built.start(
|
||||
"Ingest",
|
||||
customer_case=CASE,
|
||||
pre_approved=True,
|
||||
execution_id="b",
|
||||
terraform_modules=False,
|
||||
)
|
||||
assert runtime.seen[AUTHOR]["opted_in"] is False
|
||||
|
||||
|
||||
async def test_opting_in_is_refused_when_the_provider_approves_no_sources(tmp_path):
|
||||
built, runtime = engine(tmp_path)
|
||||
|
||||
with pytest.raises(ValueError, match="no approved module sources"):
|
||||
await built.start("Ingest", pre_approved=True, terraform_modules=True)
|
||||
with pytest.raises(ValueError, match="true or false"):
|
||||
await built.start("Ingest", pre_approved=True, terraform_modules="yes")
|
||||
assert runtime.seen == {}
|
||||
|
||||
|
||||
async def test_a_change_request_does_as_its_baseline_did(tmp_path):
|
||||
built, runtime = engine(tmp_path, modules_available=True)
|
||||
await built.start(
|
||||
"Ingest",
|
||||
customer_case=CASE,
|
||||
pre_approved=True,
|
||||
execution_id="v1",
|
||||
terraform_modules=True,
|
||||
)
|
||||
runtime.seen.clear()
|
||||
|
||||
# sample submissions change nothing, so the Change request ends with warnings;
|
||||
# what matters is which way it started.
|
||||
await built.start(
|
||||
"Retention changes.",
|
||||
customer_case=CASE,
|
||||
pre_approved=True,
|
||||
execution_id="v2",
|
||||
baseline="v1",
|
||||
)
|
||||
|
||||
assert built is not None
|
||||
state = (await built.interaction("v2")).state
|
||||
assert state["terraform_modules"] is True
|
||||
|
||||
|
||||
async def test_a_module_call_is_refused_unless_the_execution_opted_in():
|
||||
runner = TerraformRunner(
|
||||
binary="no-such-binary", module_namespaces=("approved-modules",)
|
||||
)
|
||||
files = {"terraform/main.tf": MODULE_CALL}
|
||||
|
||||
token = MODULES_OPTED_IN.set(False)
|
||||
try:
|
||||
assert (await runner.validate(files)).message == NOT_OPTED_IN
|
||||
# Plain resources are untouched by the switch.
|
||||
plain = await runner.validate({"terraform/main.tf": "locals {}"})
|
||||
assert not plain.message.startswith("Refused")
|
||||
finally:
|
||||
MODULES_OPTED_IN.reset(token)
|
||||
|
||||
token = MODULES_OPTED_IN.set(True)
|
||||
try:
|
||||
opted = await runner.validate(files)
|
||||
assert not opted.message.startswith("Refused")
|
||||
finally:
|
||||
MODULES_OPTED_IN.reset(token)
|
||||
|
||||
|
||||
def test_the_gcp_bundle_names_its_modules_skill_for_the_roles_that_run_terraform():
|
||||
bundle = load_provider("gcp")
|
||||
roles = load_roles(AGENTS_DIR, bundle)
|
||||
|
||||
assert bundle.terraform_module_namespaces == ("terraform-google-modules",)
|
||||
with_skill = {name for name, role in roles.items() if role.modules_skill}
|
||||
assert with_skill == {"iac-author", "validator"}
|
||||
# The Skill is not among any role's Skills until an Execution opts in.
|
||||
assert all(
|
||||
bundle.terraform_modules_skill not in role.skills for role in roles.values()
|
||||
)
|
||||
72
tests/test_iac_modules.py
Normal file
72
tests/test_iac_modules.py
Normal file
@@ -0,0 +1,72 @@
|
||||
"""The IaC modules Skill: every module call validates against the pinned provider.
|
||||
|
||||
A module is usable only with provider versions its own requirements admit, and
|
||||
several of the organisation's modules do not admit the pinned one. Each reference's
|
||||
example is run through `terraform validate`, which downloads the module, so a
|
||||
version bump that breaks one is found here. With no network the test is skipped.
|
||||
"""
|
||||
|
||||
import re
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from app.config import Settings
|
||||
from app.providers import load_provider
|
||||
from app.tools.local import TerraformRunner
|
||||
from app.tools.modules import module_calls
|
||||
|
||||
SKILL = "google-cloud-iac-modules"
|
||||
SKILLS = Path(__file__).resolve().parent.parent / "skills"
|
||||
ROOT = SKILLS / SKILL
|
||||
VERSIONS = SKILLS / "google-cloud-iac-patterns" / "assets" / "versions.tf"
|
||||
REFERENCES = sorted((ROOT / "references").glob("*.md"))
|
||||
_HCL = re.compile(r"^```hcl\n(.*?)^```", re.MULTILINE | re.DOTALL)
|
||||
|
||||
needs_terraform = pytest.mark.skipif(
|
||||
shutil.which("terraform") is None, reason="terraform CLI not installed"
|
||||
)
|
||||
|
||||
|
||||
def _code(reference: Path) -> str:
|
||||
return "\n".join(_HCL.findall(reference.read_text(encoding="utf-8")))
|
||||
|
||||
|
||||
def test_every_reference_is_listed_and_calls_only_allowed_pinned_modules():
|
||||
bundle = load_provider("gcp")
|
||||
skill = (ROOT / "SKILL.md").read_text(encoding="utf-8")
|
||||
assert REFERENCES
|
||||
listed = set(re.findall(r"references/([\w-]+\.md)", skill))
|
||||
assert listed == {reference.name for reference in REFERENCES}
|
||||
for reference in REFERENCES:
|
||||
calls = module_calls({"main.tf": _code(reference)})
|
||||
assert calls, reference.name
|
||||
for call in calls:
|
||||
assert call.source.split("/")[0] in bundle.terraform_module_namespaces
|
||||
# The version the example uses is the one the Skill's table gives.
|
||||
assert call.version in skill, f"{reference.name}: {call.version}"
|
||||
|
||||
|
||||
def test_the_skill_names_the_provider_version_the_bundle_pins():
|
||||
pin = load_provider("gcp").terraform_providers["google"]
|
||||
skill = (ROOT / "SKILL.md").read_text(encoding="utf-8")
|
||||
assert f"{pin['source']} {pin['version']}" in skill
|
||||
|
||||
|
||||
@needs_terraform
|
||||
@pytest.mark.parametrize("reference", REFERENCES, ids=lambda path: path.stem)
|
||||
async def test_module_example_validates(reference: Path):
|
||||
bundle = load_provider("gcp")
|
||||
runner = TerraformRunner(
|
||||
plugin_cache_dir=Settings().terraform_plugin_cache(),
|
||||
module_namespaces=bundle.terraform_module_namespaces,
|
||||
)
|
||||
files = {
|
||||
"terraform/versions.tf": VERSIONS.read_text(),
|
||||
"terraform/main.tf": _code(reference),
|
||||
}
|
||||
result = await runner.validate(files)
|
||||
if result.message.startswith("terraform init failed"):
|
||||
pytest.skip("the module or the pinned provider could not be downloaded")
|
||||
assert result.message.startswith("terraform validate passed"), result.message
|
||||
@@ -294,6 +294,7 @@ def test_local_tools_are_built_by_name_with_their_tier():
|
||||
"terraform_validate",
|
||||
"terraform_plan",
|
||||
"terraform_schema",
|
||||
"terraform_module",
|
||||
}
|
||||
with pytest.raises(KeyError, match="terraform_apply"):
|
||||
local_tools(["terraform_apply"], TerraformRunner())
|
||||
|
||||
203
tests/tools/test_modules.py
Normal file
203
tests/tools/test_modules.py
Normal file
@@ -0,0 +1,203 @@
|
||||
"""Terraform modules: which may be used, and what one accepts (iteration 8)."""
|
||||
|
||||
import httpx
|
||||
import pytest
|
||||
|
||||
from app.tools import modules
|
||||
from app.tools.local import TerraformRunner
|
||||
from app.tools.modules import ModuleLookup, admits, check_module_sources, module_calls
|
||||
|
||||
ALLOWED = ("example-modules",)
|
||||
GOOD = """
|
||||
module "network" {
|
||||
source = "example-modules/network/cloud"
|
||||
version = "1.2.3"
|
||||
|
||||
subnets = [
|
||||
{
|
||||
source = "not the module's source"
|
||||
version = "nor its version"
|
||||
}
|
||||
]
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
def refused(code: str, allowed=ALLOWED) -> str:
|
||||
result = check_module_sources({"terraform/main.tf": code}, allowed)
|
||||
return result.message if result else ""
|
||||
|
||||
|
||||
def test_a_module_call_is_read_with_its_own_source_and_version():
|
||||
(call,) = module_calls({"main.tf": GOOD})
|
||||
|
||||
assert (call.name, call.source, call.version) == (
|
||||
"network",
|
||||
"example-modules/network/cloud",
|
||||
"1.2.3",
|
||||
)
|
||||
|
||||
|
||||
def test_a_module_from_an_allowed_namespace_at_an_exact_version_is_accepted():
|
||||
assert refused(GOOD) == ""
|
||||
assert refused(GOOD.replace("network/cloud", "network/cloud//modules/nat")) == ""
|
||||
assert refused('resource "thing" "x" {}') == ""
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"source",
|
||||
[
|
||||
"someone-else/network/cloud",
|
||||
"git::https://example.com/network.git",
|
||||
"github.com/example-modules/network",
|
||||
"./modules/network",
|
||||
"../shared",
|
||||
"https://example.com/network.zip",
|
||||
"",
|
||||
],
|
||||
)
|
||||
def test_any_other_source_is_refused(source):
|
||||
message = refused(GOOD.replace("example-modules/network/cloud", source))
|
||||
|
||||
assert message.startswith("Refused") and "example-modules" in message
|
||||
|
||||
|
||||
@pytest.mark.parametrize("version", ["~> 1.2", ">= 1.0", "1.2", "latest", ""])
|
||||
def test_a_version_that_is_not_exact_is_refused(version):
|
||||
assert "one exact version" in refused(GOOD.replace("1.2.3", version))
|
||||
|
||||
|
||||
def test_with_no_namespace_configured_every_module_is_refused():
|
||||
assert "none are configured" in refused(GOOD, allowed=())
|
||||
|
||||
|
||||
def test_a_module_in_json_syntax_is_refused():
|
||||
result = check_module_sources(
|
||||
{"terraform/main.tf.json": '{"module": {"x": {"source": "a/b/c"}}}'}, ALLOWED
|
||||
)
|
||||
|
||||
assert result and result.message.startswith("Refused")
|
||||
|
||||
|
||||
async def test_validation_refuses_a_disallowed_module_before_terraform_runs():
|
||||
runner = TerraformRunner(binary="no-such-binary", module_namespaces=ALLOWED)
|
||||
|
||||
result = await runner.validate(
|
||||
{"terraform/main.tf": GOOD.replace("example-modules", "someone-else")}
|
||||
)
|
||||
|
||||
assert result.message.startswith("Refused: module")
|
||||
|
||||
|
||||
def test_a_version_constraint_is_read():
|
||||
assert admits(">= 6.37.0, < 9", "8.6.0")
|
||||
assert not admits(">= 6.2, < 8", "8.6.0")
|
||||
assert admits("~> 3.0", "3.7.2") and not admits("~> 3.0", "4.0.0")
|
||||
assert admits("~> 3.1.2", "3.1.9") and not admits("~> 3.1.2", "3.2.0")
|
||||
assert admits("", "8.6.0")
|
||||
|
||||
|
||||
REGISTRY_ANSWER = {
|
||||
"version": "1.2.3",
|
||||
"root": {
|
||||
"inputs": [
|
||||
{"name": "labels", "type": "map(string)", "description": "Labels."},
|
||||
{
|
||||
"name": "name",
|
||||
"type": "string",
|
||||
"description": "Name.",
|
||||
"required": True,
|
||||
},
|
||||
],
|
||||
"outputs": [{"name": "id"}],
|
||||
"provider_dependencies": [{"name": "cloud", "version": ">= 6, < 8"}],
|
||||
},
|
||||
"submodules": [
|
||||
{
|
||||
"path": "modules/nat",
|
||||
"inputs": [{"name": "router", "type": "string", "required": True}],
|
||||
"provider_dependencies": [{"name": "random", "version": "~> 3.0"}],
|
||||
}
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def registry(monkeypatch):
|
||||
asked: list[str] = []
|
||||
|
||||
class Client:
|
||||
def __init__(self, **_):
|
||||
pass
|
||||
|
||||
async def __aenter__(self):
|
||||
return self
|
||||
|
||||
async def __aexit__(self, *_):
|
||||
return False
|
||||
|
||||
async def get(self, url):
|
||||
asked.append(url)
|
||||
if "missing" in url:
|
||||
return httpx.Response(404, json={"errors": ["Not Found"]})
|
||||
return httpx.Response(200, json=REGISTRY_ANSWER)
|
||||
|
||||
monkeypatch.setattr(modules.httpx, "AsyncClient", Client)
|
||||
return asked
|
||||
|
||||
|
||||
async def test_a_modules_inputs_come_back_required_first_with_its_outputs(registry):
|
||||
lookup = ModuleLookup(namespaces=ALLOWED, pinned={"cloud": "7.1.0"})
|
||||
|
||||
reply = (await lookup.describe("example-modules/network/cloud", "1.2.3")).message
|
||||
|
||||
assert reply.index("- name (required") < reply.index("- labels (optional")
|
||||
assert "Outputs: id" in reply and "Submodules: modules/nat" in reply
|
||||
assert "NOT USABLE" not in reply
|
||||
assert registry == [f"{modules.REGISTRY}/example-modules/network/cloud/1.2.3"]
|
||||
# The same module is not fetched twice.
|
||||
await lookup.describe("example-modules/network/cloud", "1.2.3", find="name")
|
||||
assert len(registry) == 1
|
||||
|
||||
|
||||
async def test_a_module_the_pinned_provider_does_not_satisfy_is_called_out(registry):
|
||||
lookup = ModuleLookup(namespaces=ALLOWED, pinned={"cloud": "8.6.0"})
|
||||
|
||||
reply = (await lookup.describe("example-modules/network/cloud")).message
|
||||
|
||||
assert "NOT USABLE: it requires cloud >= 6, < 8" in reply
|
||||
assert "pinned to cloud 8.6.0" in reply
|
||||
|
||||
|
||||
async def test_a_submodule_is_described_by_its_own_inputs(registry):
|
||||
lookup = ModuleLookup(namespaces=ALLOWED, pinned={"cloud": "8.6.0"})
|
||||
|
||||
reply = (
|
||||
await lookup.describe("example-modules/network/cloud//modules/nat")
|
||||
).message
|
||||
|
||||
assert "- router (required" in reply and "- name" not in reply
|
||||
assert "It also uses the random provider" in reply
|
||||
missing = await lookup.describe("example-modules/network/cloud//modules/vpn")
|
||||
assert "has no submodule" in missing.message and "modules/nat" in missing.message
|
||||
|
||||
|
||||
async def test_find_narrows_the_inputs(registry):
|
||||
lookup = ModuleLookup(namespaces=ALLOWED)
|
||||
|
||||
reply = (
|
||||
await lookup.describe("example-modules/network/cloud", find="label")
|
||||
).message
|
||||
|
||||
assert "- labels" in reply and "- name (" not in reply
|
||||
|
||||
|
||||
async def test_a_module_outside_the_allowed_namespaces_is_not_looked_up(registry):
|
||||
lookup = ModuleLookup(namespaces=ALLOWED)
|
||||
|
||||
reply = (await lookup.describe("someone-else/network/cloud")).message
|
||||
|
||||
assert reply.startswith("Refused") and registry == []
|
||||
assert (
|
||||
"no module" in (await lookup.describe("example-modules/missing/cloud")).message
|
||||
)
|
||||
Reference in New Issue
Block a user