Branch as Code Toolset
This document introduces the essential tools required to operate the “as code” structure used throughout this guide. 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 will create new organizations and networks. Existing organizations and networks will not be affected.
Required Tools
Section titled “Required Tools”- Terraform 1.9.0 or later
- Git
- A text editor or IDE, such as Visual Studio Code
- Sample Git Repository for Unified Branch as Code
Optional Tools
Section titled “Optional Tools”- 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.
Terraform Provider
Section titled “Terraform Provider”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.
Example Resource
Section titled “Example Resource”resource "meraki_organization" "example" { name = "Sample Organization" management_details = [ { name = "MSP ID" value = "123456" } ]}Terraform Modules
Section titled “Terraform Modules”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.
Example Module
Section titled “Example Module”hclmodule "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: fullThe 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.
Template Rendering Module
Section titled “Template Rendering Module”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, the 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 "model" { source = "netascode/nac-meraki/meraki//modules/model"
yaml_directories = ["data/"] write_model_file = "model.yaml"}In this sample above, the module will merge all network templates (*.yaml files) under the data/ folder and create a merged model.yaml file.