-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dhcp-relay): Add DHCP Relay support
Closes #413
- Loading branch information
Showing
6 changed files
with
127 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#The ID can be found via API or the terminal | ||
#The command for the terminal is -> :put [/ip/dhcp-relay get [print show-ids]] | ||
terraform import routeros_ip_dhcp_relay.relay "*0" |
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,5 @@ | ||
resource "routeros_ip_dhcp_relay" "relay" { | ||
name = "test relay" | ||
interface = "ether1" | ||
dhcp_server = "0.0.0.1" | ||
} |
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,66 @@ | ||
package routeros | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
// ResourceDhcpRelay https://wiki.mikrotik.com/wiki/Manual:IP/DHCP_Relay | ||
func ResourceDhcpRelay() *schema.Resource { | ||
resSchema := map[string]*schema.Schema{ | ||
MetaResourcePath: PropResourcePath("/ip/dhcp-relay"), | ||
MetaId: PropId(Id), | ||
|
||
"add_relay_info": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
Description: "Adds DHCP relay agent information if enabled according to RFC 3046. Agent Circuit ID " + | ||
"Sub-option contains mac address of an interface, Agent Remote ID Sub-option contains MAC address " + | ||
"of the client from which request was received.", | ||
DiffSuppressFunc: AlwaysPresentNotUserProvided, | ||
}, | ||
"delay_threshold": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "If secs field in DHCP packet is smaller than delay-threshold, then this packet is ignored.", | ||
DiffSuppressFunc: TimeEquall, | ||
}, | ||
KeyDisabled: PropDisabledRw, | ||
"dhcp_server": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "List of DHCP servers' IP addresses which should the DHCP requests be forwarded to.", | ||
}, | ||
"interface": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "Interface name the DHCP relay will be working on.", | ||
}, | ||
KeyInvalid: PropInvalidRo, | ||
"local_address": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "The unique IP address of this DHCP relay needed for DHCP server to distinguish relays. " + | ||
"If set to 0.0.0.0 - the IP address will be chosen automatically", | ||
DiffSuppressFunc: AlwaysPresentNotUserProvided, | ||
}, | ||
KeyName: PropName("Descriptive name for the relay."), | ||
"relay_info_remote_id": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Specified string will be used to construct Option 82 instead of client's MAC address. Option " + | ||
"82 consist of: interface from which packets was received + client mac address or relay-info-remote-id", | ||
DiffSuppressFunc: AlwaysPresentNotUserProvided, | ||
}, | ||
} | ||
return &schema.Resource{ | ||
CreateContext: DefaultCreate(resSchema), | ||
ReadContext: DefaultRead(resSchema), | ||
UpdateContext: DefaultUpdate(resSchema), | ||
DeleteContext: DefaultDelete(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,48 @@ | ||
package routeros | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
) | ||
|
||
const testIpDhcpRelayAddress = "routeros_ip_dhcp_relay.test" | ||
|
||
func TestAccIpDhcpRelayTest_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, | ||
CheckDestroy: testCheckResourceDestroy("/ip/dhcp-relay", "routeros_ip_dhcp_relay"), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccIpDhcpRelayConfig(), | ||
Check: resource.ComposeTestCheckFunc( | ||
testResourcePrimaryInstanceId(testIpDhcpRelayAddress), | ||
resource.TestCheckResourceAttr(testIpDhcpRelayAddress, "name", "test relay"), | ||
resource.TestCheckResourceAttr(testIpDhcpRelayAddress, "interface", "ether1"), | ||
resource.TestCheckResourceAttr(testIpDhcpRelayAddress, "dhcp_server", "0.0.0.1"), | ||
), | ||
}, | ||
}, | ||
}) | ||
|
||
}) | ||
} | ||
} | ||
|
||
func testAccIpDhcpRelayConfig() string { | ||
return providerConfig + ` | ||
resource "routeros_ip_dhcp_relay" "test" { | ||
name = "test relay" | ||
interface = "ether1" | ||
dhcp_server = "0.0.0.1" | ||
} | ||
` | ||
} |