Architecture diagrams rot the day they are drawn. This playbook keeps Mermaid/D2 sources in git next to the Terraform, and uses an AI agent to regenerate the diagram from actual infrastructure code on a schedule — the diff between drawn intent and deployed reality becomes your doc-drift alarm.
Tier: Core · Hands-on time: ~35 minutes
Live-infrastructure import is the most accurate diagramming approach because it reads actual configuration rather than anyone's memory. The architect's version of that insight: treat the diagram as a build artifact derived from IaC, and treat divergence as a signal. When the regenerated diagram disagrees with the committed one, either the infrastructure changed without the design being updated, or the design changed without being built — both are findings worth thirty-five minutes.
Skip AI when there is no IaC — a drift check needs a machine-readable source of truth; hand-managed consoles give you nothing to diff against.
terraform show outputplan/state output gives deployed truth; .tf files give declared truth. Know which one you are diffing against, and never hand the agent state files containing secrets — use terraform show output reviewed for sensitive values, or the .tf sources.Establish the mapping convention once. Decide and write down, in a DIAGRAMS.md, what the diagram shows from the IaC: which resource types appear (compute, data stores, queues, gateways — usually not IAM glue or log groups), what granularity (module = box is a good default), and which edges are drawn (network paths and data flows, not every security-group reference). Without a convention, every drift check drowns in noise.
Have the agent regenerate from IaC.
Read infra/ (Terraform) for the orbit-docs-copilot stack. Following the
conventions in docs/DIAGRAMS.md, generate docs/diagrams/system.generated.mmd
showing: compute services, data stores, queues/topics, gateways, and the
VPC/subnet boundaries, with edges for network paths and data flows you
can actually evidence from the code (security group rules, IAM-granted
access, environment-variable wiring, subnet placement).
Rules:
- Every node and edge gets a trailing comment naming the Terraform
resource(s) it derives from.
- If you cannot evidence an edge from code, do not draw it — list it
under "UNEVIDENCED" at the bottom.
- Do not consult the existing system.mmd — this must be an independent
derivation.
Diff generated against committed — with the agent narrating. "Compare docs/diagrams/system.mmd (design intent) with system.generated.mmd (derived from IaC). Report three lists: in design but not deployed; deployed but not in design; present in both but different (labels, boundaries, direction). Cite the Terraform resource for every deployed-side claim." The resource citations are what make findings checkable in minutes.
Triage every drift finding to a cause. Each divergence is one of: infrastructure moved ahead of docs (update the diagram — most common), design moved ahead of build (expected, note the ticket), the agent misread the IaC (it happens — the resource citation lets you disprove it fast), or the convention is ambiguous (fix DIAGRAMS.md). The triage note, not the diff, is the deliverable — Anita's first run found a NAT path in Terraform that the design said should not exist, which was a real security finding, not a doc bug.
Fold accepted changes into the canonical diagram and PR it. Never let system.generated.mmd replace system.mmd wholesale — the canonical diagram carries intent (grouping, labels, annotations) the generator cannot know. Port the accepted deltas by hand or with scoped agent edits, keep the generated file as evidence, and open a PR containing diagram change + drift report + triage notes.
Schedule it. Wire the regeneration and diff into CI (weekly, or on merges touching infra/), failing softly with a posted drift report rather than blocking. Drift checking you remember to do monthly is drift checking you do quarterly.
terraform state list check before you announce them — the agent may simply have missed a module. Never escalate a drift finding you have not reproduced.Client Terraform is client-confidential infrastructure detail — often the most sensitive artifact you hold. Run the agent inside the approved boundary: Claude Code against a client-tenancy endpoint (Bedrock/Azure OpenAI in the client's subscription), or a local model for the generation step. Where no AI may touch the IaC at all, keep the pattern and drop the model: deterministic tools (Inframap-class generators, terraform graph post-processing) produce the deployed-truth diagram, and you do the diff reading yourself — the git-plus-schedule discipline is the durable part of this playbook, with or without the AI acceleration.
The diagram in git is a claim; the Terraform is the fact. Regenerate, diff, and triage on a schedule — drift you detect weekly is documentation; drift you find during an incident is an outage multiplier.