Skip to content

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 nac and to run nac-validate and nac-test
  • OpenTofu or Terraform 1.9.0 or later. If neither is installed, nac setup can download OpenTofu for you.
  • Your preferred text editor / IDE (such as Visual Studio Code)
  • A Meraki Dashboard account with access to an organization
  1. nac is published on PyPI as nac-cli:

    Terminal window
    uv tool install nac-cli
  2. 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.

  3. 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"
  4. In a new project directory, create a file named data/networks.nac.yaml with the following content. Replace the domain, administrator and organization name with your own:

    ---
    meraki:
    domains:
    - name: cisco.com # Replace with your domain
    administrator:
    name: admin@cisco.com # Replace with your admin email
    organizations:
    - name: Demo Organization # Replace with your organization
    managed: false
    networks:
    - name: Branch-Office-Demo
    product_types:
    - appliance
    - switch
    - wireless
    time_zone: America/Los_Angeles
    notes: Branch office demo network
    tags:
    - demo
    - branch
    wireless:
    ssids:
    - name: Corporate-WiFi
    ssid_number: "0"
    enabled: true
    auth_mode: psk
    psk: DemoPassword123
    encryption_mode: wpa
    wpa_encryption_mode: WPA2 only
    ip_assignment_mode: Bridge mode
    use_vlan_tagging: true
    default_vlan_id: 100

    This file describes the desired state of a network named Branch-Office-Demo in 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: false tells 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.

  5. 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-meraki module reads all YAML files in the data directory and maps their contents to the underlying Meraki provider resources automatically. It also writes the rendered data model, with all configuration templates resolved, to model.yaml, which is the file that nac validates and tests.

  6. Verify the prerequisites, then download the provider and module:

    Terminal window
    nac setup
    nac init
  7. Terminal window
    nac validate

    This renders model.yaml and 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.

  8. Terminal window
    nac plan
    nac apply

    nac plan saves the changes required to reach the desired state to plan.tfplan, and nac apply pushes exactly this plan to the Meraki Dashboard via the Dashboard API.

  9. Terminal window
    nac test

    This runs the tests packaged with the module against the Meraki Dashboard and verifies that the configuration in model.yaml was applied, for example that the network Branch-Office-Demo exists with the configured product types, time zone, notes and tags. The results, including an HTML report, are written to tests/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.