RouterOS 004: Import strategy for live devices; singleton rules #66

Closed
opened 2026-11-14 01:41:04 +00:00 by ginjiruu · 1 comment
Owner

Part of #43

Refs: lab/iac#45
Migrated from router-as-code tracker 004 (docs/routeros/tracker in this repo history). Research notes: docs/routeros/notes/.

Rules for getting config under management that already exists on a device,
and for objects Terraform cannot fully own. Findings in note §2 (all
verified in provider source).

Import mechanics

  • terraform import (and import {} blocks) resolve by name or
    field=value, not just *hex ids (provider ImportStateCustomContext).
    For the bench flow prefer writing config + import blocks over import CLI
    by hand; it's repeatable for the third device.
  • Bootstrap-owned objects (mgmt SVI/IP, www-ssl, users, keys) are NOT
    imported. Terraform's graph must not contain them (protected set, #002).

Singleton rules

  • Settings objects (/ip dns, /ip service, /system identity, /snmp,
    *_settings menus...) cannot be deleted over the API; provider delete only
    drops state. Consequences: never expect destroy to revert them; deleting a
    managed singleton from config = removing it from state, leaving the device
    attribute set. Manage deliberately, document each in the tree.
  • Pre-existing objects that are not singletons (default firewall entries,
    default routes on live bench devices): either import and manage, or remove
    by hand during bench prep, so plan starts truthful.

Done when

  • Documented per-workspace: what is protected, what was imported and by which
    command, and a one-page "adopt a previously hand-configured device" recipe.
Part of #43 Refs: lab/iac#45 Migrated from router-as-code tracker 004 (docs/routeros/tracker in this repo history). Research notes: docs/routeros/notes/. Rules for getting config under management that already exists on a device, and for objects Terraform cannot fully own. Findings in note §2 (all verified in provider source). ## Import mechanics - `terraform import` (and `import {}` blocks) resolve by `name` or `field=value`, not just `*hex` ids (provider `ImportStateCustomContext`). For the bench flow prefer writing config + import blocks over `import` CLI by hand; it's repeatable for the third device. - Bootstrap-owned objects (mgmt SVI/IP, www-ssl, users, keys) are NOT imported. Terraform's graph must not contain them (protected set, #002). ## Singleton rules - Settings objects (`/ip dns`, `/ip service`, `/system identity`, `/snmp`, `*_settings` menus...) cannot be deleted over the API; provider delete only drops state. Consequences: never expect `destroy` to revert them; deleting a managed singleton from config = removing it from state, leaving the device attribute set. Manage deliberately, document each in the tree. - Pre-existing objects that are not singletons (default firewall entries, default routes on live bench devices): either import and manage, or remove by hand during bench prep, so `plan` starts truthful. ## Done when - Documented per-workspace: what is protected, what was imported and by which command, and a one-page "adopt a previously hand-configured device" recipe.
Author
Owner

Done. Convention + recipe live: docs/routeros/adoption.md (protected set = bootstrap-owned mgmt/www-ssl/users, never in graph) and the render gate carries the per-device import allowlist as the record of what was imported. Proven end-to-end three times at adoption: crs309 (15 imports), rb5009-a/b (166-167 imports + 6 allowlisted), all adopted with plan clean and no drift (iac#129-133). Provider import idiom: one unique field=value.

Done. Convention + recipe live: docs/routeros/adoption.md (protected set = bootstrap-owned mgmt/www-ssl/users, never in graph) and the render gate carries the per-device import allowlist as the record of what was imported. Proven end-to-end three times at adoption: crs309 (15 imports), rb5009-a/b (166-167 imports + 6 allowlisted), all adopted with plan clean and no drift (iac#129-133). Provider import idiom: one unique field=value.
Sign in to join this conversation.
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#66
No description provided.