Skip to content

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:

Terminal window
nac setup
nac init
nac validate
nac plan
nac apply
nac test

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.

The following options are available on every command:

OptionEnvironment VariableDefaultDescription
--configNAC_CONFIGnac.yamlPath to the configuration file
-v, --verbosityNAC_VERBOSITYWARNINGDEBUG, INFO, WARNING, ERROR or CRITICAL
--no-colorNO_COLORDisable colored output
--versionShow the version and exit

Every command except setup forwards additional arguments to the wrapped tool, for example a variable file to terraform plan:

Terminal window
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.

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.

Verifies the prerequisites and reports the resolved tool versions. It is a pre-flight check for both CI/CD and local use:

  • checks that uv is on the PATH if nac-validate or nac-test has no suitable local installation, and tenv if tools.terraform.version is set
  • resolves the terraform or tofu binary
  • checks that every variable in env.required is set, without printing the values
  • reports the resolved terraform/tofu, nac-validate and nac-test versions, and warns if nac-validate or nac-test are 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.

OptionDescription
--yes, --installSkip the confirmation prompt for the OpenTofu installation
--prewarmPre-warm the uvx cache for nac-validate and nac-test, skipped for tools resolved to a local installation

Runs terraform init (or tofu init) in the working directory.

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.

Runs terraform plan -out=plan.tfplan. With --artifacts, the plan is additionally written to plan.txt and plan.json using terraform show.

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.

OptionDescription
--auto-approveSkip the confirmation prompt when applying without a saved plan

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.

OptionDescription
--no-renderSkip 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 test between nac plan and nac apply can make the saved plan.tfplan stale, so that nac apply fails.
  • Parallel runs: running several nac test at 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.

Runs terraform destroy, which asks for confirmation unless --auto-approve is passed.

OptionDescription
--auto-approveSkip the confirmation prompt