· Announcements · 6 min read
Introducing nac: One CLI for the Complete Network as Code Workflow
A single command line tool to validate, plan, apply and test, and Terraform modules that ship their own schema, validation rules and test templates. NX-OS is the first architecture to fully support it.
Every Network as Code repository follows the same workflow, regardless of the architecture: validate the data model, plan the changes, apply them and test the result. Until now, each of these steps meant a different tool with its own options: terraform or tofu, nac-validate and nac-test. On top of that, the schema, the semantic validation rules and the test templates had to be sourced and kept in sync with the version of the Terraform module.
Today we are introducing two changes that make this a lot simpler: the new nac umbrella CLI, which works with every Network as Code architecture, and Terraform modules that ship everything needed for the complete workflow. NX-OS is the first architecture to fully support both.
Meet nac
nac is a single CLI for the whole workflow. The same commands work on a laptop and in a CI/CD pipeline:
nac setup # verify prerequisites and report resolved tool versionsnac init # terraform/tofu initnac validate # syntactic and semantic validation of the data modelnac plan # terraform/tofu plan -> plan.tfplannac apply # apply the saved plannac test # verify the deployed configuration against the data modelnac destroy # destroy the managed infrastructureIt is published on PyPI as nac-cli and installed with uv:
uv tool install nac-cliMake sure to install nac-cli: the nac package on PyPI is a different, unrelated package, so don’t use pip install nac or uvx nac.
Under the hood, nac takes care of the toolchain:
- One configuration file, often none at all: an optional
nac.yamlat the root of the repository describes where the data model, schema, rules and test templates are located, which Terraform engine to use and which environment variables are required. Every field has a sensible default, and modules can provide their own defaults, so a repository following the usual conventions typically doesn’t need anac.yaml. - Managed toolchain:
nac-validateandnac-testare used from a local installation if available, or run viauvxotherwise, so they don’t have to be installed separately. If neitherterraformnortofuis installed,nac setupcan download OpenTofu for you. - Tested versions: a module can declare the
nac-validateandnac-testversions it was tested with.nacpicks a compatible version by default and warns if you are using a version outside of the tested range. - Pass-through: arguments not known to
nacare forwarded to the wrapped tool, for examplenac plan -var-file=prod.tfvars, and its exit code is returned.naccan therefore replace the individual tool calls in a pipeline without losing any options. - Pipeline friendly:
--artifactswrites the output of each command to a file, such asvalidate.txtorplan.json, ready to be collected by your CI/CD system.
Schema, Rules and Tests Ship with the Module
A data model is only as good as the guardrails around it. Schema validation catches typos and invalid values, semantic rules catch configuration that is valid YAML but makes no sense on the network, and tests verify that the device actually reflects the intended state.
Starting now, a Network as Code Terraform module can include a nac/ directory that contains all of this, versioned together with the module itself:
nac/├── manifest.yaml # tested tool versions and nac.yaml defaults├── schema.yaml # the full data model schema├── rules/ # semantic validation rules└── tests/templates/ # test templates for nac-testAfter nac init has downloaded the module, nac validate and nac test pick these up automatically. There is nothing to copy and nothing to keep in sync: when you upgrade the module, the schema, rules and tests are upgraded with it. Your own schema, rules and test templates still work as before and take precedence. See Packaged Schema and Rules for the details.
A module ships the full schema of its data model, together with a semantic validation rule and a test template that demonstrate the concepts. This lets you experience the complete Network as Code workflow, from validation to testing, out of the box, and gives you a starting point for writing your own rules and tests.
NX-OS Leads the Way
The NX-OS module is the first to fully support the new workflow, starting with version 0.4.1. It ships:
- the complete NX-OS data model schema
- a semantic rule verifying that every VLAN interface (SVI) references a VLAN defined on the same device
- a test template verifying VLANs and VLAN configuration on the device via NX-API
- module defaults for
nac, including the render step and the requiredNXOS_USERNAMEandNXOS_PASSWORDenvironment variables
As a result, an NX-OS repository needs no nac.yaml at all. A data file and a short module block are all it takes:
nxos: devices: - name: SWITCH1 url: https://10.1.1.1 configuration: system: hostname: SWITCH1 feature: interface_vlan: true vlan: vlans: - id: 10 name: WEB interfaces: vlans: - id: 10 description: WEBmodule "nxos" { source = "netascode/nac-nxos/nxos" version = "0.4.1"
yaml_files = ["inventory.nac.yaml"]}From there, the complete workflow is just:
export NXOS_USERNAME=adminexport NXOS_PASSWORD=password
nac setupnac initnac validatenac plannac applynac testnac validate renders the data model to model.yaml, resolving variables, templates and global configuration in the module, and then validates it against the packaged schema and rules. This happens locally, without connecting to the device or requiring credentials, so it can run on every commit. Change the SVI to id: 20 without defining VLAN 20, and the semantic rule reports the issue before anything is sent to the device:
[RULE 302] Verify VLAN interface references VLAN definition
================================================================================VLAN INTERFACE WITHOUT VLAN DEFINITION================================================================================
Found 1 violation(s).
VLAN interfaces without a VLAN: • VLAN 20 is not defined in vlan.vlans Path: nxos.devices[name=SWITCH1].configuration.interfaces.vlans[id=20]
--------------------------------------------------------------------------------WHY THIS MATTERS:--------------------------------------------------------------------------------
A VLAN interface (SVI) for a VLAN that is not defined under vlan.vlans iscreated on the device, but stays down (no-vlan) and cannot route trafficuntil the VLAN is defined.
[…]
────────────────────────────────────────────────────────────────────────────────Validation Summary──────────────────────────────────────────────────────────────────────────────── ✓ Syntax validation: PASSED (1 files) ✗ Semantic validation: FAILED (1 violation)
• 1 HIGH severity violation (rules: 302)────────────────────────────────────────────────────────────────────────────────The full output also includes a recommended fix. After nac apply, nac test queries the device and verifies that VLAN 10 exists with the name WEB, and writes an HTML report to tests/results/.
Follow the NX-OS First Steps guide to try it yourself.
What’s Next
NX-OS is just the beginning. nac itself is architecture agnostic, and the other Network as Code modules will ship their schema, rules and test templates in the same way over the coming releases. Watch the changelogs for updates.
Get Started
- Install
nac: follow the installation guide. - Learn the commands: see Usage and the
nac.yamlreference. - Try it on NX-OS: start with First Steps.
We’d love to hear your feedback. Join our Webex Community to share your experience and ask questions.