Skip to content

Commit

Permalink
fix: Patching firewall rules with place_before (#224)
Browse files Browse the repository at this point in the history
Fixes #223
+ Mangle + NAT
  • Loading branch information
vaerh authored May 30, 2023
1 parent 6b7c597 commit 5ef738e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
12 changes: 11 additions & 1 deletion routeros/resource_ip_firewall_filter.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package routeros

import (
"context"
"regexp"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
Expand All @@ -12,6 +14,7 @@ func ResourceIPFirewallFilter() *schema.Resource {
resSchema := map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/ip/firewall/filter"),
MetaId: PropId(Id),
MetaSkipFields: PropSkipFields(``),

"action": {
Type: schema.TypeString,
Expand Down Expand Up @@ -387,7 +390,14 @@ func ResourceIPFirewallFilter() *schema.Resource {
return &schema.Resource{
CreateContext: DefaultCreate(resSchema),
ReadContext: DefaultRead(resSchema),
UpdateContext: DefaultUpdate(resSchema),
UpdateContext: func(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
resSchema[MetaSkipFields].Default = `"place_before"`
defer func(){
resSchema[MetaSkipFields].Default = ``
}()

return ResourceUpdate(ctx, resSchema, d, m)
},
DeleteContext: DefaultDelete(resSchema),
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
Expand Down
12 changes: 11 additions & 1 deletion routeros/resource_ip_firewall_mangle.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package routeros

import (
"context"
"regexp"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
Expand All @@ -27,6 +29,7 @@ func ResourceIPFirewallMangle() *schema.Resource {
resSchema := map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/ip/firewall/mangle"),
MetaId: PropId(Id),
MetaSkipFields: PropSkipFields(``),

"action": {
Type: schema.TypeString,
Expand Down Expand Up @@ -439,7 +442,14 @@ func ResourceIPFirewallMangle() *schema.Resource {
return &schema.Resource{
CreateContext: DefaultCreate(resSchema),
ReadContext: DefaultRead(resSchema),
UpdateContext: DefaultUpdate(resSchema),
UpdateContext: func(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
resSchema[MetaSkipFields].Default = `"place_before"`
defer func() {
resSchema[MetaSkipFields].Default = ``
}()

return ResourceUpdate(ctx, resSchema, d, m)
},
DeleteContext: DefaultDelete(resSchema),
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
Expand Down
12 changes: 11 additions & 1 deletion routeros/resource_ip_firewall_nat.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package routeros

import (
"context"
"regexp"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
)
Expand All @@ -29,6 +31,7 @@ func ResourceIPFirewallNat() *schema.Resource {
resSchema := map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/ip/firewall/nat"),
MetaId: PropId(Id),
MetaSkipFields: PropSkipFields(``),

"action": {
Type: schema.TypeString,
Expand Down Expand Up @@ -384,7 +387,14 @@ func ResourceIPFirewallNat() *schema.Resource {
return &schema.Resource{
CreateContext: DefaultCreate(resSchema),
ReadContext: DefaultRead(resSchema),
UpdateContext: DefaultUpdate(resSchema),
UpdateContext: func(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
resSchema[MetaSkipFields].Default = `"place_before"`
defer func() {
resSchema[MetaSkipFields].Default = ``
}()

return ResourceUpdate(ctx, resSchema, d, m)
},
DeleteContext: DefaultDelete(resSchema),
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
Expand Down

0 comments on commit 5ef738e

Please sign in to comment.