Handling Configuration Drift #649
-
Hello Folks, first of all, thanks for this amazing Terraform provider! It works really well and makes it easy to get started. Managing switch configurations with Terraform sounds great because it ensures the desired state. However, I’m struggling to understand how to effectively prevent configuration drift with the current implementation. As far as I understand, the provider only manages resources (e.g., bridges/interfaces) that are already in its state. This means that if someone manually creates a new interface or bridge, the provider won’t manage it. I know that I can import resources into the state, but for that, I need the resource ID and a valid planned configuration. This makes it difficult to ensure consistency automatically. I would love to see a way to either:
Maybe I’m missing something due to my inexperience with Terraform, or perhaps the documentation could be improved in this regard? Looking forward to your input—thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments
-
Hello! Questions similar to yours appear here from time to time. But unfortunately I can't give any encouragement and say that there is a solution to them. |
Beta Was this translation helpful? Give feedback.
-
Hello, I completely understand that keeping the state clean can be challenging, especially when users add items through the GUI or API. Is there anything else I can do to make this easier, besides just making the user read-only? How do you and your team, or others from the Community prevent drift from occurring? I believe the answer is in your text, but I think starting a discussion could be helpful for others who face the same problem and might benefit from different perspectives within the community. |
Beta Was this translation helpful? Give feedback.
-
In my case it's a bit easier, as I'm the only one administrating MT. That is, I follow the principle of monopoly configuration for TF managed resources. |
Beta Was this translation helpful? Give feedback.
-
I have some automation. So I'm the only one that manages all te stuff and do it in Terraform. I have some people who needs to vlan or force poe. They edit an config file in git and commit, an github action then performs the change on the device. In this way the person does not need to know how the different milrotik models vlan. All handled in the module. |
Beta Was this translation helpful? Give feedback.
-
As @vaerh mentions, terraform (as other configuration tools like pulumi, puppet, ansible, etc) know of the resources they manage in a target, and no others. So they can detect drift in such resources, but not in resources they know nothing of. The idea behind this is that the targets can be modified from outside these tools (which is usually desired) but the resources under the tool's control are always kept as desired. This also allows you also to gradually manage a device, importing resources as needed. In some of these tools you can manage some top-level resources as a block, ie, managing In my case, I use some terraform code I wrote where most resources are iterable so importing a whole new MT takes some effort but not much. As a "marker" to know which resource is managed by terraform and which not, I automatically comment them with text that lets me identify the resources. Maybe this solution helps you too? |
Beta Was this translation helpful? Give feedback.
-
Hey, i am very grateful, for the Solutions you guys provided, I was also using a comment as marker, but was hoping to find a more complete Solution. I think the Discussion has been answered, with @vaerh comment for now. Maybe MT implements something to make the state manageble better. (someone can Dream, right?) |
Beta Was this translation helpful? Give feedback.
In my case it's a bit easier, as I'm the only one administrating MT. That is, I follow the principle of monopoly configuration for TF managed resources.
What I can think of at the moment is to either leave your account alone with RW permissions, or go the long way and describe in the TF script all attributes of your resources that have the
DiffSuppressFunc: AlwaysPresentNotUserProvided
entry. You can see this in the source code of theterraform-provider-routeros/routeros
provider.