First Steps
This guide walks you through deploying a network to a Meraki organization using Network as Code, starting from a single YAML file and a one-line Terraform module. The whole workflow is driven by the nac CLI, which wraps Terraform/OpenTofu, nac-validate and nac-test. Because Terraform assumes full control of the lifecycle of the resources it creates, this example focuses on network configuration that won’t impact existing organization settings.
Prerequisites:
- uv, used to install
nacand to runnac-validateandnac-test - OpenTofu or Terraform 1.9.0 or later. If neither is installed,
nac setupcan download OpenTofu for you. - Your preferred text editor / IDE (such as Visual Studio Code)
- A Meraki Dashboard account with access to an organization
-
Install the
Section titled “Install the nac CLI”nacCLInacis published on PyPI asnac-cli:Terminal window uv tool install nac-cli -
Generate an API Key
Section titled “Generate an API Key”API access must be enabled for the organization under Organization > Settings > Dashboard API access in the Meraki Dashboard. Then generate an API key in your user profile under API keys and access.
-
Set Environment Variables
Section titled “Set Environment Variables”The Meraki provider and the tests authenticate using the API key. Set the following in your terminal:
Terminal window export MERAKI_API_KEY="your-api-key-here" -
Create Your First Data File
Section titled “Create Your First Data File”In a new project directory, create a file named
data/networks.nac.yamlwith the following content. Replace the domain, administrator and organization name with your own:---meraki:domains:- name: cisco.com # Replace with your domainadministrator:name: admin@cisco.com # Replace with your admin emailorganizations:- name: Demo Organization # Replace with your organizationmanaged: falsenetworks:- name: Branch-Office-Demoproduct_types:- appliance- switch- wirelesstime_zone: America/Los_Angelesnotes: Branch office demo networktags:- demo- branchwireless:ssids:- name: Corporate-WiFissid_number: "0"enabled: trueauth_mode: pskpsk: DemoPassword123encryption_mode: wpawpa_encryption_mode: WPA2 onlyip_assignment_mode: Bridge modeuse_vlan_tagging: truedefault_vlan_id: 100This file describes the desired state of a network named
Branch-Office-Demoin an existing organization: its product types, time zone, notes and tags, and a single SSID with WPA2-PSK authentication, bridged to VLAN 100. The structure follows the Meraki Dashboard: domains contain organizations, which contain networks.managed: falsetells the module to look up the existing organization by its name instead of creating it. Without it, Terraform creates the organization and manages its lifecycle. -
Create the Terraform Configuration
Section titled “Create the Terraform Configuration”In the project directory, create a file named
main.tf:module "meraki" {source = "netascode/nac-meraki/meraki"version = "0.13.0"yaml_directories = ["data"]}This is the only Terraform configuration required. The
nac-merakimodule reads all YAML files in thedatadirectory and maps their contents to the underlying Meraki provider resources automatically. It also writes the rendered data model, with all configuration templates resolved, tomodel.yaml, which is the file thatnacvalidates and tests. -
Set Up and Initialize
Section titled “Set Up and Initialize”Verify the prerequisites, then download the provider and module:
Terminal window nac setupnac init -
Validate the Data Model
Section titled “Validate the Data Model”Terminal window nac validateThis renders
model.yamland validates it against the schema and rules packaged with the module, catching errors such as typos, invalid values or references to group policies that don’t exist, before anything is sent to the Meraki Dashboard. -
Plan and Apply the Configuration
Section titled “Plan and Apply the Configuration”Terminal window nac plannac applynac plansaves the changes required to reach the desired state toplan.tfplan, andnac applypushes exactly this plan to the Meraki Dashboard via the Dashboard API. -
Test the Deployment
Section titled “Test the Deployment”Terminal window nac testThis runs the tests packaged with the module against the Meraki Dashboard and verifies that the configuration in
model.yamlwas applied, for example that the networkBranch-Office-Demoexists with the configured product types, time zone, notes and tags. The results, including an HTML report, are written totests/results/.
Congratulations! You have deployed and tested your first Meraki network using Network as Code. Continue with Going Further to learn how to extend the configuration, use default values, organize larger deployments and remove resources.