diff --git a/docs/resources/interface_ipip.md b/docs/resources/interface_ipip.md index 56b077cc..670028ec 100644 --- a/docs/resources/interface_ipip.md +++ b/docs/resources/interface_ipip.md @@ -15,9 +15,7 @@ resource "routeros_interface_ipip" "ipip_hq" { ### Required -- `name` (String) Changing the name of this resource will force it to be recreated. - > The links of other configuration properties to this resource may be lost! - > Changing the name of the resource outside of a Terraform will result in a loss of control integrity for that resource! +- `name` (String) Name of the ipip interface. ### Optional diff --git a/docs/resources/ipip.md b/docs/resources/ipip.md index 5648dfc3..f405acb7 100644 --- a/docs/resources/ipip.md +++ b/docs/resources/ipip.md @@ -8,9 +8,7 @@ ### Required -- `name` (String) Changing the name of this resource will force it to be recreated. - > The links of other configuration properties to this resource may be lost! - > Changing the name of the resource outside of a Terraform will result in a loss of control integrity for that resource! +- `name` (String) Name of the ipip interface. ### Optional diff --git a/docs/resources/ipv6_dhcp_client.md b/docs/resources/ipv6_dhcp_client.md new file mode 100644 index 00000000..eeca8732 --- /dev/null +++ b/docs/resources/ipv6_dhcp_client.md @@ -0,0 +1,32 @@ +# routeros_ipv6_dhcp_client (Resource) + + + + + +## 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" + + diff --git a/routeros/provider.go b/routeros/provider.go index c5b4ece1..a21fb563 100644 --- a/routeros/provider.go +++ b/routeros/provider.go @@ -97,6 +97,7 @@ func Provider() *schema.Provider { "routeros_ip_dns": ResourceDns(), "routeros_ip_dns_record": ResourceDnsRecord(), "routeros_ip_service": ResourceIpService(), + "routeros_ipv6_dhcp_client": ResourceIPv6DhcpClient(), "routeros_ipv6_address": ResourceIPv6Address(), "routeros_ipv6_firewall_addr_list": ResourceIPv6FirewallAddrList(), "routeros_ipv6_firewall_filter": ResourceIPv6FirewallFilter(), @@ -210,7 +211,7 @@ func Provider() *schema.Provider { // Helpers "routeros_wireguard_keys": ResourceWireguardKeys(), - "routeros_move_items": ResourceMoveItems(), + "routeros_move_items": ResourceMoveItems(), // User Manager "routeros_user_manager_advanced": ResourceUserManagerAdvanced(), diff --git a/routeros/resource_ipv6_dhcp_client.go b/routeros/resource_ipv6_dhcp_client.go new file mode 100644 index 00000000..e305b47a --- /dev/null +++ b/routeros/resource_ipv6_dhcp_client.go @@ -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, + } +} diff --git a/routeros/resource_ipv6_dhcp_client_test.go b/routeros/resource_ipv6_dhcp_client_test.go new file mode 100644 index 00000000..ef6c8879 --- /dev/null +++ b/routeros/resource_ipv6_dhcp_client_test.go @@ -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" +} + +` +}