-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add IP neighbor discovery resource
Closes #388
- Loading branch information
Showing
4 changed files
with
133 additions
and
2 deletions.
There are no files selected for viewing
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
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,79 @@ | ||
package routeros | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" | ||
) | ||
|
||
/* | ||
{ | ||
"discover-interface-list": "LAN", | ||
"lldp-med-net-policy-vlan": "disabled", | ||
"mode": "tx-and-rx", | ||
"protocol": "cdp,lldp,mndp" | ||
} | ||
*/ | ||
|
||
// https://help.mikrotik.com/docs/display/ROS/MAC+server | ||
func ResourceIpNeighborDiscoverySettings() *schema.Resource { | ||
resSchema := map[string]*schema.Schema{ | ||
MetaResourcePath: PropResourcePath("/ip/neighbor/discovery-settings"), | ||
MetaId: PropId(Id), | ||
|
||
"discover_interface_list": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Interface list on which members the discovery protocol will run on.", | ||
DiffSuppressFunc: AlwaysPresentNotUserProvided, | ||
}, | ||
"lldp_med_net_policy_vlan": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: `Advertised VLAN ID for LLDP-MED Network Policy TLV. This allows assigning a VLAN ID for | ||
LLDP-MED capable devices, such as VoIP phones. The TLV will only be added to interfaces where LLDP-MED | ||
capable devices are discovered. Other TLV values are predefined and cannot be changed: | ||
- Application Type - Voice | ||
- VLAN Type - Tagged | ||
- L2 Priority - 0 | ||
- DSCP Priority - 0 | ||
When used together with the bridge interface, the (R/M)STP protocol should be enabled with protocol-mode setting. | ||
Additionally, other neighbor discovery protocols (e.g. CDP) should be excluded using protocol setting to | ||
avoid LLDP-MED misconfiguration.`, | ||
DiffSuppressFunc: AlwaysPresentNotUserProvided, | ||
}, | ||
"mode": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Selects the neighbor discovery packet sending and receiving mode. The setting is " + | ||
"available since RouterOS version 7.7.", | ||
ValidateFunc: validation.StringInSlice([]string{"rx-only", "tx-only", "tx-and-rx"}, false), | ||
DiffSuppressFunc: AlwaysPresentNotUserProvided, | ||
}, | ||
"protocol": { | ||
Type: schema.TypeSet, | ||
Optional: true, | ||
Description: "List of used discovery protocols.", | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
ValidateFunc: validation.StringInSlice([]string{"cdp", "lldp", "mndp"}, false), | ||
}, | ||
DiffSuppressFunc: AlwaysPresentNotUserProvided, | ||
}, | ||
} | ||
|
||
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,51 @@ | ||
package routeros | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
) | ||
|
||
const testIpNeighborDiscoverySettings = "routeros_ip_neighbor_discovery_settings.test" | ||
|
||
func TestAccIpNeighborDiscoverySettingsTest_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: testAccIpNeighborDiscoverySettingsConfig("static", "1", "rx-only", `[]`), | ||
Check: resource.ComposeTestCheckFunc( | ||
testResourcePrimaryInstanceId(testIpNeighborDiscoverySettings), | ||
resource.TestCheckResourceAttr(testIpNeighborDiscoverySettings, "discover_interface_list", "static"), | ||
), | ||
}, | ||
{ | ||
Config: testAccIpNeighborDiscoverySettingsConfig("LAN", "disabled", "tx-and-rx", `["cdp", "lldp", "mndp"]`), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr(testIpNeighborDiscoverySettings, "discover_interface_list", "LAN"), | ||
), | ||
}, | ||
}, | ||
}) | ||
}) | ||
} | ||
} | ||
|
||
func testAccIpNeighborDiscoverySettingsConfig(iflist, lldp, mode, proto string) string { | ||
return fmt.Sprintf(`%v | ||
resource "routeros_ip_neighbor_discovery_settings" "test" { | ||
discover_interface_list = "%v" | ||
lldp_med_net_policy_vlan = "%v" | ||
mode = "%v" | ||
protocol = %v | ||
} | ||
`, providerConfig, iflist, lldp, mode, proto) | ||
} |