Skip to content

Default Values

Default Values Purpose

When dealing with large configurations, it is important to have a way to set default values for certain keys, to avoid repeating the same values in multiple files and while making it easier to manage the configuration.

Each data model comes with certain default values based on common best practices.

These default values, based on common best practices, are embedded into the terraform module itself (for those technologies that use Terraform/OpenTofu).

For example, here is the default values file for ACI terraform module.

Default Values for ACI Terraform Module

In some cases these default values might not be appropriate for a specific environment, therefore those values can be overridden in the configuration files.

For example, if we want to change the default value of the unicast_routing attribute of an ACI bridge domain, we can do so by overriding the default value in the configuration file. The default value is set to true, but we want to set it to false for our specific environment.

defaults:
apic:
tenants:
bridge_domains:
unicast_routing: false

The YAML shown above will be typically saved as defaults.nac.yaml in the same directory as other data model files (typically in the “data” directory).

For example, your ACI “data” directory can contain the defaults.nac.yaml file as shown below.

Data Directory with Defaults File

The default values follow the same structure and hirarchy as the data model, where everything is defined under a defaults root element. Lists in the data model (e.g., tenants) are defined as dictionaries in the defaults section.

Default Values Behavior at Runtime

There can be two sources for default values:

  1. Embedded Defaults: These are the default values that come with the terraform module itself, as shown in the example above.
  2. Local Defaults: These are the default values defined in a defaults.nac.yaml file in the same directory as the data model files.

At run-time the default values are merged with the configuration data, where the local defaults takes precedence over the embedded defaults. This means that if a key is present in both the local defaults and the embedded defaults, the value from the local defaults will be used.

Below diagram shows the different default sources and how they are merged at runtime.

Default Values Merge at Runtime

In the diagram above, the “blue” defaults.yaml represents the local defaults file, while the “green” defaults.yaml represents the embedded defaults from the terraform module.

And the “yellow” defaults.yaml represents the merged defaults that are used at runtime.

The path to this “yellow” defaults.yaml file is passed to the terraform module as an input variable, as shown below.

module "aci" {
source = "netascode/nac-aci/aci"
version = "1.0.0"
yaml_directories = ["data"]
manage_access_policies = true
manage_fabric_policies = true
manage_pod_policies = true
manage_node_policies = true
manage_interface_policies = true
manage_tenants = true
write_default_values_file = "./defaults.yaml"
}

The write_default_values_file input variable specifies the path to the merged defaults file that will be created at runtime. This file will contain the merged defaults from both the embedded defaults and the local defaults.