Skip to content

Commit

Permalink
add dhcp client option
Browse files Browse the repository at this point in the history
Add the dhcp client option
  • Loading branch information
melchiormoulin committed Feb 10, 2024
1 parent 5b31239 commit 1059728
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 2 deletions.
3 changes: 3 additions & 0 deletions examples/resources/routeros_ip_dhcp_client_option/import.sh
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-client/option get [print show-ids]]
terraform import routeros_ip_dhcp_client_option.option "*0"
4 changes: 4 additions & 0 deletions examples/resources/routeros_ip_dhcp_client_option/resource.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
resource "routeros_ip_dhcp_client_option" "option" {
name = "my-dhcp-option"
code = 60
}
6 changes: 4 additions & 2 deletions routeros/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ func Provider() *schema.Provider {
[]string{"ROS_HOSTURL", "MIKROTIK_HOST"},
nil,
),
Description: `URL of the MikroTik router, default is TLS connection to REST.
Description: `URL of the MikroTik router, default is TLS connection to REST.
* API: api[s]://host[:port]
* api://router.local
* apis://router.local:8729
* REST: https://host
* https://router.local
* router.local
* 127.0.0.1
* 127.0.0.1
export ROS_HOSTURL=router.local or export MIKROTIK_HOST=router.local
Expand Down Expand Up @@ -80,6 +80,7 @@ func Provider() *schema.Provider {

// IP objects
"routeros_ip_dhcp_client": ResourceDhcpClient(),
"routeros_ip_dhcp_client_option": ResourceDhcpClientOption(),
"routeros_ip_dhcp_server": ResourceDhcpServer(),
"routeros_ip_dhcp_server_config": ResourceDhcpServerConfig(),
"routeros_ip_dhcp_server_network": ResourceDhcpServerNetwork(),
Expand All @@ -104,6 +105,7 @@ func Provider() *schema.Provider {

// Aliases for IP objects to retain compatibility between original and fork
"routeros_dhcp_client": ResourceDhcpClient(),
"routeros_dhcp_client_option": ResourceDhcpClientOption(),
"routeros_dhcp_server": ResourceDhcpServer(),
"routeros_dhcp_server_network": ResourceDhcpServerNetwork(),
"routeros_dhcp_server_lease": ResourceDhcpServerLease(),
Expand Down
47 changes: 47 additions & 0 deletions routeros/resource_ip_dhcp_client option.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package routeros

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

// ResourceDhcpClient https://help.mikrotik.com/docs/display/ROS/DHCP#DHCP-DHCPClient
func ResourceDhcpClientOption() *schema.Resource {
resSchema := map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/ip/dhcp-client/option"),
MetaId: PropId(Id),
"name": {
Type: schema.TypeString,
Required: true,
Description: "The name that will be used in dhcp-client.",
},
"code": {
Type: schema.TypeInt,
Required: true,
Description: "The dhcp-client option code.",
},
"value": {
Type: schema.TypeString,
Optional: true,
Description: "The dhcp-client option",
},
"raw_value":
{
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "raw_value is computed from value.",
},

}
return &schema.Resource{
CreateContext: DefaultCreate(resSchema),
ReadContext: DefaultRead(resSchema),
UpdateContext: DefaultUpdate(resSchema),
DeleteContext: DefaultDelete(resSchema),
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},

Schema: resSchema,
}
}
47 changes: 47 additions & 0 deletions routeros/resource_ip_dhcp_client_option_test.go
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 testIpDhcpClientOptionAddress = "routeros_ip_dhcp_client_option.test_dhcp"

func TestAccIpDhcpClientOptionTest_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-client-option", "routeros_ip_dhcp_client_option"),
Steps: []resource.TestStep{
{
Config: testAccIpDhcpClientOptionConfig(),
Check: resource.ComposeTestCheckFunc(
testResourcePrimaryInstanceId(testIpDhcpClientOptionAddress),
resource.TestCheckResourceAttr(testIpDhcpClientOptionAddress, "name", "my-dhcp-option"),
resource.TestCheckResourceAttr(testIpDhcpClientOptionAddress, "code", "60"),

),
},
},
})

})
}
}

func testAccIpDhcpClientOptionConfig() string {
return providerConfig + `
resource "routeros_ip_dhcp_client_option" "test_dhcp" {
name = "my-dhcp-option"
code = 60
}
`
}

0 comments on commit 1059728

Please sign in to comment.