Skip to content

Commit

Permalink
Merge pull request #238 from terraform-routeros/vaerh/issue237
Browse files Browse the repository at this point in the history
Vaerh/issue237
  • Loading branch information
vaerh committed Jul 12, 2023
2 parents 67f63a6 + fa04b82 commit c240ef4
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
5 changes: 5 additions & 0 deletions routeros/parse_duration.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package routeros
import (
"errors"
"fmt"
"strings"
"time"
)

Expand All @@ -28,6 +29,10 @@ func ParseDuration(s string) (time.Duration, error) {
if s == "" {
return 0, fmt.Errorf(`time: invalid duration "%v"`, orig)
}
// hh:mm:ss format
if ss := strings.Split(s, ":"); len(ss) == 3 {
s = ss[0] + "h" + ss[1] + "m" + ss[2]
}
for s != "" {
var (
v, f int64 // integers before, after decimal point
Expand Down
1 change: 1 addition & 0 deletions routeros/parse_duration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ func TestParseDuration(t *testing.T) {
{name: "300ms", args: args{"300ms"}, want: time.Duration(300 * time.Millisecond), wantErr: false},
{name: "300", args: args{"300"}, want: time.Duration(300 * time.Second), wantErr: false},
{name: "300s", args: args{"300s"}, want: time.Duration(300 * time.Second), wantErr: false},
{name: "00:00:10", args: args{"00:00:10"}, want: time.Duration(10 * time.Second), wantErr: false},
{name: "2h45m", args: args{"2h45m"}, want: time.Duration(2*time.Hour + 45*time.Minute), wantErr: false},
{name: "163w4d9h", args: args{"163w4d9h"}, want: time.Duration(98960400 * time.Second), wantErr: false},
{name: "27489h", args: args{"27489h"}, want: time.Duration(98960400 * time.Second), wantErr: false},
Expand Down
2 changes: 1 addition & 1 deletion routeros/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func init() {
testAccProvider = Provider()
testAccProviderFactories = map[string]func() (*schema.Provider, error){
"routeros": func() (*schema.Provider, error) {
return NewProvider(), nil
return testAccProvider, nil
},
}
}
Expand Down
8 changes: 7 additions & 1 deletion routeros/resource_ip_firewall_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,19 @@ func ResourceIPFirewallFilter() *schema.Resource {
"jump", "log", "passthrough", "reject", "return", "tarpit",
}, false),
},
"address_list": {
Type: schema.TypeString,
Optional: true,
Description: "Name of the address list used in 'add-dst-to-address-list' and 'add-src-to-address-list' actions.",
},
"address_list_timeout": {
Type: schema.TypeString,
Optional: true,
Default: "none-dynamic",
Description: "Time interval after which the address will be removed from the address list specified by " +
"address-list parameter. Used in conjunction with add-dst-to-address-list or add-src-to-address-list " +
"actions.",
DiffSuppressFunc: TimeEquall,
},
"bytes": {
Type: schema.TypeInt,
Expand Down Expand Up @@ -392,7 +398,7 @@ func ResourceIPFirewallFilter() *schema.Resource {
ReadContext: DefaultRead(resSchema),
UpdateContext: func(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
resSchema[MetaSkipFields].Default = `"place_before"`
defer func(){
defer func() {
resSchema[MetaSkipFields].Default = ``
}()

Expand Down
18 changes: 11 additions & 7 deletions routeros/resource_ip_firewall_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,24 @@ func testAccCheckIPFirewallFilterExists(name string) resource.TestCheckFunc {
}

func testAccIPFirewallFilterConfig() string {
return `
provider "routeros" {
insecure = true
}
return providerConfig + `
resource "routeros_firewall_filter" "rule" {
action = "accept"
chain = "forward"
src_address = "10.0.0.1"
dst_address = "10.0.1.1"
dst_port = "443"
protocol = "tcp"
}
}
resource "routeros_ip_firewall_filter" "testepeg" {
action = "add-dst-to-address-list"
address_list_timeout = "00:00:10"
protocol = "tcp"
tls_host = "globo"
address_list = "teste"
chain = "forward"
src_address_list = "LAN"
}
`
}

0 comments on commit c240ef4

Please sign in to comment.