Usage
All commands are run from the root of the repository, where nac.yaml is located if used. The file is optional: without it, every field falls back to its default. Modules can provide their settings, including the environment variables required by the Terraform provider, as module defaults, so in many cases no nac.yaml is needed.
A complete run of the workflow looks like this:
nac setupnac initnac validatenac plannac applynac testRequired Environment Variables
Section titled “Required Environment Variables”The variables listed in env.required, in nac.yaml or provided by the module, are checked by nac setup and again by nac plan, nac apply, nac destroy and nac test, the commands that connect to devices. If one isn’t set, the command fails before running the wrapped tool, without printing any values. Module defaults are only known after nac init has downloaded the module, so these later checks also cover variables that nac setup couldn’t check when run before nac init. nac init and nac validate don’t check them, and --help works without them.
Global Options
Section titled “Global Options”The following options are available on every command:
| Option | Environment Variable | Default | Description |
|---|---|---|---|
--config | NAC_CONFIG | nac.yaml | Path to the configuration file |
-v, --verbosity | NAC_VERBOSITY | WARNING | DEBUG, INFO, WARNING, ERROR or CRITICAL |
--no-color | NO_COLOR | Disable colored output | |
--version | Show the version and exit |
Pass-Through Arguments
Section titled “Pass-Through Arguments”Every command except setup forwards additional arguments to the wrapped tool, for example a variable file to terraform plan:
nac plan -var-file=prod.tfvars--help shows the options of nac followed by the options of the wrapped tool. The exit code of the wrapped tool is returned, so nac can be used in CI/CD pipelines the same way as the wrapped tools.
Artifacts
Section titled “Artifacts”All commands except setup accept --artifacts, which also writes the output of the command to <command>.txt in the working directory, for example validate.txt or apply.txt. This is useful to collect the results of a CI/CD pipeline.
Commands
Section titled “Commands”nac setup
Section titled “nac setup”Verifies the prerequisites and reports the resolved tool versions. It is a pre-flight check for both CI/CD and local use:
- checks that
uvis on thePATHifnac-validateornac-testhas no suitable local installation, andtenviftools.terraform.versionis set - resolves the
terraformortofubinary - checks that every variable in
env.requiredis set, without printing the values - reports the resolved
terraform/tofu,nac-validateandnac-testversions, and warns ifnac-validateornac-testare outside the tested versions of the module
The command fails with a non-zero exit code if a prerequisite is missing. Warnings about tested versions never fail it.
| Option | Description |
|---|---|
--yes, --install | Skip the confirmation prompt for the OpenTofu installation |
--prewarm | Pre-warm the uvx cache for nac-validate and nac-test, skipped for tools resolved to a local installation |
nac init
Section titled “nac init”Runs terraform init (or tofu init) in the working directory.
nac validate
Section titled “nac validate”Runs nac-validate against the data model, using the validate.schema and validate.rules from nac.yaml.
If render.target is configured, a targeted terraform apply -target=<target> -auto-approve is run first to render the data model to render.output, which is then validated instead of data.paths. This is used by architectures that resolve variables and templates in the Terraform module, such as NX-OS. The output of the render step is only shown if it fails, otherwise a short Render Summary with the target and render.output is printed instead. With --verbosity INFO or DEBUG, the output is always shown.
Schema and rules packaged with the Terraform module or with bundles in nac/bundles/ are loaded by default (see Packaged Schema and Rules). To opt out, set NAC_VALIDATE_ARTIFACTS=false or pass --no-artifacts.
nac plan
Section titled “nac plan”Runs terraform plan -out=plan.tfplan. With --artifacts, the plan is additionally written to plan.txt and plan.json using terraform show.
nac apply
Section titled “nac apply”If a saved plan plan.tfplan exists in the working directory, it is applied with terraform apply plan.tfplan and deleted after a successful apply. Otherwise, terraform apply is run interactively with its usual confirmation prompt.
| Option | Description |
|---|---|
--auto-approve | Skip the confirmation prompt when applying without a saved plan |
nac test
Section titled “nac test”Runs nac-test against the data model, using the test.templates, test.filters and test.output from nac.yaml. The data model is render.output if render is configured, else data.paths, followed by data.defaults if configured.
If render.target is configured, the data model is rendered first, the same way as by nac validate, so the tests never run against a missing or outdated render.output, for example in a fresh CI/CD checkout or after the data model was changed. If render.output is already up to date, the targeted apply leaves it unchanged.
With --no-render, the render step is skipped and the existing render.output is tested, for example one passed on from an earlier CI/CD job. This also avoids that nac test needs terraform/tofu and access to the Terraform state. The command fails if render.output doesn’t exist.
| Option | Description |
|---|---|
--no-render | Skip the render step and test the existing render.output |
The render step is a terraform apply and therefore takes the state lock and can update the state, for example when render.output has to be written again. Use --no-render in these cases:
- Saved plan: running
nac testbetweennac planandnac applycan make the savedplan.tfplanstale, so thatnac applyfails. - Parallel runs: running several
nac testat the same time, or alongside another Terraform command, can fail because the state is locked.
Templates, filters and Jinja tests packaged with the Terraform module or with bundles in nac/bundles/ are loaded by default. To opt out, set NAC_TEST_ARTIFACTS=false or pass --no-artifacts.
nac destroy
Section titled “nac destroy”Runs terraform destroy, which asks for confirmation unless --auto-approve is passed.
| Option | Description |
|---|---|
--auto-approve | Skip the confirmation prompt |