Skip to content
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

add dhcp client option #352

Merged
merged 2 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
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"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the resource path: /ip/dhcp-client/option

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh sorry did not see the notification ! thanks

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
}

`
}
Loading