- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Terraform - meraki_networks_appliance_ports wont update all ports in a list of ports
Hi guys, not sure if my title is clear enough as I'm not sure how to word it. I'm not sure if this is terraform issue or provider issue.
I have an appliance in an existing network on Meraki. I want to use terraform to change the port settings on the MX. Currently, Terraform doesn't have the MX's ports in its state file, so here's what I plan to do:
- Retrieve all ports on MX from Meraki using data block, this returns a list of MX's ports and their current settings.
- Create a resource block and use count to iterate the list from data block, define the new settings that I want on those port.
- Add import block to import those ports to terraform state and also update those ports.
When I run terraform plan, terraform shows me the plan as how I want it.
and when I run terraform apply, it said apply successfully. But when I went back to Meraki and check port settings, not all of them are changed. You can see in VLAN columns, some of them are still saying "Drop Untagged Traffic". When in my Terraform code, I want them all changed to Native VLAN 1
here's my terraform code
data "meraki_networks_appliance_ports" "example" {
network_id = module.shop_network["${var.full_shop_num}"].network_id
}
resource "meraki_networks_appliance_ports" "example"{
count = length(data.meraki_networks_appliance_ports.example.items)
port_id = data.meraki_networks_appliance_ports.example.items[count.index].number
network_id = module.shop_network["${var.full_shop_num}"].network_id
allowed_vlans = "all"
drop_untagged_traffic = false
enabled = true
type = "trunk"
vlan = 1
access_policy = null
}
import {
for_each = local.ports
id = each.value.port_id
to = meraki_networks_appliance_ports.example[each.value.port_to]
}
locals {
ports = [for port in data.meraki_networks_appliance_ports.example.items : {
port_id = "${module.shop_network["${var.full_shop_num}"].network_id}, ${port.number}"
port_to = "${index(data.meraki_networks_appliance_ports.example.items, port)}"
}]
}
output "ports" {
value = local.ports
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I’ve seen this before. It’s not a Terraform problem, but a bug with the specific operation that can’t handle well concurrent PUT requests.
If you add a delay between the API calls to set different ports - it should work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Oren, I'm using count to iterate through my MX ports and I don't think I can add a delay between count iterations in Terraform. Does cisco-open terraform provider let you set delay between API calls?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Try Terraform’s “time”:
https://registry.terraform.io/providers/hashicorp/time/latest/docs/resources/sleep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you, but I think the time_sleep block only works for 2 different complete resource instances which are manually declared in terraform, whereas mine is created by iterating through a list of ports on MX.
I want to use count loop because I have 2 MX models: MX67 with 5 ports, and MX68 with 12 ports, so there's no fixed number of ports.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Let me check what can we do on our end.
