Replies: 6 comments
-
Yes, I could write a lot about the attempts to connect Mikrotik and Teraform, but there are a number of problems which were described above. Unfortunately, the approach of managing only through TF (which was assumed by me at least) is not applicable. Only recently I made changes to be able to react to changes that were made from outside. |
Beta Was this translation helpful? Give feedback.
-
Yes, it's a big problem. Probably have to give up support for resources with a key field in the form of "name". But this requires a lot of consideration. As a solution, which would preserve the integrity of the logic when managing through TF, I added recreation of resources when they are renamed. |
Beta Was this translation helpful? Give feedback.
-
Hey, thanks for your response and patience. Here are my test cases. Test: rename manually (outside Terraform)First, lets create brand new bridge: resource "routeros_interface_bridge" "test" {
name = "terraform-test"
} Then apply, everything is fine, clean plans - no additional changes. But after I've changed bridge name with: /interface bridge set [ find name="terraform-test" ] name="terraform-renamed" Terraform lost reference and wants to create it again:
This will create NEW bridge, and probably tries to assign ports to it causing collisions / fails - I didn't test this, but I assume disaster :) Test: rename inside TerraformAfter creating (same way as in previous step) I've changed: resource "routeros_interface_bridge" "test" {
name = "terraform-renamed"
} plan looks like this:
This looks "fine" but notice the "id" will stay the same - misleading! Worst part is that, after apply (and successful renaming), running plan again gives the same output: "routeros_interface_bridge.test has been deleted" and wants to create it again with
So with current approach |
Beta Was this translation helpful? Give feedback.
-
I checked the current PropIds from the resources and found it quite disturbing that some resources use ID and others use Name even though they are similar or related, ie:
|
Beta Was this translation helpful? Give feedback.
-
Hi! |
Beta Was this translation helpful? Give feedback.
-
Solved. The release is available on GitHub release |
Beta Was this translation helpful? Give feedback.
-
This discussion is question/proposal. TL/DR at bottom.
I found out that this provider uses
.name
as unique identifier of all(?) resources. The name is indeed unique, however for all API operations requires.id
(like*2D1
) which is internal RouterOS thing. To make this work, before update/delete operation functions usesdynamicIdLookup()
to map name to ID. This is still fine, but... why it's like that?The only scenario I found it helps if when you manually dropped and recreated resource, then Terraform can still manage it. This should be mitigated by removing resource from state and importing new one - most providers works like that, because underlying APIs requires this flow. Anyways that kind of "swap" is bad for consistency.
I'm not sure what happens during backup/restore of configuration - if ID stays the same - it's perfect! if not.. either you shouldn't restore configuration but just use Terraform to provision your device again (That's why you're using TF in first place, right?), or just import all resources again.
What terrifies me, is case when you just renamed resource outside Terraform (intentionally or by mistake) which I guess happens more often. Then provider will just ignore it and try to create it again with unexpected consequences rather than renaming it back.
Even worse, same thing might happens when you rename resource INSIDE Terraform, the ID (which is name) isn't updating causing Terraform planing creating new resource on next run (tested this with
routeros_interface_bridge
) - this is definitely a bug, and should be fixed.TL/DR: Why not use RouterOS
.id
as Terraform resourceid
?Beta Was this translation helpful? Give feedback.
All reactions