From 4251b6a6552bd8a07edebab046f5f97a0d85300a Mon Sep 17 00:00:00 2001 From: Michael Dokolin Date: Thu, 30 May 2024 07:55:48 +0200 Subject: [PATCH] feat: Add the `routeros_system_routerboard_usb` resource to manage the USB port --- .../routeros_system_routerboard_usb/import.sh | 1 + .../resource.tf | 3 ++ routeros/provider.go | 1 + routeros/resource_system_routerboard_usb.go | 49 +++++++++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 examples/resources/routeros_system_routerboard_usb/import.sh create mode 100644 examples/resources/routeros_system_routerboard_usb/resource.tf create mode 100644 routeros/resource_system_routerboard_usb.go diff --git a/examples/resources/routeros_system_routerboard_usb/import.sh b/examples/resources/routeros_system_routerboard_usb/import.sh new file mode 100644 index 00000000..6a4ee12a --- /dev/null +++ b/examples/resources/routeros_system_routerboard_usb/import.sh @@ -0,0 +1 @@ +terraform import routeros_system_routerboard_usb.settings . diff --git a/examples/resources/routeros_system_routerboard_usb/resource.tf b/examples/resources/routeros_system_routerboard_usb/resource.tf new file mode 100644 index 00000000..911987f2 --- /dev/null +++ b/examples/resources/routeros_system_routerboard_usb/resource.tf @@ -0,0 +1,3 @@ +resource "routeros_system_routerboard_usb" "settings" { + type = "auto" +} diff --git a/routeros/provider.go b/routeros/provider.go index 7760b783..0bd0ebc4 100644 --- a/routeros/provider.go +++ b/routeros/provider.go @@ -188,6 +188,7 @@ func Provider() *schema.Provider { "routeros_system_routerboard_button_reset": ResourceSystemRouterboardButtonReset(), "routeros_system_routerboard_button_wps": ResourceSystemRouterboardButtonWps(), "routeros_system_routerboard_settings": ResourceSystemRouterboardSettings(), + "routeros_system_routerboard_usb": ResourceSystemRouterboardUsb(), "routeros_system_scheduler": ResourceSystemScheduler(), "routeros_system_script": ResourceSystemScript(), "routeros_system_user": ResourceUser(), diff --git a/routeros/resource_system_routerboard_usb.go b/routeros/resource_system_routerboard_usb.go new file mode 100644 index 00000000..ac762869 --- /dev/null +++ b/routeros/resource_system_routerboard_usb.go @@ -0,0 +1,49 @@ +package routeros + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" +) + +/* +{ + "type": "auto", + "usb-mode": "automatic" +} +*/ + +// https://help.mikrotik.com/docs/display/ROS/USB+Features +func ResourceSystemRouterboardUsb() *schema.Resource { + resSchema := map[string]*schema.Schema{ + MetaResourcePath: PropResourcePath("/system/routerboard/usb"), + MetaId: PropId(Id), + + "type": { + Type: schema.TypeString, + Optional: true, + Description: "An option to set the type of the USB port. Possible value: `auto`, `mini-PCIe`, `USB-type-A`.", + ValidateFunc: validation.StringInSlice([]string{"auto", "mini-PCIe", "USB-type-A"}, false), + DiffSuppressFunc: AlwaysPresentNotUserProvided, + }, + "usb_mode": { + Type: schema.TypeString, + Optional: true, + Description: "An option to set the USB port mode. Possible values: `automatic`, `force-host`.", + ValidateFunc: validation.StringInSlice([]string{"automatic", "force-host"}, false), + DiffSuppressFunc: AlwaysPresentNotUserProvided, + }, + } + + return &schema.Resource{ + CreateContext: DefaultSystemCreate(resSchema), + ReadContext: DefaultSystemRead(resSchema), + UpdateContext: DefaultSystemUpdate(resSchema), + DeleteContext: DefaultSystemDelete(resSchema), + + Importer: &schema.ResourceImporter{ + StateContext: schema.ImportStatePassthroughContext, + }, + + Schema: resSchema, + } +}