Configuration
A single nac.yaml at the root of the repository configures all commands. Its location can be changed with --config or NAC_CONFIG. Every field is optional, and a missing nac.yaml is treated like an empty one.
Reference
Section titled “Reference”| Field | Default | Description |
|---|---|---|
working_dir | . | Directory in which terraform/tofu runs |
data.paths | [data/] | Data model files or directories used by validate and test when no rendering applies |
data.defaults | defaults.yaml if it exists in working_dir | Defaults file added to the data of test |
render.target | Terraform target rendering the data model before validation and testing, e.g. module. | |
render.output | Path of the rendered data model, e.g. model.yaml. Required if render.target is set. | |
validate.schema | Schema passed to nac-validate -s. If not set, nac-validate uses its own default. | |
validate.rules | Rule directories passed to nac-validate -r. If not set, nac-validate uses its own default. | |
test.templates | tests/templates if it exists in working_dir | Templates passed to nac-test -t. If not set, nac-test uses templates provided by the module or a bundle. |
test.filters | tests/filters if it exists in working_dir | Filters passed to nac-test -f |
test.output | tests/results | Output directory passed to nac-test -o |
tools. | tofu if on the PATH and working, else terraform, else the OpenTofu installed by nac setup | terraform or tofu |
tools. | Terraform or OpenTofu version installed and used via tenv | |
tools. | latest compatible with the tested version | Version or version specifier of nac-validate, e.g. 1.2.0 or >=0.9,<1.0 |
tools.nac_test | latest compatible with the tested version | Version or version specifier of nac-test, e.g. 2.0.0 or >=2.0,<3.0 |
env.required | [] | Environment variables checked by nac setup, plan, apply, destroy and test. Their values are never printed. |
The data used by the commands follows from the configuration:
validateusesrender.outputifrender.targetis set, elsedata.paths.testusesrender.outputifrenderis configured, elsedata.paths, followed bydata.defaultsif configured.
If render.target is set, both validate and test render render.output first. nac test --no-render skips this step and uses the existing file.
Examples
Section titled “Examples”An ACI repository without rendering. test adds defaults.yaml automatically if it exists at the root of the repository:
env: required: [ACI_URL, ACI_USERNAME, ACI_PASSWORD]An NX-OS repository, where the data model is rendered to model.yaml by the Terraform module before it is validated and tested:
tools: terraform: engine: tofu
render: target: module.nxos.local_sensitive_file.model output: model.yaml
env: required: [NXOS_USERNAME, NXOS_PASSWORD]The NX-OS module provides render and env as module defaults and writes model.yaml by default, so only tools remains, and without it no nac.yaml is needed at all. Add model.yaml to .gitignore, as it is generated on every run.
The same NX-OS repository with every field set explicitly:
working_dir: .
data: paths: [data/] defaults: null
render: target: module.nxos.local_sensitive_file.model output: model.yaml
validate: schema: .schema.yaml rules: [.rules]
test: templates: tests/templates filters: tests/filters output: tests/results
tools: terraform: engine: tofu version: "1.9.5" nac_validate: ">=0.9,<1.0" nac_test: ">=2.0,<3.0"
env: required: [NXOS_USERNAME, NXOS_PASSWORD]Tool Versions
Section titled “Tool Versions”Terraform/OpenTofu: if tools.terraform.engine is set, that binary must be on the PATH, and nac never falls back to the other one. Otherwise, the binary is looked up on the PATH: tofu first, terraform otherwise. A binary that fails to run <binary> version is skipped, for example a version manager shim such as tenv’s after its last version was uninstalled. If neither is found, nac setup offers to download and cache a verified OpenTofu binary, without requiring a package manager or tenv, and later commands use the cached binary. Setting tools.terraform.version uses tenv to install and use that version. In this case, binaries on the PATH aren’t checked with version, as the shim installs the pinned version on first use.
nac-validate/nac-test: a local installation on the PATH is used if it satisfies tools.nac_validate or tools.nac_test (any local version if not set). Otherwise, the tool is run via uvx, e.g. uvx --from nac-validate==<version> nac-validate. If no version is set, uvx uses the latest release, or the latest release compatible with the tested version of the module. nac setup reports whether each tool was resolved to a local installation or uvx. uv is only required if a tool is run via uvx. If it is missing in that case, nac fails with a message naming the tool and the version to install locally instead.
Tested Versions
Section titled “Tested Versions”A Network as Code Terraform module can include a nac/manifest.yaml, next to its schema, rules and test templates, listing the nac-validate and nac-test versions it was tested with:
schema: 1tools: nac-validate: "2.0.0" nac-test: "2.0.0"Terraform, OpenTofu and provider versions are not part of the manifest, as they are already constrained by the versions.tf of the module.
After nac init has downloaded the module, nac finds the manifest via .terraform/modules/modules.json. If several modules include one, the one closest to the root module is used, so a local wrapper module works as well. The manifest is only a hint and is never enforced. Without a manifest, for example before the first nac init, nothing changes.
- Defaults: if
tools.nac_validateortools.nac_testis not set, the latest release compatible with the tested version is used instead of the latest release overall. A local installation is used if it is in that range, otherwiseuvxdownloads it. - Warnings: an explicitly configured version always takes precedence. If it is outside the compatible range,
nac validate,nac testandnac setupprint a warning, and a short note after the output if the command fails. Exit codes are never changed. Version ranges resolved byuvx, such as>=1.0, are not checked, as the resulting version isn’t known up front.
Compatible means the tested version or newer, up to the next major version, or the next minor version for 0.x versions. A tested version 2.0.0 allows >=2.0.0,<3, a tested version 0.13.1 allows >=0.13.1,<0.14.
Module Defaults
Section titled “Module Defaults”The nac/manifest.yaml of a module can also provide nac.yaml defaults in a config section, so that repositories using the module don’t need to repeat them:
schema: 1tools: nac-validate: "2.1.0" nac-test: "2.1.0"config: render: resource: local_sensitive_file.model output: model.yaml env: required: [NXOS_USERNAME, NXOS_PASSWORD]- Render target:
render.resourceis the resource address within the module.nacprefixes it with the address of the module from.terraform/modules/modules.json, so a module called asmodule "fabric"rendersmodule.fabric.local_sensitive_file.model, and a module called from a local wrapper modulemodule.wrapper.module.nxos.local_sensitive_file.model. - Precedence: settings in
nac.yamltake precedence key by key.render: {output: data.yaml}keeps the render target of the module but changes the output file, a list such asenv.requiredreplaces the module’s list, and an explicitnull, e.g.render: null, turns a module default off. - Scope: only
renderandenv.requiredcan be provided by a module. Settings of the repository itself, such asworking_dir,dataandtools, can only be set innac.yaml. Schema, rules and test templates are picked up from the module bynac-validateandnac-testdirectly. - Rendered file: after the render step,
nac validateandnac testcheck thatrender.outputexists and fails otherwise, for example if thewrite_model_filevariable of the module was changed without changingrender.outputas well. - Availability: module defaults are available after
nac inithas downloaded the module.nac setuplists the settings taken from the module. An invalidconfigsection is ignored with a warning, while the tested versions of the manifest are still used.