Agents as IaC Modules
Treat each autonomous agent — each "software employee" — as a reusable
infrastructure-as-code MODULE, not a hand-assembled one-off. The agent's
configuration becomes a single module instantiation: every meaningful property
is an explicit input, the whole thing lives in version control, and the fleet is
the set of instantiations.
When an agent is a module, the operations that are otherwise manual and
error-prone become declarative:
- Onboard a new agent by instantiating the module with new inputs.
- Offboard by removing the instantiation; the deletion is the audit trail.
- Scale by adjusting an input (replicas, resources) or instantiating again.
- Audit by reading the committed inputs — no archaeology across live systems.
This is the higher-level pattern. For the file layout of an individual module
see [[terraform-module-layout]]; for the rule that infrastructure must be
reproducible from source rather than clicked together live see
[[iac-not-ad-hoc]].
The six facets (the module inputs)
Every agent decomposes into the same facets. Make each one an explicit input so
two agents differ only by their inputs, never by bespoke wiring.
- Identity — the account or bot the agent acts AS, and what it is allowed to
act on. The agent is a first-class principal, not a borrowed human login.
Onboarding creates the identity; offboarding revokes it.
- Runtime — where and how it executes: base image, CPU/memory/limits,
replicas, restart and lifecycle policy. Sized per agent, declared not tuned by
hand on a live host.
- Capabilities — the tools, skills, and external connectors it may use.
Capability is granted by input, so least-privilege is reviewable: you can read
off exactly what an agent can do.
- Knowledge — the memory, wiki, or context stores it reads and writes,
declared as mounts or references. Knowledge persists across restarts and is
attached, not baked into the runtime.
- Secrets — credential MAPPINGS only: a declared reference from a secret
manager to the agent, injected at runtime. Never the secret value, never
hand-placed into a running instance. Rotating upstream changes nothing in the
module.
- Schedule — when the agent runs: always-on, cron, or event-triggered. A
declared input so "when does this run" is answerable from source.
The module interface
module "agent" {
identity = ... # the account/bot it acts as + its grants
runtime = ... # image, resources, replicas, lifecycle
capabilities = ... # tools / skills / connectors allowed
knowledge = ... # memory / wiki mounts and references
secrets = ... # declared secret-manager mappings (never values)
schedule = ... # always-on / cron / event-triggered
}
│
▼
one instantiated, running agent
The fleet is then just a set of these instantiations side by side in version
control. A reviewer can diff one agent against another and see only the facets
that differ. A new agent is a copy with new inputs, not a fresh investigation of
how agents are built.
Honest limits
Not every step is fully declarative, and pretending otherwise is the failure
mode. Some inputs require a one-time MANUAL step that the module cannot perform:
- Interactive auth — an OAuth consent flow, device login, or browser sign-in
to mint a token the module then references.
- App / integration installation — installing an app into an external
workspace or org, or approving a connector.
- External account creation — registering the underlying identity when the
provider has no API for it.
Handle these honestly: declare the reference (the secret mapping, the installed
app id) in the module, and DOCUMENT the manual step that produces it as a named
prerequisite with a verification check. The goal is "everything that can be
declarative is declarative, and the few steps that can't are written down" — not
a false claim of full automation.
When to use
- Standing up more than one agent, or expecting to add/remove agents over time.
- You need onboarding/offboarding/scaling/audit to be reproducible and reviewable.
- You want least-privilege and credential custody to be readable from source.
When not to use
- A single throwaway or experimental agent with no reuse and no audit need —
the module machinery is overhead. Promote it to a module once a second agent
appears or it goes anywhere near production.
Conformance check
Read the committed source — not a live instance — and confirm each facet is an
explicit input:
- Identity is declared and scoped; it is not a shared or human login.
- Runtime (image, resources, lifecycle) is in source, not tuned on a live host.
- Capabilities are enumerated, so least-privilege is reviewable.
- Knowledge stores are declared mounts/references that survive restarts.
- Secrets appear only as manager→agent mappings; no values, no hand-placed files.
- Schedule is an explicit input.
- Every manual prerequisite (interactive auth, app install, account creation) is
documented with a verification step, and the module references its output.
1---2name: agents-as-iac-modules3description: Use when onboarding, scaling, decommissioning, or auditing autonomous agents (or any "software employee") in a fleet. Model each agent as a reusable infrastructure-as-code module whose inputs are its facets, so its whole configuration is declarative, reviewable, and reproducible.4---56# Agents as IaC Modules78Treat each autonomous agent — each "software employee" — as a reusable9infrastructure-as-code MODULE, not a hand-assembled one-off. The agent's10configuration becomes a single module instantiation: every meaningful property11is an explicit input, the whole thing lives in version control, and the fleet is12the set of instantiations.1314When an agent is a module, the operations that are otherwise manual and15error-prone become declarative:1617- **Onboard** a new agent by instantiating the module with new inputs.18- **Offboard** by removing the instantiation; the deletion is the audit trail.19- **Scale** by adjusting an input (replicas, resources) or instantiating again.20- **Audit** by reading the committed inputs — no archaeology across live systems.2122This is the higher-level pattern. For the file layout of an individual module23see [[terraform-module-layout]]; for the rule that infrastructure must be24reproducible from source rather than clicked together live see25[[iac-not-ad-hoc]].2627## The six facets (the module inputs)2829Every agent decomposes into the same facets. Make each one an explicit input so30two agents differ only by their inputs, never by bespoke wiring.3132- **Identity** — the account or bot the agent acts AS, and what it is allowed to33 act on. The agent is a first-class principal, not a borrowed human login.34 Onboarding creates the identity; offboarding revokes it.35- **Runtime** — where and how it executes: base image, CPU/memory/limits,36 replicas, restart and lifecycle policy. Sized per agent, declared not tuned by37 hand on a live host.38- **Capabilities** — the tools, skills, and external connectors it may use.39 Capability is granted by input, so least-privilege is reviewable: you can read40 off exactly what an agent can do.41- **Knowledge** — the memory, wiki, or context stores it reads and writes,42 declared as mounts or references. Knowledge persists across restarts and is43 attached, not baked into the runtime.44- **Secrets** — credential MAPPINGS only: a declared reference from a secret45 manager to the agent, injected at runtime. Never the secret value, never46 hand-placed into a running instance. Rotating upstream changes nothing in the47 module.48- **Schedule** — when the agent runs: always-on, cron, or event-triggered. A49 declared input so "when does this run" is answerable from source.5051## The module interface5253```54module "agent" {55 identity = ... # the account/bot it acts as + its grants56 runtime = ... # image, resources, replicas, lifecycle57 capabilities = ... # tools / skills / connectors allowed58 knowledge = ... # memory / wiki mounts and references59 secrets = ... # declared secret-manager mappings (never values)60 schedule = ... # always-on / cron / event-triggered61}62 │63 ▼64 one instantiated, running agent65```6667The fleet is then just a set of these instantiations side by side in version68control. A reviewer can diff one agent against another and see only the facets69that differ. A new agent is a copy with new inputs, not a fresh investigation of70how agents are built.7172## Honest limits7374Not every step is fully declarative, and pretending otherwise is the failure75mode. Some inputs require a one-time MANUAL step that the module cannot perform:7677- **Interactive auth** — an OAuth consent flow, device login, or browser sign-in78 to mint a token the module then references.79- **App / integration installation** — installing an app into an external80 workspace or org, or approving a connector.81- **External account creation** — registering the underlying identity when the82 provider has no API for it.8384Handle these honestly: declare the *reference* (the secret mapping, the installed85app id) in the module, and DOCUMENT the manual step that produces it as a named86prerequisite with a verification check. The goal is "everything that can be87declarative is declarative, and the few steps that can't are written down" — not88a false claim of full automation.8990## When to use9192- Standing up more than one agent, or expecting to add/remove agents over time.93- You need onboarding/offboarding/scaling/audit to be reproducible and reviewable.94- You want least-privilege and credential custody to be readable from source.9596## When not to use9798- A single throwaway or experimental agent with no reuse and no audit need —99 the module machinery is overhead. Promote it to a module once a second agent100 appears or it goes anywhere near production.101102## Conformance check103104Read the committed source — not a live instance — and confirm each facet is an105explicit input:106107- Identity is declared and scoped; it is not a shared or human login.108- Runtime (image, resources, lifecycle) is in source, not tuned on a live host.109- Capabilities are enumerated, so least-privilege is reviewable.110- Knowledge stores are declared mounts/references that survive restarts.111- Secrets appear only as manager→agent mappings; no values, no hand-placed files.112- Schedule is an explicit input.113- Every manual prerequisite (interactive auth, app install, account creation) is114 documented with a verification step, and the module references its output.