Skip to content

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.

FieldDefaultDescription
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.defaultsdefaults.yaml if it exists in working_dirDefaults file added to the data of test
render.targetTerraform target rendering the data model before validation and testing, e.g. module.nxos.local_sensitive_file.model
render.outputPath of the rendered data model, e.g. model.yaml. Required if render.target is set.
validate.schemaSchema passed to nac-validate -s. If not set, nac-validate uses its own default.
validate.rulesRule directories passed to nac-validate -r. If not set, nac-validate uses its own default.
test.templatestests/templates if it exists in working_dirTemplates passed to nac-test -t. If not set, nac-test uses templates provided by the module or a bundle.
test.filterstests/filters if it exists in working_dirFilters passed to nac-test -f
test.outputtests/resultsOutput directory passed to nac-test -o
tools.terraform.enginetofu if on the PATH and working, else terraform, else the OpenTofu installed by nac setupterraform or tofu
tools.terraform.versionTerraform or OpenTofu version installed and used via tenv
tools.nac_validatelatest compatible with the tested versionVersion or version specifier of nac-validate, e.g. 1.2.0 or >=0.9,<1.0
tools.nac_testlatest compatible with the tested versionVersion 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:

  • validate uses render.output if render.target is set, else data.paths.
  • test uses render.output if render is configured, else data.paths, followed by data.defaults if 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.

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]

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.

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: 1
tools:
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_validate or tools.nac_test is 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, otherwise uvx downloads it.
  • Warnings: an explicitly configured version always takes precedence. If it is outside the compatible range, nac validate, nac test and nac setup print a warning, and a short note after the output if the command fails. Exit codes are never changed. Version ranges resolved by uvx, 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.

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: 1
tools:
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.resource is the resource address within the module. nac prefixes it with the address of the module from .terraform/modules/modules.json, so a module called as module "fabric" renders module.fabric.local_sensitive_file.model, and a module called from a local wrapper module module.wrapper.module.nxos.local_sensitive_file.model.
  • Precedence: settings in nac.yaml take precedence key by key. render: {output: data.yaml} keeps the render target of the module but changes the output file, a list such as env.required replaces the module’s list, and an explicit null, e.g. render: null, turns a module default off.
  • Scope: only render and env.required can be provided by a module. Settings of the repository itself, such as working_dir, data and tools, can only be set in nac.yaml. Schema, rules and test templates are picked up from the module by nac-validate and nac-test directly.
  • Rendered file: after the render step, nac validate and nac test check that render.output exists and fails otherwise, for example if the write_model_file variable of the module was changed without changing render.output as well.
  • Availability: module defaults are available after nac init has downloaded the module. nac setup lists the settings taken from the module. An invalid config section is ignored with a warning, while the tested versions of the manifest are still used.