FOU//CAL
IT & SystemsOct 29, 20266 min read

Infrastructure as code, by an AI: VLANs, firewall rules, and a switch with no API

What actually happened when I handed my AI agent a scoped API key to provision eight VLAN zones, 24 firewall rules, and an undocumented 10G switch — including the mistake it made and I caught.

Yesterday I ran the network equivalent of "here's the keys, back it out of the driveway." My AI agent — the same stack that runs my assistant — got a scoped API credential to the firewall and a job: carve eight new VLAN zones, write their firewall policy, and tag the trunk on the managed switch in front of it. What follows is the honest write-up: what went better than expected, what went quietly wrong, and the one line I typed that mattered most.

The doctrine first, keystrokes second

Before any write, we agreed on five rules. They're the only reason this is a story and not an outage report:

  1. Read-only inventory before any mutation. No write command runs until both of us have seen the current state.
  2. New objects only. Existing interfaces, VLANs, and rules are untouch- able by default. Create; never edit; never delete.
  3. One batch per apply, verify after each. No megapatches.
  4. No checkbox without machine read-back. The agent may not mark any- thing "done" unless a fresh API response proves it.
  5. Human owns the risky levers. Manual config backup stayed mine; console access stays the escape hatch.

Batch 0: the inventory, and the first lesson

The API greeted us the way APIs do: with 404s. Every endpoint the agent guessed from documentation of older versions was dead. The lesson it internalized fast (and this is the kind of thing you cannot grep for):

a 404 from a wrong path looks identical to a 404 from bad credentials — so a 404 proves nothing. Authenticate against a known-good GET, then treat every other 404 as a wrong map.

Inventory came out clean: eight candidate VLAN tags with no collisions against the legacy set, ~80 default-deny rules, one interface with the spare capacity we needed. The agent also did something I'd have done manually: it joined the firewall's interface MAC table against the switch's learned-MAC table and physically identified which switch port the firewall trunk plugged into — poor-man's LLDP, two API calls.

Batch 1: eight zones, zero drama

VLAN creation, interface assignment, static gateway IPs — all via API, all additive, applied and re-read:

zone VLAN gateway policy intent
servers 20 10.10.20.1/24 internal spine
iot 5 10.10.5.1/24 internet, LAN blackholed
cams 6 10.10.6.1/24 no egress at all
guest 7 10.10.7.1/24 internet, LAN blackholed
core 9 10.10.9.1/24 same-subnet only
mgmt 10 10.10.10.1/24 admin plane
work 15 10.10.15.1/24 the trusted LAN
ai 30 10.10.30.1/24 internal only, internet blocked

(numbers simplified — the scheme and every IP here are changed for publication).

The API had opinions: option fields want the option key (keep), never the display string (keep state); description masks forbade hyphens (zone_srv, not zone-srv); a full-object setItem crash-looped while a two-field minimal diff worked fine. Each trap, once bitten, went into the agent's persistent runbook. That's the new "as code": a big share of the institutional knowledge now lives in the agent's notes file, not a wiki.

Batch 2: the mistake I caught

The agent created 24 tagged firewall rules across the eight zones, read them back, reported ordering, looked immaculate. But something nagged:

"i think you created firewall rules without port specified, making them any port."

Audit: it was right. Six zone→firewall rules carried descriptions claiming DNS and NTP — and left destination_port empty, which means every TCP and UDP port on the gateway, including its management UI, from the guest, IoT and camera zones. Descriptions are comments. Enforcement is fields. The fix: explicit port aliases (53,123 for resolver rules; 53,123,514,443 for the admin plane), applied, read back, diffed again.

If you take one line from this post: an AI-written rule is not done when its description reads correctly — it's done when a read-back diffs the description's claim against the actual protocol and port fields. Intent verification against intent is theater; verify intent against bytes.

The switch: no API, no mercy

The firewall has a real API. The 10G managed switch — a no-name box that punches far above its price — has a web UI from a fever dream: form-encoded CGI calls, an RC4-era auth dance, menu pages assembled client-side. I'd started a parser for it years ago and abandoned it. It could read the whole config — but writing port VLAN membership was nowhere in it.

So the agent reverse-engineered it live: authenticated a session, fetched the membership page HTML, extracted the JS bindings, mapped the write commands, and rehearsed payloads. Two findings were nastier than the auth:

  • The "create VLANs" call takes a full list — it is declarative with no warning label. Send a partial list and you don't add a VLAN, you replace the set. The safe pattern: read current state, send original ∪ new, always.
  • Port-membership semantics were only guessable, so we tested on a dead port first — a spare 10G link with an edge switch that carries nothing. Verify the write behaves, then touch the live trunk.

And on the live trunk, my one human instruction, repeated until it was boring: do not remove the legacy management VLAN from the trunk. That VLAN is the path to the switch's own UI. Removing it is the classic way to discover you need a console cable you don't own. The batch went in tagged- only, native VLAN untouched, management VLAN intact, read-back verified.

Was it actually "infrastructure as code"?

No — and that's the interesting part. There was no plan file, no state lock, no diff before apply. The "code" was an agent with scripts, a read-back habit, and a memory file where every bitten API quirk becomes a permanent rule. Where traditional IaC gives you reproducibility, AI-as- ops gives you exploration at the speed of a very fast junior — and it fails exactly like one too: confidently, plausibly, with the wrong port.

Honest gaps, no rounding off: the agent couldn't read the outbound-NAT mode through the API (a manual UI check stayed on my list), the config-backup endpoint 404s meant the backup was human labor, and the console was never confirmed attached. Roughly 90 % of the keystrokes were the machine's. The 10 % that mattered was catching what looked right and wasn't.

That ratio is the whole job description, theirs and mine, for now.

#ai#automation#networking#firewall#vlan