Terraform - meraki_networks_appliance_ports wont update all ports in a list of ports

Hugh-Nguyen
Here to help

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. 

HughNguyen_0-1741861662473.png

 

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

HughNguyen_1-1741861729238.png
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
}

 

 

5 Replies 5
Oren
Meraki Employee
Meraki Employee

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. 

Hugh-Nguyen
Here to help

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? 

Oren
Meraki Employee
Meraki Employee
Hugh-Nguyen
Here to help

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.

Oren
Meraki Employee
Meraki Employee

Let me check what can we do on our end.

Get notified when there are additional replies to this discussion.