Skip to content

Commit

Permalink
feat(ipv6): New resource routeros_ipv6_dhcp_server_option_sets
Browse files Browse the repository at this point in the history
  • Loading branch information
vaerh committed Oct 10, 2024
1 parent e93b170 commit 559be52
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#The ID can be found via API or the terminal
#The command for the terminal is -> :put [/ipv6/dhcp/server/option/sets get [print show-ids]]
terraform import routeros_ipv6_dhcp_server_option_sets.test *3
#Or you can import a resource using one of its attributes
terraform import routeros_ipv6_dhcp_server_option_sets.test "name=test-set"
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
resource "routeros_ipv6_dhcp_server_option" "domain-search" {
name = "domain-search"
code = 24
value = "0x07'example'0x05'local'0x00"
}

resource "routeros_ipv6_dhcp_server_option_sets" "test" {
name = "test-set"
options = [routeros_ipv6_dhcp_server_option.domain-search.name]
}
2 changes: 2 additions & 0 deletions routeros/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ func Provider() *schema.Provider {
"routeros_ipv6_address": ResourceIPv6Address(),
"routeros_ipv6_dhcp_client": ResourceIPv6DhcpClient(),
"routeros_ipv6_dhcp_client_option": ResourceIPv6DhcpClientOption(),
"routeros_ipv6_dhcp_server_option": ResourceIpv6DhcpServerOption(),
"routeros_ipv6_dhcp_server_option_sets": ResourceIpv6DhcpServerOptionSets(),
"routeros_ipv6_firewall_addr_list": ResourceIPv6FirewallAddrList(),
"routeros_ipv6_firewall_filter": ResourceIPv6FirewallFilter(),
"routeros_ipv6_neighbor_discovery": ResourceIPv6NeighborDiscovery(),
Expand Down
45 changes: 45 additions & 0 deletions routeros/resource_ipv6_dhcp_server_option_sets.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package routeros

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

/*
{
".id": "*1",
"name": "set1",
"options": "dns,option1"
}
*/

// https://help.mikrotik.com/docs/display/ROS/
func ResourceIpv6DhcpServerOptionSets() *schema.Resource {
resSchema := map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/ipv6/dhcp-server/option/sets"),
MetaId: PropId(Id),

KeyComment: PropCommentRw,
KeyName: PropName("The name of the DHCPv6 option."),
"options": {
Type: schema.TypeSet,
Optional: true,
Description: "The list of options.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
}

return &schema.Resource{
CreateContext: DefaultCreate(resSchema),
ReadContext: DefaultRead(resSchema),
UpdateContext: DefaultUpdate(resSchema),
DeleteContext: DefaultDelete(resSchema),

Importer: &schema.ResourceImporter{
StateContext: ImportStateCustomContext(resSchema),
},

Schema: resSchema,
}
}
54 changes: 54 additions & 0 deletions routeros/resource_ipv6_dhcp_server_option_sets_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package routeros

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

const testIpv6DhcpServerOptionSets = "routeros_ipv6_dhcp_server_option_sets.test"

func TestAccIpv6DhcpServerOptionSetsTest_basic(t *testing.T) {
t.Parallel()
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-server/option/sets", "routeros_ipv6_dhcp_server_option_sets"),
Steps: []resource.TestStep{
{
Config: testAccIpv6DhcpServerOptionSetsConfig(),
Check: resource.ComposeTestCheckFunc(
testResourcePrimaryInstanceId(testIpv6DhcpServerOptionSets),
resource.TestCheckResourceAttr(testIpv6DhcpServerOptionSets, "name", "test-set"),
resource.TestCheckResourceAttr(testIpv6DhcpServerOptionSets, "options.#", "1"),
resource.TestCheckResourceAttr(testIpv6DhcpServerOptionSets, "options.0", "domain-search-o24"),
),
},
},
})

})
}
}

func testAccIpv6DhcpServerOptionSetsConfig() string {
return fmt.Sprintf(`%v
resource "routeros_ipv6_dhcp_server_option" "domain-search" {
name = "domain-search-o24"
code = 24
value = "0x07'example'0x05'local'0x00"
}
resource "routeros_ipv6_dhcp_server_option_sets" "test" {
name = "test-set"
options = [routeros_ipv6_dhcp_server_option.domain-search.name]
}
`, providerConfig)
}

0 comments on commit 559be52

Please sign in to comment.