terraform-routeros / terraform-provider-routeros

Terraform Provider for Mikrotik RouterOS
Mozilla Public License 2.0
185 stars 53 forks source link

resource "routeros_interface_bridge_vlan" "bonding_vlans" keeps asking to update #546

Closed tofkamp closed 1 week ago

tofkamp commented 2 weeks ago

Describe the bug Upgraded the routeros provider from (before 1.54.3) to the latest (1.61.0). Updated the resources to have vlan_ids = [ each.value.vlans ] After apply, the system keeps asking to update the resource again, and again, etc.

To Reproduce Hard to reproduce because it is a resource in a module, with foreach loops etc. If you cannot find the cause in the logfile, I will try to make a simpler version of the module.

Expected behavior Just change it, and not come back. It looks good in the switch itself.

Debug Information See logfile. One of the plan and one of the apply.

Additional context tflogapply.txt tflogplan.txt

OpenTofu will perform the following actions:

  # module.mikrotik_chrtjibbe.routeros_interface_bridge_vlan.bonding_vlans["uplink2core"] will be updated in-place
  ~ resource "routeros_interface_bridge_vlan" "bonding_vlans" {
        id               = "*A"
      ~ vlan_ids         = [
          - "10",
          - "100",
          - "101",
          - "102",
          - "103",
          - "112",
          - "20",
          - "201",
          - "202",
          - "220",
          - "254",
          - "4",
          - "50",
          + "4,10,20,50,100,101,102,103,112,201,202,220,254",
        ]
        # (9 unchanged attributes hidden)
    }

  # module.mikrotik_chrtjibbe.routeros_interface_bridge_vlan.trunk_vlans["ether3"] will be updated in-place
  ~ resource "routeros_interface_bridge_vlan" "trunk_vlans" {
        id               = "*12"
      ~ vlan_ids         = [
          - "1",
          - "10",
          - "20",
          - "200-202",
          - "220",
          + "1,10,20,200-202,220",
        ]
        # (9 unchanged attributes hidden)
    }

Plan: 0 to add, 2 to change, 0 to destroy.

on windows 10: c:> tofu -version 2024-08-27T12:21:54.700+0200 [INFO] OpenTofu version: 1.7.1 2024-08-27T12:21:54.757+0200 [DEBUG] using github.com/hashicorp/go-tfe v1.36.0 2024-08-27T12:21:54.758+0200 [DEBUG] using github.com/opentofu/hcl/v2 v2.0.0-20240416130056-03228b26f391 2024-08-27T12:21:54.758+0200 [DEBUG] using github.com/hashicorp/terraform-svchost v0.1.1 2024-08-27T12:21:54.758+0200 [DEBUG] using github.com/zclconf/go-cty v1.14.4 2024-08-27T12:21:54.758+0200 [INFO] Go runtime version: go1.21.3

vaerh commented 2 weeks ago

Can you add the output TF_LOG_PROVIDER=debug ROS_LOG_COLOR=1 terraform apply ?

tofkamp commented 2 weeks ago

I set the env vars, and redirected the stderr to this file. Is this what you are searching for ?

vaerh commented 2 weeks ago

Thank you, I hope that's enough. I have hidden the comment to avoid deleting the output file.

vaerh commented 2 weeks ago

@tofkamp Yes, it's a funny story: we changed the attribute type, but forgot to change the description. Please use the following syntax in your scenario and check it:

    ...
    vlan_ids = ["4", "10", "20", "50", "100", "101", "102", "103", "112", "201", "202", "220", "254"]
    ...
tofkamp commented 2 weeks ago

Well, it's a funny story. I changed it to your suggestion, but nothing changed. It was still broken. Then I looked better at the output of the command, and noticed it wants to replaces a list of 13 strings, with a list of 1 string. They are only equal if you have just 1 vlan. Then it works fine. I changed my data and code, to provide it with a list of strings, and it worked ! Then a list of numbers, which also worked. Any list with of a range (100-102), do not work. The order of the numbers does not matter. Maybe it is wise to change the example to have multiple vlans in the list, so people will be less likely to make the same mistake I made.

Question: Is it a list of vlan-numbers ? Or a set of vlan-numbers ? I think it is a set of numbers, because I changed the input to: "vlans" = [ 4,10,20,50,100,101,102,103,112,201,202,220,254, 4,10,20,50,100,101,102,103,112,201,202,220,254 ] and this also works.

Thank you for your great product and support.

vaerh commented 2 weeks ago

Interesting information. I will try to debug this point in the near future. Better to get the code to work right than to tweak the documentation. The way I see it. You are always welcome!

vaerh commented 2 weeks ago

Hi @tofkamp I have debugged the resource on different datasets and didn't get any significant issues. The following variants worked for me on ROS 7.14.2 without problems:

vlan_ids = ["4", "10", "20", "50", "100", "101", "102", "103", "112", "201", "202", "220", "254"]
vlan_ids = ["4", "10", "20", "50", "100-103", "112", "201", "202", "220", "254"]
vlan_ids = ["100-115", "120", "122", "128-130"]

And yes, vlan_ids is exactly a set of values, not a list, to eliminate the effect of sorting on execution plan changes.

Do I need to check some other specific set of vlan_ids or do I just include these in the example for the resource?

tofkamp commented 2 weeks ago

You did a great job fixing! I think it is resolved, and made better.

vaerh commented 1 week ago

:tada: This issue has been resolved in version 1.61.2 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: