Hello Meraki Community,
I am currently working on configuring Spanning Tree Protocol (STP) settings for my Meraki switches using Terraform, but I have run into some challenges that I hope to get some advice on.
Background
I am trying to set up STP configurations for different types of switches in my Meraki network, specifically for access, core, and external switches. The configurations need to handle both stacked and standalone switches.
Current Setup
I have implemented a Terraform configuration that attempts to create a single meraki_switch_stp resource with conditional logic to determine whether to use switch serial numbers or stack IDs based on whether the switches are stacked.
Here’s a simplified snippet of my Terraform configuration:
resource "meraki_switch_stp" "example" {
network_id = jsondecode(data.aws_secretsmanager_secret_version.meraki_network_id.secret_string)[var.meraki_network_id]
rstp_enabled = true
stp_bridge_priority = [
{
stp_priority = var.access_stp_priority
switches = var.enable_access_switch_stack ? [] : [
jsondecode(data.aws_secretsmanager_secret_version.meraki_switch_serials.secret_string)[var.access_switch1_serial],
jsondecode(data.aws_secretsmanager_secret_version.meraki_switch_serials.secret_string)[var.access_switch2_serial]
]
stacks = var.enable_access_switch_stack ? [
jsondecode(data.aws_secretsmanager_secret_version.stack_ids.secret_string)[var.access_stack_id]
] : []
},
# Repeated configurations for core and external switches...
]
}
Issue Encountered
When I run terraform apply, I receive the following error:
Error: Client Error
Failed to configure object (POST/PUT), got error: HTTP Request failed: StatusCode 400, JSON error: ["Each STP configuration must correspond to at least one switch or switch stack."]
It seems that when I enable stacking for either access or core switches, the corresponding switches list ends up empty, leading to the API rejection. (Although it still corresponds to a switch stack...)
Previous Attempts
I have attempted to create multiple resources for each scenario i.e.:
- core-stack-stp-configuration
- access-stack-stp-configuration
- core-switch-stp-configuration
- access-switch-stp-configuration
- external-switch-stp-configuration (Never stacked)
And used a count argument to decide whether the stack resource is deployed or non stack resource, i.e.
If enable_core_switch_stack = True
Delpoy:
core-stack-stp-configuration
If enable_core_switch_stack = False
Deploy:
core-switch-stp-configuration
However they continue to overwrite each other leaving me with just the external switches assigned with an STP priority.
Request for Advice
I would appreciate any insights or suggestions on the following:
- How to ensure that at least one switch or stack is included in the configuration without leading to an empty list.
- Best practices for structuring the Terraform resource to handle both stacked and standalone configurations effectively.
- Any experiences or tips you might have when working with the Meraki API and Terraform for STP configurations.
Thank you for your help!
Archie 🙂