Description
Describe the bug
I manage the ssl ceritficates for /ip/services
with terraform. I configure the www-ssl
services
with terraform while terraform is using the services to connect to the device.
This leads randomly to the error:
│ Error: POST 'https://<url>/rest/ip/service/set' returned response code: 400, message: 'Bad Request', details: 'failure: this is configured elsewhere'
The cause is that RouterOS 7.19 started to list all connections in /ip/services
.
Changelog:
*) ip-service - show all TCP/UDP connections on the system;
*) ip-service - show all TCP/UDP ports on system, including ports in containers;
*) ip-service - show error message when service enable fails;
Now there are multiple "services" with the name/number www-ssl
.
/ip/service/print
[...]
9 www-ssl 443 tcp letsencrypt.crt main 20
10 D c www-ssl 443 tcp <ip> <ip>:43532
11 D c www-ssl 443 tcp <ip> <ip>:47640
[...]
Entries with D c
are dynamic connections. When the API request from terraform hits one of the dynamic connections instead of the right service the error is returned.
I found this forum therad: https://forum.mikrotik.com/viewtopic.php?p=1146407
Their solution is to filterer the set command with a sub query.
/ip/service set [find dynamic =no and name =ssh] port=2222 disabled=no
But I have no idea how this could be done through the rest API or inside the tf provider code.
If I could get some pointers on how to fix this I'm more than happy to open a PR.
To Reproduce
- Enable the
www
service.
/ip/service set [find dynamic =no and name =www] port=80 disabled=no
- Open the web interface of the Mikrotik device over
http
to create dynamichttp
connections in the/ip/service
table. - Try to apply:
terraform {
required_providers {
routeros = {
source = "terraform-routeros/routeros"
version = "1.85.3"
}
}
}
provider "routeros" {
hosturl = "http://<ip>:80"
username = "[...]"
password = "[...]"
}
resource "routeros_ip_service" "www" {
numbers = "www"
port = "80"
disabled = false
}
This randomly results in:
Error: POST 'http://<ip>:80/rest/ip/service/set' returned response code: 400, message: 'Bad Request', details: 'failure: this is configured elsewhere'