I don’t know why MikroTik Team changed forum to this one, previous was better but ok, back to the case
For TF users I have a case:
Code looks like this
provider.tf:
terraform {
required_providers {
routeros = {
source = "terraform-routeros/routeros"
}
}
}
provider "routeros" {
hosturl = "apis://10.255.253.1" # env ROS_HOSTURL or MIKROTIK_HOST
username = "konrad" # env ROS_USERNAME or MIKROTIK_USER
password = "xxxx" # env ROS_PASSWORD or MIKROTIK_PASSWORD
insecure = true # env ROS_INSECURE or MIKROTIK_INSECURE
}
main.tf:
locals {
dhcp = yamldecode(file("${path.module}/dhcp.yaml"))
}
resource "routeros_ip_dhcp_server_lease" "leases" {
for_each = local.dhcp.dhcp.leases
mac_address = each.value.mac
address = each.value.ip_address
comment = each.value.comment
server = each.value.server
dhcp_option = each.value.dhcp_option
lifecycle {
create_before_destroy = false
}
}
dhcp.yaml:
---
dhcp:
leases:
eset-eth:
mac: A8:60:B6:24:EC:61
ip_address: 10.255.0.10
comment: eset-eth
server: MGMT_LAN
dhcp_option: ""
Important here is dhcp-option which was “h-node” now it’s “” , nothing. For tf it’s null.
When I run plan I get
❯ tf plan
routeros_ip_dhcp_server_lease.leases["eset-eth"]: Refreshing state... [id=*3174]
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
~ update in-place
Terraform will perform the following actions:
# routeros_ip_dhcp_server_lease.leases["eset-eth"] will be updated in-place
~ resource "routeros_ip_dhcp_server_lease" "leases" {
- dhcp_option = "h-node" -> null
id = "*3174"
# (11 unchanged attributes hidden)
}
Plan: 0 to add, 1 to change, 0 to destroy.
And after Apply
❯ tf apply
routeros_ip_dhcp_server_lease.leases["eset-eth"]: Refreshing state... [id=*3174]
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
~ update in-place
Terraform will perform the following actions:
# routeros_ip_dhcp_server_lease.leases["eset-eth"] will be updated in-place
~ resource "routeros_ip_dhcp_server_lease" "leases" {
- dhcp_option = "h-node" -> null
id = "*3174"
# (11 unchanged attributes hidden)
}
Plan: 0 to add, 1 to change, 0 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
routeros_ip_dhcp_server_lease.leases["eset-eth"]: Modifying... [id=*3174]
routeros_ip_dhcp_server_lease.leases["eset-eth"]: Modifications complete after 0s [id=*3174]
Apply complete! Resources: 0 added, 1 changed, 0 destroyed.
and on MikroTik
[recover@rtpoz1] /ip service> /ip dhcp-server lease print detail where address=10.255.0.10
Flags: X - disabled, R - radius, D - dynamic, B - blocked
0 ;;; eset-eth
address=10.255.0.10 mac-address=A8:60:B6:24:EC:61 address-lists="" server=MGMT_LAN dhcp-option=h-node status=waiting last-seen=never
as you see h-node is still there. What is the problem?
I will add log from TF_LOG=TRACE
2023-07-17T19:21:13.416+0200 [DEBUG] provider.terraform-provider-routeros_v1.13.0: response body: !re @r1 [{`.id` `*3174`} {`address` `10.255.0.10`} {`mac-address` `A8:60:B6:24:EC:61`} {`address-lists` ``} {`server` `MGMT_LAN`} {`dhcp-option` `h-node`} {`status` `waiting`} {`last-seen` `never`} {`radius` `false`} {`dynamic` `false`} {`blocked` `false`} {`disabled` `false`} {`comment` `eset-eth`}]
!done @r1 []: tf_req_id=9d52f245-1d8b-bab2-7c05-d33e7f7e6dcd tf_rpc=Configure @caller=github.com/terraform-routeros/terraform-provider-routeros/routeros/log.go:16 @module=routeros tf_provider_addr=terraform-routeros/routeros timestamp=2023-07-17T19:21:13.407+0200
2023-07-17T19:21:13.416+0200 [DEBUG] provider.terraform-provider-routeros_v1.13.0: request body: /ip/dhcp-server/lease/set =mac-address=A8:60:B6:24:EC:61 =server=MGMT_LAN =address=10.255.0.10 =block-access=no =disabled=no =dhcp-option= =comment=eset-eth: tf_req_id=9d52f245-1d8b-bab2-7c05-d33e7f7e6dcd tf_rpc=Configure @caller=github.com/terraform-routeros/terraform-provider-routeros/routeros/log.go:16 @module=routeros tf_provider_addr=terraform-routeros/routeros timestamp=2023-07-17T19:21:13.407+0200
2023-07-17T19:21:13.416+0200 [DEBUG] provider.terraform-provider-routeros_v1.13.0: response body: !done @r2 []: tf_rpc=Configure @caller=github.com/terraform-routeros/terraform-provider-routeros/routeros/log.go:16 @module=routeros tf_provider_addr=terraform-routeros/routeros tf_req_id=9d52f245-1d8b-bab2-7c05-d33e7f7e6dcd timestamp=2023-07-17T19:21:13.411+0200
it seems that it takes correct body with dhcp-option: h-node and then sending empty dhcp-option and it receives done 200 but even so on MikroTik I see that nothing changed.