Skip to content

Branch as Code Toolset

This document introduces the essential tools required to work with the as code structure used throughout this guide and in production. These tools form the foundation for defining, deploying, and managing Meraki environments using declarative configuration.

Terraform assumes full control over the lifecycle of the resources it manages. In the examples that follow, we create two networks that are fully managed as code. Pre-created and existing organization or datacenter networks will not be affected.

  • Python environment The lab guide is tested with Python version 3.12.10.
  • nac-validate Validates the data model before deployment by checking it against the predefined schema.
  • nac-test Validates the state of the network devices after deployment by comparing actual device state to the desired model.

The solution uses Terraform together with the Cisco Meraki Terraform Provider.

The provider offers a comprehensive set of resources and data sources for managing organizations, networks, devices, SSIDs, VLANs, traffic shaping, and other Dashboard configurations entirely as code. It uses the Meraki Dashboard REST API to convert declarative Terraform definitions into actual network state.

resource "meraki_organization" "example" {
name = "Sample Organization"
management_details = [
{
name = "MSP ID"
value = "123456"
}
]
}

The solution uses Terraform Network-as-Code Cisco Meraki Module.
A Terraform module is a container for multiple resources and serves as a reusable building block. While a resource represents a single API object, a module can orchestrate several resources to form a complete configuration pattern. In this workflow, Terraform modules consume the YAML input and apply the necessary logic, transforming the YAML into Terraform structures such as maps, objects, and lists of objects.

module "meraki" {
source = "netascode/nac-meraki/meraki"
yaml_files = ["organizations_admins.yaml"]
}

Where organizations_admins.yaml are defined as:

meraki:
domains:
- name: EMEA
administrator:
name: Administrator
organizations:
- name: Sample Organization
admins:
- name: superadmin
email: admin@foobar.com
authentication_method: Email
org_access: full

The Terraform provider then takes this desired state from the modules and translates it into the required calls to the Meraki API, ensuring that the real network configuration matches the declared intent.

The solution also includes a Template Rendering Module for rendering templates. This module merges all YAML templates and configuration files into a single output file, which is particularly useful for validation. At this time, only network-level templates are supported.

This is useful when defining templates for specific features or configurations that need to be applied across multiple resources. For example, you may want to create multiple identical branches where only a subset of parameters—such as IP addressing or device serial numbers—differs from branch to branch.

module "meraki" {
source = "github.com/netascode/terraform-meraki-nac-meraki"
yaml_directories = ["data"]
write_model_file = "merged_configuration.nac.yaml"
}

In this sample, the module merges all network templates (*.yaml files) under the data/ folder and creates merged_configuration.nac.yaml. In v1, this merge process required an additional manual step. That step is no longer required in v2.

Branch as Code is designed to be executed through CI/CD pipelines so that validation, planning, deployment, and testing can run in a consistent and repeatable way.

Typical pipeline flow includes:

  • Validate (format checks, syntax validation, semantic validation)
  • Plan (preview infrastructure changes)
  • Deploy (apply approved changes)
  • Test (automated post-deployment verification)

In this learning lab, we use GitHub Actions to execute both:

  • The full end-to-end pipeline
  • Individual tasks such as syntax validation, semantic validation, and automated testing

This allows you to run complete delivery workflows as well as focused checks during development and troubleshooting.