Skip to content

Commit

Permalink
fix(firewall): Fix the error of deleting field-lists
Browse files Browse the repository at this point in the history
  • Loading branch information
vaerh committed Dec 25, 2023
1 parent f2f13c0 commit 3f2f7b1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
5 changes: 5 additions & 0 deletions routeros/mikrotik_serialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ func TerraformResourceDataToMikrotik(s map[string]*schema.Schema, d *schema.Reso

switch terraformMetadata.Type {
case schema.TypeString:
if _, ok := setUnsetFields[terraformSnakeName]; ok && value.(string) == "" {
// Unset
item["!"+mikrotikKebabName] = ""
continue
}
item[mikrotikKebabName] = value.(string)
case schema.TypeFloat:
item[mikrotikKebabName] = strconv.FormatFloat(value.(float64), 'f', -1, 64)
Expand Down
7 changes: 4 additions & 3 deletions routeros/resource_ip_firewall_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import (
// ResourceIPFirewallFilter https://wiki.mikrotik.com/wiki/Manual:IP/Firewall/Filter
func ResourceIPFirewallFilter() *schema.Resource {
resSchema := map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/ip/firewall/filter"),
MetaId: PropId(Id),
MetaSkipFields: PropSkipFields(`"bytes","packets"`),
MetaResourcePath: PropResourcePath("/ip/firewall/filter"),
MetaId: PropId(Id),
MetaSkipFields: PropSkipFields(`"bytes","packets"`),
MetaSetUnsetFields: PropSetUnsetFields(`"dst_address_list","src_address_list","in_interface_list","out_interface_list","in_bridge_port_list","out_bridge_port_list"`),

"action": {
Type: schema.TypeString,
Expand Down
7 changes: 4 additions & 3 deletions routeros/resource_ip_firewall_mangle.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ import (
// ResourceIPFirewallMangle https://wiki.mikrotik.com/wiki/Manual:IP/Firewall/Mangle
func ResourceIPFirewallMangle() *schema.Resource {
resSchema := map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/ip/firewall/mangle"),
MetaId: PropId(Id),
MetaSkipFields: PropSkipFields(`"bytes","packets"`),
MetaResourcePath: PropResourcePath("/ip/firewall/mangle"),
MetaId: PropId(Id),
MetaSkipFields: PropSkipFields(`"bytes","packets"`),
MetaSetUnsetFields: PropSetUnsetFields(`"dst_address_list","src_address_list","in_interface_list","out_interface_list","in_bridge_port_list","out_bridge_port_list"`),

"action": {
Type: schema.TypeString,
Expand Down
7 changes: 4 additions & 3 deletions routeros/resource_ip_firewall_nat.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ import (
// ResourceIPFirewallNat https://wiki.mikrotik.com/wiki/Manual:IP/Firewall/NAT
func ResourceIPFirewallNat() *schema.Resource {
resSchema := map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/ip/firewall/nat"),
MetaId: PropId(Id),
MetaSkipFields: PropSkipFields(`"bytes","packets"`),
MetaResourcePath: PropResourcePath("/ip/firewall/nat"),
MetaId: PropId(Id),
MetaSkipFields: PropSkipFields(`"bytes","packets"`),
MetaSetUnsetFields: PropSetUnsetFields(`"dst_address_list","src_address_list","in_interface_list","out_interface_list","in_bridge_port_list","out_bridge_port_list"`),

"action": {
Type: schema.TypeString,
Expand Down

0 comments on commit 3f2f7b1

Please sign in to comment.