-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
185 additions
and
7 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,32 @@ | ||
# routeros_ipv6_dhcp_client (Resource) | ||
|
||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `interface` (String) The interface on which the DHCPv6 client will be running. | ||
- `pool_name` (String) Name of the IPv6 pool in which received IPv6 prefix will be added | ||
- `pool_prefix_length` (Number) Prefix length parameter that will be set for IPv6 pool in which received IPv6 prefix is added. Prefix length must be greater than the length of the received prefix, otherwise, prefix-length will be set to received prefix length + 8 bits. | ||
|
||
### Optional | ||
|
||
- `add-default-route ` (Boolean) Whether to add default IPv6 route after a client connects. | ||
- `comment` (String) | ||
- `disabled` (Boolean) | ||
- `prefix_hint ` (Number) Include a preferred prefix length. | ||
- `script` (String) Run this script on the DHCP-client status change. Available variables:pd-valid - if the prefix is acquired by the client;pd-prefix - the prefix acquired by the client if any;na-valid - if the address is acquired by the client;na-address - the address acquired by the client if any.options - array of received options (only ROSv7) | ||
- `use_peer_dns` (Boolean) Routing table this route belongs to. | ||
|
||
### Read-Only | ||
|
||
- `duid` (String) Auto-generated DUID that is sent to the server.DUID is generated using one of the MAC addresses available on the router. | ||
- `id` (String) The ID of this resource. | ||
- `prefix` (String) Shows received IPv6 prefix from DHCPv6-PD server | ||
- `request` (List of String) To choose if the DHCPv6 request will ask for the address or the IPv6 prefix, or both. | ||
- `status` (String) Shows the status of DHCPv6 Client:stopped - dhcpv6 client is stoppedsearching - sending "solicit" and trying to get "advertise" Shows actual (resolved) gateway and interface that will be used for packet forwarding.requesting - sent "request" waiting for "reply"bound - received "reply". Prefix assigned. renewing - sent "renew", waiting for "reply" rebinding - sent "rebind", waiting for "reply" error - reply was not received in time or some other error occurred. stopping - sent "release" | ||
|
||
|
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,102 @@ | ||
package routeros | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" | ||
) | ||
|
||
// ResourceIPv6DhcpClient https://help.mikrotik.com/docs/display/ROS/DHCP#DHCP-DHCPv6Client | ||
func ResourceIPv6DhcpClient() *schema.Resource { | ||
resSchema := map[string]*schema.Schema{ | ||
MetaResourcePath: PropResourcePath("/ipv6/dhcp-client/"), | ||
MetaId: PropId(Id), | ||
|
||
"add-default-route ": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
Description: "Whether to add default IPv6 route after a client connects.", | ||
Default: true, | ||
}, | ||
KeyComment: PropCommentRw, | ||
KeyDisabled: PropDisabledRw, | ||
"duid": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Auto-generated DUID that is sent to the server." + | ||
"DUID is generated using one of the MAC addresses available on the router.", | ||
}, | ||
"interface": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "The interface on which the DHCPv6 client will be running.", | ||
}, | ||
"pool_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
Description: "Name of the IPv6 pool in which received IPv6 prefix will be added", | ||
}, | ||
"pool_prefix_length": { | ||
Type: schema.TypeInt, | ||
Computed: false, | ||
Required: true, | ||
Description: "Prefix length parameter that will be set for IPv6 pool in which received IPv6 prefix is added." + | ||
" Prefix length must be greater than the length of the received prefix, otherwise, prefix-length will be set to received prefix length + 8 bits.", | ||
ValidateFunc: validation.IntBetween(0, 128), | ||
}, | ||
"prefix": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Shows received IPv6 prefix from DHCPv6-PD server", | ||
}, | ||
"prefix_hint ": { | ||
Type: schema.TypeInt, | ||
Optional: true, | ||
Description: "Include a preferred prefix length.", | ||
ValidateFunc: validation.IntBetween(0, 128), | ||
}, | ||
"request": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Description: "To choose if the DHCPv6 request will ask for the address or the IPv6 prefix, or both.", | ||
}, | ||
"status": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "Shows the status of DHCPv6 Client:" + | ||
"stopped - dhcpv6 client is stopped" + | ||
"searching - sending \"solicit\" and trying to get \"advertise\" Shows actual (resolved) gateway and interface that will be used for packet forwarding.requesting - sent \"request\" waiting for \"reply\"" + | ||
"bound - received \"reply\". Prefix assigned. " + | ||
"renewing - sent \"renew\", waiting for \"reply\" " + | ||
"rebinding - sent \"rebind\", waiting for \"reply\" " + | ||
"error - reply was not received in time or some other error occurred. " + | ||
"stopping - sent \"release\"", | ||
}, | ||
"script": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: "Run this script on the DHCP-client status change. Available variables:" + | ||
"pd-valid - if the prefix is acquired by the client;" + | ||
"pd-prefix - the prefix acquired by the client if any;" + | ||
"na-valid - if the address is acquired by the client;" + | ||
"na-address - the address acquired by the client if any." + | ||
"options - array of received options (only ROSv7)", | ||
}, | ||
"use_peer_dns": { | ||
Type: schema.TypeBool, | ||
Optional: true, | ||
Default: true, | ||
Description: "Routing table this route belongs to.", | ||
}, | ||
} | ||
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,47 @@ | ||
package routeros | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
) | ||
|
||
const testIPv6DhcpClient = "routeros_ipv6_dhcp_client.client" | ||
|
||
func TestAccIPv6DhcpClient_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("/ipv6/dhcp-client/client", "routeros_ipv6_dhcp_client"), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccIPv6DhcpClientConfig(), | ||
Check: resource.ComposeTestCheckFunc( | ||
testResourcePrimaryInstanceId(testIPv6DhcpClient), | ||
resource.TestCheckResourceAttr(testIPv6DhcpClient, "interface", "ether1"), | ||
resource.TestCheckResourceAttr(testIPv6DhcpClient, "pool_name", "inet-provider-pool"), | ||
), | ||
}, | ||
}, | ||
}) | ||
|
||
}) | ||
} | ||
} | ||
|
||
func testAccIPv6DhcpClientConfig() string { | ||
return providerConfig + ` | ||
resource "routeros_ipv6_dhcp_client" "client" { | ||
interface = "ether1" | ||
request = ["prefix"] | ||
pool_name = "inet-provider-pool" | ||
} | ||
` | ||
} |