-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #209
- Loading branch information
Showing
5 changed files
with
182 additions
and
13 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
examples/resources/routeros_interface_bridge_settings/import.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
terraform import routeros_interface_bridge_settings.settings . |
3 changes: 3 additions & 0 deletions
3
examples/resources/routeros_interface_bridge_settings/resource.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
resource "routeros_interface_bridge_settings" "settings" { | ||
use_ip_firewall = true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package routeros | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
/* | ||
{ | ||
"allow-fast-path": "true", | ||
"bridge-fast-forward-bytes": "0", | ||
"bridge-fast-forward-packets": "0", | ||
"bridge-fast-path-active": "true", | ||
"bridge-fast-path-bytes": "0", | ||
"bridge-fast-path-packets": "0", | ||
"use-ip-firewall": "false", | ||
"use-ip-firewall-for-pppoe": "false", | ||
"use-ip-firewall-for-vlan": "false" | ||
} | ||
*/ | ||
|
||
// https://wiki.mikrotik.com/wiki/Manual:Interface/Bridge#Bridge_Settings | ||
func ResourceInterfaceBridgeSettings() *schema.Resource { | ||
resSchema := map[string]*schema.Schema{ | ||
MetaResourcePath: PropResourcePath("/interface/bridge/settings"), | ||
MetaId: PropId(Name), | ||
|
||
"use_ip_firewall": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
Default: false, | ||
Description: "Force bridged traffic to also be processed by prerouting, forward and postrouting sections " + | ||
"of IP routing ( Packet Flow). This does not apply to routed traffic. This property is required in " + | ||
"case you want to assign Simple Queues or global Queue Tree to traffic in a bridge. Property " + | ||
"use-ip-firewall-for-vlan is required in case bridge vlan-filtering is used.", | ||
}, | ||
"use_ip_firewall_for_pppoe": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
Default: false, | ||
Description: "Send bridged un-encrypted PPPoE traffic to also be processed by IP/Firewall. This " + | ||
"property only has effect when use-ip-firewall is set to yes. This property is required " + | ||
"in case you want to assign Simple Queues or global Queue Tree to PPPoE traffic in a " + | ||
"bridge.", | ||
}, | ||
"use_ip_firewall_for_vlan": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
Default: false, | ||
Description: "Send bridged VLAN traffic to also be processed by IP/Firewall. This property only has " + | ||
"effect when use-ip-firewall is set to yes. This property is required in case you want " + | ||
"to assign Simple Queues or global Queue Tree to VLAN traffic in a bridge.", | ||
}, | ||
"allow_fast_path": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
Default: true, | ||
Description: "Whether to enable a bridge FastPath globally.", | ||
}, | ||
"bridge_fast_path_active": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
Description: "Shows whether a bridge FastPath is active globally, FastPatch status per bridge " + | ||
"interface is not displayed.", | ||
}, | ||
"bridge_fast_path_packets": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "Shows packet count forwarded by Bridge FastPath.", | ||
}, | ||
"bridge_fast_path_bytes": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "Shows byte count forwarded by Bridge Fast Path.", | ||
}, | ||
"bridge_fast_forward_packets": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "Shows packet count forwarded by Bridge Fast Forward.", | ||
}, | ||
"bridge_fast_forward_bytes": { | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
Description: "Shows byte count forwarded by Bridge Fast Forward.", | ||
}, | ||
} | ||
|
||
return &schema.Resource{ | ||
CreateContext: DefaultSystemCreate(resSchema), | ||
ReadContext: DefaultSystemRead(resSchema), | ||
UpdateContext: DefaultSystemUpdate(resSchema), | ||
DeleteContext: DefaultSystemDelete(resSchema), | ||
|
||
Importer: &schema.ResourceImporter{ | ||
StateContext: schema.ImportStatePassthroughContext, | ||
}, | ||
|
||
Schema: resSchema, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package routeros | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-testing/terraform" | ||
) | ||
|
||
const testInterfaceBridgeSettingsAddress = "routeros_interface_bridge_settings.test" | ||
|
||
func TestAccInterfaceBridgeSettingsTest_basic(t *testing.T) { | ||
for _, name := range testNames { | ||
t.Run(name, func(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { | ||
testAccPreCheck(t) | ||
testSetTransportEnv(t, name) | ||
}, | ||
ProviderFactories: testAccProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccInterfaceBridgeSettingsConfig(name), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckInterfaceBridgeSettingsExists(testInterfaceBridgeSettingsAddress), | ||
resource.TestCheckResourceAttr(testInterfaceBridgeSettingsAddress, "id", "interface.bridge.settings"), | ||
), | ||
}, | ||
}, | ||
}) | ||
}) | ||
} | ||
} | ||
|
||
func testAccCheckInterfaceBridgeSettingsExists(name string) resource.TestCheckFunc { | ||
return func(s *terraform.State) error { | ||
rs, ok := s.RootModule().Resources[name] | ||
if !ok { | ||
return fmt.Errorf("not found: %s", name) | ||
} | ||
|
||
if rs.Primary.ID == "" { | ||
return fmt.Errorf("no id is set") | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
func testAccInterfaceBridgeSettingsConfig(testName string) string { | ||
if strings.Contains(testName, "API") { | ||
return providerConfig + ` | ||
resource "routeros_interface_bridge_settings" "test" { | ||
use_ip_firewall = true | ||
} | ||
` | ||
} | ||
return providerConfig + ` | ||
resource "routeros_interface_bridge_settings" "test" { | ||
use_ip_firewall = false | ||
} | ||
` | ||
} |