· 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:

Terminal window
nac setup # verify prerequisites and report resolved tool versions
nac init # terraform/tofu init
nac validate # syntactic and semantic validation of the data model
nac plan # terraform/tofu plan -> plan.tfplan
nac apply # apply the saved plan
nac test # verify the deployed configuration against the data model
nac destroy # destroy the managed infrastructure

It is published on PyPI as nac-cli and installed with uv:

Terminal window
uv tool install nac-cli

Make 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.yaml at 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 a nac.yaml.
  • Managed toolchain: nac-validate and nac-test are used from a local installation if available, or run via uvx otherwise, so they don’t have to be installed separately. If neither terraform nor tofu is installed, nac setup can download OpenTofu for you.
  • Tested versions: a module can declare the nac-validate and nac-test versions it was tested with. nac picks a compatible version by default and warns if you are using a version outside of the tested range.
  • Pass-through: arguments not known to nac are forwarded to the wrapped tool, for example nac plan -var-file=prod.tfvars, and its exit code is returned. nac can therefore replace the individual tool calls in a pipeline without losing any options.
  • Pipeline friendly: --artifacts writes the output of each command to a file, such as validate.txt or plan.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-test

After 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 required NXOS_USERNAME and NXOS_PASSWORD environment 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:

inventory.nac.yaml
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: WEB
main.tf
module "nxos" {
source = "netascode/nac-nxos/nxos"
version = "0.4.1"
yaml_files = ["inventory.nac.yaml"]
}

From there, the complete workflow is just:

Terminal window
export NXOS_USERNAME=admin
export NXOS_PASSWORD=password
nac setup
nac init
nac validate
nac plan
nac apply
nac test

nac 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:

Terminal window
[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 is
created on the device, but stays down (no-vlan) and cannot route traffic
until 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

  1. Install nac: follow the installation guide.
  2. Learn the commands: see Usage and the nac.yaml reference.
  3. 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.

Share:
Back to Blog

Related Posts

View All Posts »