routeros: full-config render + round-trip gate (#70) #117

Merged
ginjiruu merged 6 commits from routeros-generator-70 into master 2026-11-17 02:19:36 +00:00
Owner

Closes #70. Rebased onto master 48bd585 (#118-#123). The runner side (provider mirror CLI config, hostAliases) is already on lab/clusters main via #1704.

What

routeros/render/ turns each device root into one full RouterOS config and proves Terraform adopts it cleanly. The mission is hardware replacement: a dead router or switch gets reimaged on the bench with exactly the config its root describes, and the controller adopts it without creating or breaking anything. The #73 cutover uses the same procedure.

  • task render:device DEVICE=...: fresh CHR with the device's port names, the real #64 bootstrap, tofu apply of a copy of the root (sim exception: own containerlab net 172.31.250.0/24, local state, endpoint validated), /export, cut to what Terraform owns -> out/<device>.full.rsc (gitignored, holds the PPPoE password when rendered with it). Import blocks keyed field=value -> imports/<device>.tf (committed, adoption-time only, never left in a root). Keys are always attributes Terraform holds, never RouterOS auto-names.
  • task render:gate DEVICE=...: fresh CHR, bootstrap, render via load.sh (the bench loader), empty state + imports, plan. Every object must import with no change, except a fixed allowlist with exact actions: move_items x2 create, ip_dns create, the www-ssl rotation (module.www_cert vault cert, routeros cert, ip_service create limited to numbers/port/certificate/disabled), and the #74 fuse steps (arm, guard, confirm). The residue is applied, and the device export (normalised) must stay identical. The second plan must exit 0. Coverage: no object in a Terraform-owned menu outside state.
  • task render:selftest: the gate must reject five broken renders (missing object, drifted attribute, swapped rules, rogue rule, recovery left on).
  • task render:provider-check: upstream 1.99.1 must fail an in-place address update (vrf bug), the lab fork must apply it.

Results (CHR 7.25.1, master 48bd585 + this branch, provider fork 1.99.1003, fresh CHR per step)

device gate: imported no-op allowlisted residue coverage
rb5009-a 208 9, no-op on device 206 objects / 21 menus
rb5009-b 208 9, no-op on device 206 objects / 21 menus
crs309 24 3 (fuse steps), no-op on device 22 objects / 7 menus

Selftest: 5/5 broken renders rejected, each for its own reason. Provider check: PASS. The #74 fuse runs in every sim apply: with no probe up it reports NOT ARMED and leaves nothing on the device (render.sh refuses to export otherwise).

Changes outside routeros/render

  • modules/router: interface list members get "<list>: <interface>" comments, their import key. The in-icmp v6 rule comment loses its commas. crs309/switch.tf: same for the legacy-lan VLAN comment. Comment-only.
  • crs309 management (option B): modules/site reservation VLAN 10 crs309 -> 10.30.10.10 on a fixed, locally administered bridge MAC 02:00:0A:1E:0A:0A (in config, so a replacement switch gets the same lease); the crs309 root gets vlan10-mgmt with a DHCP client.
  • Provider: routeros/tofu.rc installs terraform-routeros/routeros from the lab fork 1.99.1003 (public OCI mirror git.animeteamspeak.moe/lab/terraform-provider-routeros); the four routeros lock files pin it. Carried fixes, all hit by these CHR applies: vrf read-only on ip_address (upstream PR #984), netwatch type = "dns" (the #74 DNS probe failed every plan), no default for BGP connection add_path_out/address_families (RouterOS 7.21+ rejects both; every #118 BGP connection create failed).
  • bootstrap/render.sh: RENDER_VARS, RENDER_OUT, EXTRA_IP_SANS hooks for the sim. Unset changes nothing.
  • docs: README decisions 2 and 4 rewritten (netinstall slot = bootstrap only, full config = second file, adoption via imports). adoption.md: import-key rules, the provider fork, the crs309 management path.

Decisions (2026-11-16)

  • No certificate in the render: the bootstrap cert serves until the first controller apply rotates it.
  • The gate passes on an allowlist, not exit 0: move_items, ip_dns, the vault cert and terraform_data have no importer.
  • Run our own provider fork instead of downgrading RouterOS to 7.20.
  • crs309 management by DHCP reservation (option B).

Not provable on a CHR

  • Hardware defaults, PPPoE, load.sh over the real recovery port, the crs309's DHCP lease (no DHCP server on the CHR's VLAN 10), BGP sessions, and an armed fuse (isolated CHR: NOT ARMED). Bench recipe in routeros/render/README.md.
  • Replacement needs the dead device's state Secret on mini deleted first (live change, sign-off at the time).
Closes #70. Rebased onto master 48bd585 (#118-#123). The runner side (provider mirror CLI config, hostAliases) is already on lab/clusters main via #1704. ## What `routeros/render/` turns each device root into one full RouterOS config and proves Terraform adopts it cleanly. The mission is hardware replacement: a dead router or switch gets reimaged on the bench with exactly the config its root describes, and the controller adopts it without creating or breaking anything. The #73 cutover uses the same procedure. - `task render:device DEVICE=...`: fresh CHR with the device's port names, the real #64 bootstrap, `tofu apply` of a copy of the root (sim exception: own containerlab net 172.31.250.0/24, local state, endpoint validated), `/export`, cut to what Terraform owns -> `out/<device>.full.rsc` (gitignored, holds the PPPoE password when rendered with it). Import blocks keyed `field=value` -> `imports/<device>.tf` (committed, adoption-time only, never left in a root). Keys are always attributes Terraform holds, never RouterOS auto-names. - `task render:gate DEVICE=...`: fresh CHR, bootstrap, render via `load.sh` (the bench loader), **empty state** + imports, plan. Every object must import with no change, except a fixed allowlist with exact actions: `move_items` x2 create, `ip_dns` create, the www-ssl rotation (`module.www_cert` vault cert, routeros cert, ip_service create limited to numbers/port/certificate/disabled), and the #74 fuse steps (arm, guard, confirm). The residue is applied, and the device export (normalised) must stay identical. The second plan must exit 0. Coverage: no object in a Terraform-owned menu outside state. - `task render:selftest`: the gate must reject five broken renders (missing object, drifted attribute, swapped rules, rogue rule, recovery left on). - `task render:provider-check`: upstream 1.99.1 must fail an in-place address update (vrf bug), the lab fork must apply it. ## Results (CHR 7.25.1, master 48bd585 + this branch, provider fork 1.99.1003, fresh CHR per step) | device | gate: imported no-op | allowlisted residue | coverage | |---|---|---|---| | rb5009-a | 208 | 9, no-op on device | 206 objects / 21 menus | | rb5009-b | 208 | 9, no-op on device | 206 objects / 21 menus | | crs309 | 24 | 3 (fuse steps), no-op on device | 22 objects / 7 menus | Selftest: 5/5 broken renders rejected, each for its own reason. Provider check: PASS. The #74 fuse runs in every sim apply: with no probe up it reports NOT ARMED and leaves nothing on the device (`render.sh` refuses to export otherwise). ## Changes outside routeros/render - `modules/router`: interface list members get `"<list>: <interface>"` comments, their import key. The in-icmp v6 rule comment loses its commas. `crs309/switch.tf`: same for the legacy-lan VLAN comment. Comment-only. - crs309 management (option B): `modules/site` reservation VLAN 10 crs309 -> 10.30.10.10 on a fixed, locally administered bridge MAC `02:00:0A:1E:0A:0A` (in config, so a replacement switch gets the same lease); the crs309 root gets `vlan10-mgmt` with a DHCP client. - Provider: `routeros/tofu.rc` installs `terraform-routeros/routeros` from the lab fork `1.99.1003` (public OCI mirror `git.animeteamspeak.moe/lab/terraform-provider-routeros`); the four routeros lock files pin it. Carried fixes, all hit by these CHR applies: vrf read-only on ip_address (upstream PR #984), netwatch `type = "dns"` (the #74 DNS probe failed every plan), no default for BGP connection `add_path_out`/`address_families` (RouterOS 7.21+ rejects both; every #118 BGP connection create failed). - `bootstrap/render.sh`: `RENDER_VARS`, `RENDER_OUT`, `EXTRA_IP_SANS` hooks for the sim. Unset changes nothing. - docs: README decisions 2 and 4 rewritten (netinstall slot = bootstrap only, full config = second file, adoption via imports). adoption.md: import-key rules, the provider fork, the crs309 management path. ## Decisions (2026-11-16) - No certificate in the render: the bootstrap cert serves until the first controller apply rotates it. - The gate passes on an allowlist, not exit 0: `move_items`, `ip_dns`, the vault cert and `terraform_data` have no importer. - Run our own provider fork instead of downgrading RouterOS to 7.20. - crs309 management by DHCP reservation (option B). ## Not provable on a CHR - Hardware defaults, PPPoE, `load.sh` over the real recovery port, the crs309's DHCP lease (no DHCP server on the CHR's VLAN 10), BGP sessions, and an armed fuse (isolated CHR: NOT ARMED). Bench recipe in `routeros/render/README.md`. - Replacement needs the dead device's state Secret on mini deleted first (live change, sign-off at the time).
Interface list members carry "<list>: <interface>" as comment: an interface
sits in several lists, and provider 1.99.1 imports by one unique field=value.
Comments that serve as import keys lose their commas: RouterOS REST matches
nothing when a filter value holds a literal comma (the provider escapes only
spaces). Proven on CHR 7.25.1.
routeros/render/ applies each device root to a throwaway CHR (sim
exception: own containerlab net 172.31.250.0/24, local state, endpoint
validated), exports it, and cuts the export down to what Terraform owns:
out/<device>.full.rsc (gitignored). It also writes import blocks keyed
field=value (imports/<device>.tf, committed, adoption-time only).

The gate replays a hardware replacement: fresh CHR, bootstrap, render via
load.sh (the bench loader), empty state + imports, plan. Every object must
import with no change except a fixed allowlist (move_items x2, ip dns,
www-ssl rotation). Applying that residue must leave the device export
byte-identical, the second plan must exit 0, and no object in an owned menu
may sit outside state. task render:selftest proves the gate rejects five
kinds of broken render.

Results on CHR 7.25.1: rb5009-a/b 166 imports no-op + 6 allowlisted,
crs309 15 imports no-op, selftest 5/5.

No certificate in the render: the bootstrap cert serves until the first
controller apply. The render disables the recovery address as its last
line, because provider 1.99.1 cannot update a routeros_ip_address on
RouterOS 7.25.1 (it sends the read-only vrf). Docs: README decisions 2 and 4
rewritten for the bootstrap/full-render split; adoption.md gets the
import-key rules.
Author
Owner

Pushed 29c7892: the roots now run the lab provider fork 1.99.1+lab.1 (vrf fix, upstream PR #984) from the public OCI mirror git.animeteamspeak.moe/lab/terraform-provider-routeros, via routeros/tofu.rc. task render:provider-check proves it on a CHR (upstream fails the in-place address update with unknown parameter vrf, the fork applies it). All three gates re-run on the fork: PASS, import blocks unchanged.

Merge order: lab/clusters #1703 first (runner CLI config); without it the runners cannot resolve 1.99.1+lab.1.

Pushed 29c7892: the roots now run the lab provider fork 1.99.1+lab.1 (vrf fix, upstream PR #984) from the public OCI mirror git.animeteamspeak.moe/lab/terraform-provider-routeros, via routeros/tofu.rc. task render:provider-check proves it on a CHR (upstream fails the in-place address update with unknown parameter vrf, the fork applies it). All three gates re-run on the fork: PASS, import blocks unchanged. **Merge order: lab/clusters #1703 first** (runner CLI config); without it the runners cannot resolve 1.99.1+lab.1.
Provider 1.99.1 sends the read-only vrf on every routeros_ip_address update
and RouterOS 7.21+ rejects it, so no router address could be changed in
place. Upstream fix (PR #984) is unmerged; the roots now run the lab fork
1.99.1+lab.1 (lab/terraform-provider-routeros, published as a public OCI
provider mirror on Forgejo's container registry).

- routeros/tofu.rc: oci_mirror for terraform-routeros/routeros only; lock
  files of rb5009-a, rb5009-b, crs309 and the lab sim pin 1.99.1+lab.1
- routeros/render uses it (lib.sh tf), as does task routeros:validate
- task render:provider-check (provider-check.sh, sim/vrf-check.tf): on a
  CHR, upstream 1.99.1 fails a comment-only address update with "unknown
  parameter vrf" and the fork applies it

Gates re-run on the fork: rb5009-a/b and crs309 PASS, imports unchanged.
Needs lab/clusters #1703 (runner CLI config) merged first.
The crs309 root declared no address, so after the render disabled the
recovery address the switch had no IP path. Now:

- modules/site: reservation VLAN 10 crs309 -> 10.30.10.10, MAC
  02:00:0A:1E:0A:0A (locally administered: 02:00 + the IPv4 in hex). Both
  routers serve it.
- crs309: bridge pinned to that MAC (auto_mac off), the bridge tagged on
  VLAN 10, vlan10-mgmt with a DHCP client (default route from the lease,
  DNS/NTP not from the peer). The MAC lives in config, not hardware, so a
  replacement loaded from the render gets the same lease.
- render.py: an import key must be an attribute Terraform holds with the
  device's value. The DHCP client was keyed name=client2, a RouterOS
  auto-number that differs on hardware; it is now keyed by its comment.
  Existing keys unchanged.

Gates on CHR 7.25.1 (fork provider): crs309 17 imported no-op, rb5009-a/b
167 + the 6 allowlisted; coverage PASS on all three. The lease itself is
a bench check: the CHR has no DHCP server on VLAN 10.
Author
Owner

Pushed 0bbecbc, option B for the crs309 management path: site reservation VLAN 10 crs309 -> 10.30.10.10 on a fixed, locally administered bridge MAC (02:00:0A:1E:0A:0A, set in config so a replacement switch gets the same lease); crs309 gets vlan10-mgmt with a DHCP client. The generator now only picks import keys Terraform itself holds (the DHCP client had been keyed by a RouterOS auto-name, client2, which differs on hardware). Gates re-run: crs309 17 imported no-op, rb5009-a/b 167 + allowlist, coverage PASS. The lease itself is a bench check. Runner hostAliases (name -> 10.30.10.x until #50 DNS) are in lab/clusters #1703.

Pushed 0bbecbc, option B for the crs309 management path: site reservation VLAN 10 crs309 -> 10.30.10.10 on a fixed, locally administered bridge MAC (02:00:0A:1E:0A:0A, set in config so a replacement switch gets the same lease); crs309 gets vlan10-mgmt with a DHCP client. The generator now only picks import keys Terraform itself holds (the DHCP client had been keyed by a RouterOS auto-name, client2, which differs on hardware). Gates re-run: crs309 17 imported no-op, rb5009-a/b 167 + allowlist, coverage PASS. The lease itself is a bench check. Runner hostAliases (name -> 10.30.10.x until #50 DNS) are in lab/clusters #1703.
Author
Owner

Heads-up for the #70 session: master moved. #118 (ER-X parity: BGP, NAT, VLAN/reservation trim), #119 (#74 rollback, adds depends_on = [module.rollback] in crs309/switch.tf identity/NTP/bridge blocks and modules/www-cert), and the static crs309 mgmt from #118 is now removed again (user chose your DHCP design). This branch conflicts in routeros/crs309/switch.tf (bridge block: #119 depends_on next to your auto_mac/admin_mac); please rebase and re-run render:all.

Heads-up for the #70 session: master moved. #118 (ER-X parity: BGP, NAT, VLAN/reservation trim), #119 (#74 rollback, adds depends_on = [module.rollback] in crs309/switch.tf identity/NTP/bridge blocks and modules/www-cert), and the static crs309 mgmt from #118 is now removed again (user chose your DHCP design). This branch conflicts in routeros/crs309/switch.tf (bridge block: #119 depends_on next to your auto_mac/admin_mac); please rebase and re-run render:all.
Author
Owner

For the #70 session: master now has #122 (router host port map: new modules/router var ports, hybrid pvid+tagged; L2-only VLAN 21 added to the bridge VLAN table; rb5009-a/b main.tf ports maps) and #123 (crs309 trunk_ports = sfp1, sfp2, sfp7, sfp8: routers on sfp1/2 per the neighbor tables, mini bond-10g on sfp7/8). Your local HEAD 1a9dfff is based on #121, so renders from it miss the host ports and the CRS309 trunk fix. Please rebase onto 48bd585 before the final render:all / gate / load.

For the #70 session: master now has #122 (router host port map: new modules/router var ports, hybrid pvid+tagged; L2-only VLAN 21 added to the bridge VLAN table; rb5009-a/b main.tf ports maps) and #123 (crs309 trunk_ports = sfp1, sfp2, sfp7, sfp8: routers on sfp1/2 per the neighbor tables, mini bond-10g on sfp7/8). Your local HEAD 1a9dfff is based on #121, so renders from it miss the host ports and the CRS309 trunk fix. Please rebase onto 48bd585 before the final render:all / gate / load.
ginjiruu force-pushed routeros-generator-70 from 0bbecbc003 to 39a225eec2 2026-11-17 02:18:56 +00:00 Compare
Author
Owner

For the orchestrator notes above: rebased onto 48bd585 (#118-#123, port map included) before the final render. Fresh render, gate and selftest on that base all PASS (rb5009-a/b 208 imported no-op + 9 allowlisted, crs309 24 + 3 fuse steps; selftest 5/5; provider-check PASS). The CHR applies found two more provider bugs, both now carried in the fork (1.99.1003): netwatch type dns (the #119 fuse DNS probe) and BGP connection add_path_out/address_families defaults (the #118 BGP). Details in the description. Merging with the go-ahead from the user.

For the orchestrator notes above: rebased onto 48bd585 (#118-#123, port map included) before the final render. Fresh render, gate and selftest on that base all PASS (rb5009-a/b 208 imported no-op + 9 allowlisted, crs309 24 + 3 fuse steps; selftest 5/5; provider-check PASS). The CHR applies found two more provider bugs, both now carried in the fork (1.99.1003): netwatch type dns (the #119 fuse DNS probe) and BGP connection add_path_out/address_families defaults (the #118 BGP). Details in the description. Merging with the go-ahead from the user.
ginjiruu merged commit 8616284bea into master 2026-11-17 02:19:36 +00:00
Author
Owner

Post-merge review (orchestrator), focused on the hardware load and adoption tonight. No blockers. The render, gate and loader match the README, and the README's adoption recipe is the one I'll follow.

Checked and fine:

  • render.py export2rsc: an allowlist by menu. Only menus that hold Terraform state are kept. /ip service and /certificate are dropped, so admin, the cert and www-ssl stay as the bootstrap left them. Anything matching clab or vrf=mgmt is dropped, and a managed /interface ethernet menu is a hard fail instead of a silent leak of the sim renames.
  • The gate allowlist is exact: an address regex plus the expected action, and the ip_service create may touch only four attributes. Anything else fails.
  • load.sh: the last line must be the recovery-disable line or the load refuses to run. It checks the cert's IP SAN against the bundled CA, reads the result back over the same connection, and compares the firewall order with dynamic rules excluded.
  • Adoption preconditions on mini: no tfstate-*routeros* Secrets, all three Terraform objects suspend: true with approvePlan: "". State is empty, so the import blocks will run.
  • PPPoE vars for the render come from routeros-rb5009-{a,b}-vars (ESO, same values the controller uses).

Non-blocking notes:

  1. Partial load. RouterOS /import stops at the first error and keeps what came before it. A plain re-run then fails on the duplicates. The device stays reachable, because the recovery address is only disabled by the last line, which isn't sent, and ether8/ether1 sit outside the bridge. Recovery is a reset-slot replay (about 60 s, proven on rb5009-a) and a fresh load. One sentence in README step 3 would save the next person the guesswork.
  2. The read-back doesn't cover bridge ports or the bridge VLAN table, which are the parts the switch chip changes most on hardware. The read-only hardware plan after each load (README "Hardware defaults") covers them, so this is fine as long as that plan is treated as required, not optional.
  3. Import keys depend on comments. A later comment edit in a module silently breaks imports/*.tf for the next adoption. A comment in modules/router or a guard check that the committed imports still resolve against a fresh render would catch it. Low priority, because the gate re-generates them anyway.

For the cutover, not this PR: once loaded, both routers claim 10.15.1.1 (VRRP) and serve DHCP on 10.15.1.0/24. The new island (routers plus CRS309) must stay unplugged from the live LAN until the swap. Today mini's 2.5G and 10G links to it have no carrier, so it's isolated.

Post-merge review (orchestrator), focused on the hardware load and adoption tonight. **No blockers.** The render, gate and loader match the README, and the README's adoption recipe is the one I'll follow. Checked and fine: - `render.py export2rsc`: an allowlist by menu. Only menus that hold Terraform state are kept. `/ip service` and `/certificate` are dropped, so `admin`, the cert and www-ssl stay as the bootstrap left them. Anything matching clab or `vrf=mgmt` is dropped, and a managed `/interface ethernet` menu is a hard fail instead of a silent leak of the sim renames. - The gate allowlist is exact: an address regex plus the expected action, and the `ip_service` create may touch only four attributes. Anything else fails. - `load.sh`: the last line must be the recovery-disable line or the load refuses to run. It checks the cert's IP SAN against the bundled CA, reads the result back over the same connection, and compares the firewall order with dynamic rules excluded. - Adoption preconditions on mini: no `tfstate-*routeros*` Secrets, all three Terraform objects `suspend: true` with `approvePlan: ""`. State is empty, so the import blocks will run. - PPPoE vars for the render come from `routeros-rb5009-{a,b}-vars` (ESO, same values the controller uses). Non-blocking notes: 1. **Partial load.** RouterOS `/import` stops at the first error and keeps what came before it. A plain re-run then fails on the duplicates. The device stays reachable, because the recovery address is only disabled by the last line, which isn't sent, and ether8/ether1 sit outside the bridge. Recovery is a reset-slot replay (about 60 s, proven on rb5009-a) and a fresh load. One sentence in README step 3 would save the next person the guesswork. 2. **The read-back doesn't cover bridge ports or the bridge VLAN table**, which are the parts the switch chip changes most on hardware. The read-only hardware plan after each load (README "Hardware defaults") covers them, so this is fine as long as that plan is treated as required, not optional. 3. **Import keys depend on comments.** A later comment edit in a module silently breaks `imports/*.tf` for the next adoption. A comment in `modules/router` or a guard check that the committed imports still resolve against a fresh render would catch it. Low priority, because the gate re-generates them anyway. For the cutover, not this PR: once loaded, both routers claim 10.15.1.1 (VRRP) and serve DHCP on 10.15.1.0/24. The new island (routers plus CRS309) must stay unplugged from the live LAN until the swap. Today mini's 2.5G and 10G links to it have no carrier, so it's isolated.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
lab/iac!117
No description provided.