-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ipv6 dhcp client resource #354
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 @@ | ||
# routeros_ipv6_dhcp_client (Resource) | ||
|
||
|
||
## Example Usage | ||
```terraform | ||
resource "routeros_ipv6_dhcp_client" "inet_provider" { | ||
pool_name = "pub-add-pool" | ||
interface = "ether1" | ||
add-default-route = true | ||
pool_prefix_length = 64 | ||
request = ["prefix"] | ||
disabled = false | ||
} | ||
``` | ||
|
||
<!-- 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" | ||
|
||
## Import | ||
Import is supported using the following syntax: | ||
```shell | ||
#The ID can be found via API or the terminal | ||
#The command for the terminal is -> :put [/ipv6/dhcp-client/ get [print show-ids]] | ||
terraform import routeros_ipv6_dhcp_client.inet_provider "*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
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 [/ipv6/dhcp-client/ get [print show-ids]] | ||
terraform import routeros_ipv6_dhcp_client.inet_provider "*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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
resource "routeros_ipv6_dhcp_client" "inet_provider" { | ||
pool_name = "pub-add-pool" | ||
interface = "ether1" | ||
add-default-route = true | ||
pool_prefix_length = 64 | ||
request = ["prefix"] | ||
disabled = false | ||
} | ||
|
||
resource "routeros_ipv6_dhcp_client" "client" { | ||
pool_name = "pub-add-pool" | ||
interface = "ether1" | ||
add-default-route = true | ||
pool_prefix_length = "64" | ||
request = ["prefix"] | ||
interface = "ether1" | ||
} |
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,129 @@ | ||
package routeros | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" | ||
) | ||
|
||
/* | ||
[ | ||
{ | ||
".id": "*1", | ||
"add-default-route": "false", | ||
"dhcp-options": "", | ||
"dhcp-server-v6": "fe80::", | ||
"disabled": "false", | ||
"duid": "0x000003434343443", | ||
"interface": "if-name", | ||
"invalid": "false", | ||
"pool-name": "blacknight-pub-addr", | ||
"pool-prefix-length": "64", | ||
"prefix": "2a01:----:/56, 6d16h56m8s", | ||
"prefix-hint": "::/0", | ||
"request": "prefix", | ||
"status": "bound", | ||
"use-peer-dns": "true" | ||
} | ||
] | ||
*/ | ||
|
||
// 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.TypeString, | ||
Optional: true, | ||
Description: "Include a preferred prefix length.", | ||
ValidateFunc: validation.IsIPv6Address, | ||
DiffSuppressFunc: AlwaysPresentNotUserProvided, | ||
}, | ||
"request": { | ||
Type: schema.TypeList, | ||
Required: true, | ||
Description: "To choose if the DHCPv6 request will ask for the address or the IPv6 prefix, or both.", | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
ValidateFunc: validation.StringInSlice([]string{"info", "address", "prefix"}, false), | ||
}, | ||
}, | ||
"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,48 @@ | ||
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", "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"), | ||
resource.TestCheckResourceAttr(testIPv6DhcpClient, "request.0", "prefix"), | ||
), | ||
}, | ||
}, | ||
}) | ||
}) | ||
} | ||
} | ||
|
||
func testAccIPv6DhcpClientConfig() string { | ||
return providerConfig + ` | ||
|
||
resource "routeros_ipv6_dhcp_client" "client" { | ||
request = ["prefix"] | ||
pool_name = "inet-provider-pool" | ||
pool_prefix_length = "64" | ||
interface = "ether1" | ||
} | ||
|
||
` | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can happily change this. I don't have go installed on the same path and was giving me errors. The rest of the file is using just "go" instead of "/usr/bin/go"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok