-
Notifications
You must be signed in to change notification settings - Fork 61
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
feat: Add missing schema fields #303
feat: Add missing schema fields #303
Conversation
Hi Michael,
|
It might be if the
I don't expect anything like that. It's mainly for the update operation when the value is present remotely and not in the configuration. Terraform will skip that if it matches the returned default value. The beauty of this approach is that it doesn't change the serialization function, so I don't expect any side effects. |
@dokmic resource "routeros_interface_ethernet" "test" {
factory_name = "ether3"
name = "swtich-eth0"
mtu = 9000
} request body:
{
"arp": "enabled",
"arp-timeout": "auto",
"auto-negotiation": "yes",
"disable-running-check": "yes",
"disabled": "no",
"full-duplex": "yes",
"loop-protect": "default",
"loop-protect-disable-time": "5m",
"loop-protect-send-interval": "5s",
"mdix-enable": "yes",
"mtu": "9000",
"name": "swtich-eth0",
"rx-flow-control": "off",
"sfp-rate-select": "high",
"tx-flow-control": "off"
}
response body:
{
".id": "*3",
"advertise": "10M-half,10M-full,100M-half,100M-full,1000M-full", AlwaysPresentNotUserProvided
"arp": "enabled",
"arp-timeout": "auto",
"auto-negotiation": "true",
"cable-settings": "default", AlwaysPresentNotUserProvided
"default-name": "ether3",
"disable-running-check": "true",
"disabled": "false",
"loop-protect": "default",
"loop-protect-disable-time": "5m",
"loop-protect-send-interval": "5s",
"loop-protect-status": "off",
"mac-address": "54:05:AB:FE:F4:93", AlwaysPresentNotUserProvided
"mtu": "9000",
"name": "swtich-eth0",
"orig-mac-address": "54:05:AB:FE:F4:93",
"running": "true",
"rx-broadcast": "0",
"rx-bytes": "0",
"rx-flow-control": "off",
"rx-multicast": "0",
"rx-packet": "0",
"tx-broadcast": "5",
"tx-bytes": "3751",
"tx-flow-control": "off",
"tx-multicast": "21",
"tx-packet": "26"
}
state file:
{
"schema_version": 0,
"attributes": {
"___id___": null,
"___path___": null,
"___skip___": null,
"advertise": "10M-half,10M-full,100M-half,100M-full,1000M-full", <<<
"arp": "enabled",
"arp_timeout": "auto",
"auto_negotiation": true,
"bandwidth": null,
"cable_settings": "default", <<<
"combo_mode": null,
"comment": null,
"default_name": "ether3",
"disable_running_check": true,
"disabled": false,
"factory_name": "ether3",
"full_duplex": true,
"id": "*3",
"l2mtu": null,
"loop_protect": "default",
"loop_protect_disable_time": "5m",
"loop_protect_send_interval": "5s",
"loop_protect_status": "off",
"mac_address": "54:05:AB:FE:F4:93", <<<
"mdix_enable": true,
"mtu": 9000,
"name": "swtich-eth0",
"orig_mac_address": "54:05:AB:FE:F4:93",
"poe_out": "off",
"poe_priority": null,
"running": true,
"rx_flow_control": "off",
"sfp_rate_select": "high",
"sfp_shutdown_temperature": null,
"slave": null,
"speed": null,
"switch": null,
"tx_flow_control": "off"
}, I guess I can't understand your idea. Would you mind explaining it to me? |
…e is not present in the raw config
…ysPresentNotUserProvided` helper instead
…uterOS capabilities
@vaerh, Thank you so much for the explanation. You are absolutely right. In my PR, I was basically reinventing the wheel ( I fixed I've updated my PR to reuse this helper in the missing fields -- this should be compatible with all the supported RouterOS versions. |
Okay, here is the summary of the updated PR:
|
@@ -94,7 +90,7 @@ func ResourceInterfaceEthernet() *schema.Resource { | |||
RX limit is supported only on Atheros8327/QCA8337 switch-chip ports.`, | |||
DiffSuppressFunc: AlwaysPresentNotUserProvided, | |||
}, | |||
"cable_settings": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What version of ROS are you testing the provider?
In v7.10 this field looks exactly like "cable-settings":
Warning: Field 'cable_settings' not found in the schema
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have to put aside some part of things and start versioning schemas. In fact, I don't update the docker container either, so as not to lose any changes in schemas....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have this particular one in my fleet. While adding the PoE fields, I noticed the difference in their docs. After double-checking and a quick search, I thought that was a typo on the provider's side. I reverted the rename. Sorry about that 😞
I have to put aside some part of things and start versioning schemas.
It shouldn't be necessary at this point. We can cover almost all of the cases with AlwaysPresentNotUserProvided
rather than introducing an option (#271) requiring users to update that on every upgrade.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 This PR is included in version 1.25.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
While working on #300, I discovered that one property was missing in older versions of RouterOS. After digging into the current architecture and checking the way the plugin SDK evaluates the difference, I discovered that the code can be written in an isomorphic way so that it won't produce any errors on older versions. Here is some explanation:
Default
will make the resource incompatible with older versions.null
if they are not present in the configuration, so it's kind of necessary to specify defaults for those.DefaultFunc
callback to provide a default value conditionally depending on the preceding read operation. In that case, the default value for the created resources will be empty and only be present for updating resources if it's already present remotely. The latter should produce an empty plan on update if there are no changes in the config.I am aware of #271, and I got the idea of adding a version parameter, but it may break the declarative way of defining schemas as it requires if statements for such fields. The approach with conditional defaults should resolve pretty much all the current compatibility issues and should work as long as Mikrotik follows semantic versioning.
As the result, the PR brings the following:
DefaultIfSupported
helper function.vrf
parameter in the RADIUS resource.poe_out
,poe_priority
,cable_setting
,disable_running_check
,sfp_rate_select
,sfp_shutdown_temperature
.poe_voltage
,poe_lldp_enabled
,power_cycle_interval
,power_cycle_ping_enabled
,power_cycle_ping_address
,power_cycle_ping_timeout
.address_list_extra_time
to the DNS resource without breaking compatibility with any older versions (resolves Resource routeros_ip_dns missing address_list_extra_time fields #270 and closes New field address_list_extra_time in routeros_dns (in 7.10) #230).The changes are compatible with both
6.x
and7.x
versions of RouterOS.UPD: #303 (comment)