My Firewall Is Now Code: Retiring the Last 39 Legacy Rules
Updated November 26, 2026

This morning I ran a Terraform plan against my firewall and it came back with two words: No changes.
That plan covered every filter rule on my router. For the first time, the firewall that guards my infrastructure is fully described in a Git repository, reviewed before it changes, and rebuilt from code if it ever has to be. This post is about the last and hardest step to get there, and the discipline that made it boring in the best way.
It is also the first in a series. Every major piece of my infrastructure that moves into code gets a write-up like this one.
The Problem: Rules the Automation Could Not Reach
My router runs OPNsense. Over the years I built its rules the usual way: in the web GUI, one at a time, whenever I needed something. Later I started managing the firewall through its API and then through Terraform. Most of the rule set made that move. One group did not.
OPNsense 26.x keeps older GUI-made rules (the "legacy" rules) in a separate store. The API cannot edit them, so Terraform cannot manage them. In my case there were 39 of them. And in this version the GUI no longer let me delete them one by one either. The vendor offers exactly one path: a Migration Assistant. You export the legacy rules to a CSV file, import that file into the new rules system, and then remove all legacy rules in a single step.
All of them at once, on the device every packet in the house goes through.
Step One: Decide What Deserves to Survive
Before touching anything, we asked of each of the 39 rules: what does this do today, and does anything still depend on it?
The result was a written design that kept 9 rules and dropped 30. The dropped rules fell into a few plain groups:
- Rules that were disabled.
- Rules pointing at a host I had already retired.
- Rules that could never match because an earlier rule always decided first.
- Leftovers from a security plugin that was no longer installed. They pointed at empty block lists, so they looked like protection but blocked nothing.
A rule that looks like a defense but does nothing is worse than no rule. It makes you believe something false about your own network.
The design also caught a subtle trap. Imported rules land in a new processing order, grouped by rule type. If the kept rules had simply carried over their old positions, one broad allow rule would have jumped ahead of narrower rules I was designing to replace it. So the import file changed only two things, each rule's position and its description, and a test enforced that nothing else changed. The design then walked through each class of rules to show that no traffic decision would come out differently.
Step Two: Build a Way Back Before Going Forward
My rule for risky changes is simple: there must be a tested way back, and it must exist before the change, not after.
For this one there were three:
- A ZFS boot environment snapshot of the firewall itself. If everything went wrong, I could activate it and reboot into the exact system from before.
- A configuration backup saved off the router.
- A verified restore point inside OPNsense. Our reviewer asked a fair question: is the backup file actually restorable from the firewall's own configuration history? So we checked. The revision in the history was byte-identical to the backup file. Only then did that gate pass.
One more detail: the first snapshot predated an earlier reviewed change, so rolling back to it would have quietly undone that work. We took a fresh safety net after it and kept the older one as last-resort recovery only.
Step Three: Measure Before, Change, Measure After
A firewall change is only safe if you can prove what it did. Before the migration we recorded a baseline, and after each step we ran the same checks again:
- DNS and time-server redirect probes from several internal networks. The firewall quietly redirects those requests to local services, so each probe had to get the same answer as before, and the counters on the rules doing the work had to rise.
- Every public site I host, checked for the same response as before.
- Mail, checked for its normal greeting.
- The backend services behind my public sites, each one reachable.
- The admin path: the firewall's management interfaces had to stay closed from the networks that should not reach them, and open from the one that should.
- And at the end, a Terraform plan that had to say No changes.
We ran the full set again an hour later. Same results.
The Two Clicks, and the One That Did Nothing
The import and the final removal are GUI steps in the Migration Assistant. I clicked them myself.
The first import did nothing. No error, no warning, no change. It turns out the small check mark next to the file name is the upload button. I had chosen the file but never sent it. The second try worked, and the check that followed confirmed the 9 rules existed exactly once each, with the values from the reviewed file.
This is why the checks run after every step. A silent no-op looks like success until you look.
After the import checks passed, I clicked the second step: remove all legacy rules. The probes came back the same. The sites came back the same. The legacy store was empty.
Bringing It Home in Terraform
The last step was to tell Terraform about the 9 rules that now lived in the new system. That was a state-only import: no change to the router at all. The plan said 9 to import, 0 to add, 0 to change, 0 to destroy. After the apply, the plan said No changes.
A follow-up change then deleted the leftover block lists from that old plugin, with a check first that no rule anywhere still referenced them.
Earlier the Same Week
The migration was the finish line, not the whole race. Earlier the same week, three high-risk rule problems were fixed as code, each one reviewed and applied on its own:
- Admin access. One rule now blocks the firewall's management interfaces from every network except the trusted management networks.
- Outbound from the public-facing zone. Two broad rules that allowed far more than needed were removed, after evidence showed nothing used them.
- Public zone to the GPU server. A rule that allowed every port was replaced with one rule for a named list of ports. That list came from evidence: what each service actually connects to, and live connection sampling over a couple of hours.
The Team: One Human, Several Agents
I did not do this alone, and I did not hand it off either:
- Me. I approved every change before it touched the router. Nothing applied without my yes.
- An orchestrator agent applied the approved changes, ran the before and after tests, and kept the backups and notes.
- A builder agent wrote the changes: the Terraform code, the migration design, the import file.
- A separate reviewer agent (Codex) reviewed every change, often more than once, and caught real bugs. One rollback plan would have removed more than it should. One proposed block rule would have caught some of my own admin traffic. One design had no proven restore path until the reviewer asked for it.
And the safety gates are real. Later the same day a different change started down the same path. Its first gate was a read-only check, and it found a configuration the design had not accounted for. So the change stopped before anything on the router was touched. That is the gate doing its job.
What's Next
The firewall is the first big piece. Next comes the rest of the network and the services that run on it, each moved into code with the same method: find what exists, decide what deserves to survive, build the way back, test before and after, and let the plan say No changes.
Each one gets its own post in this series. See you at the next No changes.
Enjoyed this article?
Subscribe to get notified about new posts on software engineering, AI development, and infrastructure.
No spam, unsubscribe anytime.