-
Notifications
You must be signed in to change notification settings - Fork 77
Add DefaultReadFiltered, filter ip_dhcp_server_lease
resource reads based on dynamic
field
#794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
ip_dhcp_server_lease
resource reads based on dynamic
field
Not bad:) |
So my use case is a bit cursed, but here we go:
# routeros_ip_dhcp_server_lease.static_lease will be updated in-place
~ resource "routeros_ip_dhcp_server_lease" "static_lease" {
~ address = "10.10.10.254" -> "10.1.1.11"
- client_id = "foo" -> null
id = "*1"
~ mac_address = (sensitive value)
~ server = "dhcp1" -> "dhcp2"
# (16 unchanged attributes hidden)
}
Does this make sense? Admittedly, it is not entirely "correct" to try to run |
I would like to look into your case in more detail. It seems to me that this should not be happening for the following reason: Mikrotik increases the counter-identifier when creating a new resource, so the case of identifier reuse can only occur after resetting the device (possibly after deleting resources and rebooting). It is also strictly forbidden to manipulate resources based on whether they are dynamic or not, since TF will not contain an accurate view of the managed resource and, in this case, it will not be possible to ensure its lifecycle. |
Yes, fair enough I guess that I should be doing |
This question is for Terraform ;) |
The setup that I have currently is that I have a bootstrap script that sets up the devices in a state where I can run
terraform apply
against that, regardless of the existing state in terraform. This is admittedly a bit cursed but bear with me.The problem I'm facing is with dhcp leases, where MikroTik seemingly doesn't separate between dynamic leases and static ones in their IDs.
This then causes a problem where the ID that terraform state has for the static lease is currently a dynamic lease, which results in
Error: PATCH 'https://10.1.1.2/rest/ip/dhcp-server/lease/*1' returned response code: 400, message: 'Bad Request', details: 'failure: can not change dynamic lease'
.As dynamic leases can not be changed anyways, probably would be okay to add filtering on the read of
routeros_ip_dhcp_server_lease
that filters out dynamic leases withdynamic=no
.Did this with adding a
DefaultReadFiltered
as well as two more underlying functions to mimicDefaultRead
, and then calling itrouteros/resource_ip_dhcp_server_lease.go
.Tested this at least locally and it works for my use case and doesn't seem to cause any weirdness.
Please let me know if this makes any sense, I'm new to terraform providers so there's also that.