From 2f78e94ceaf4c484376a5909159675371f3da90b Mon Sep 17 00:00:00 2001 From: Vaerh Date: Sun, 10 Nov 2024 22:35:44 +0300 Subject: [PATCH] feat(ds): Add new datasource `routeros_system_routerboard` Please provide a /system/routerboard datasource Fixes #588 --- .../data-source.tf | 1 + routeros/datasource_system_routerboard.go | 60 +++++++++++++++++++ .../datasource_system_routerboard_test.go | 43 +++++++++++++ routeros/provider.go | 1 + 4 files changed, 105 insertions(+) create mode 100644 examples/data-sources/routeros_system_routerboard/data-source.tf create mode 100644 routeros/datasource_system_routerboard.go create mode 100644 routeros/datasource_system_routerboard_test.go diff --git a/examples/data-sources/routeros_system_routerboard/data-source.tf b/examples/data-sources/routeros_system_routerboard/data-source.tf new file mode 100644 index 00000000..a2629d80 --- /dev/null +++ b/examples/data-sources/routeros_system_routerboard/data-source.tf @@ -0,0 +1 @@ +data "routeros_system_routerboard" "data" {} \ No newline at end of file diff --git a/routeros/datasource_system_routerboard.go b/routeros/datasource_system_routerboard.go new file mode 100644 index 00000000..6afacf1b --- /dev/null +++ b/routeros/datasource_system_routerboard.go @@ -0,0 +1,60 @@ +package routeros + +import ( + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" +) + +/* +{ + "current-firmware":"7.11.2", + "factory-firmware":"6.48.6", + "firmware-type":"qca9531L", + "model":"CRS312-4C+8XG", + "revision":"r2", + "routerboard":"true", + "serial-number":"XXXXXXXXXX", + "upgrade-firmware":"7.11.2" +} +*/ + +// https://help.mikrotik.com/docs/display/ROS/ +func DatasourceSystemRouterboard() *schema.Resource { + resSchema := map[string]*schema.Schema{ + MetaResourcePath: PropResourcePath("/system/routerboard"), + MetaId: PropId(Id), + + "current_firmware": { + Type: schema.TypeString, + Computed: true, + }, + "factory_firmware": { + Type: schema.TypeString, + Computed: true, + }, + "firmware_type": { + Type: schema.TypeString, + Computed: true, + }, + "model": { + Type: schema.TypeString, + Computed: true, + }, + "routerboard": { + Type: schema.TypeBool, + Computed: true, + }, + "serial_number": { + Type: schema.TypeString, + Computed: true, + }, + "upgrade_firmware": { + Type: schema.TypeString, + Computed: true, + }, + } + + return &schema.Resource{ + ReadContext: DefaultSystemDatasourceRead(resSchema), + Schema: resSchema, + } +} diff --git a/routeros/datasource_system_routerboard_test.go b/routeros/datasource_system_routerboard_test.go new file mode 100644 index 00000000..d7931119 --- /dev/null +++ b/routeros/datasource_system_routerboard_test.go @@ -0,0 +1,43 @@ +package routeros + +import ( + "testing" +) + +const testDatasourceSystemRouterboard = "data.routeros_system_routerboard.data" + +func TestAccDatasourceSystemRouterboardTest_basic(t *testing.T) { + t.Log("The test is skipped, the resource is only available on real hardware.") + /* + 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, + Steps: []resource.TestStep{ + { + Config: testAccDatasourceSystemRouterboardConfig(), + Check: resource.ComposeTestCheckFunc( + testResourcePrimaryInstanceId(testDatasourceSystemRouterboard), + ), + }, + }, + }) + + }) + } + */ +} + +/* +func testAccDatasourceSystemRouterboardConfig() string { + return providerConfig + ` + +data "routeros_system_routerboard" "data" {} +` +} +*/ diff --git a/routeros/provider.go b/routeros/provider.go index fba80498..70766a0c 100644 --- a/routeros/provider.go +++ b/routeros/provider.go @@ -341,6 +341,7 @@ func Provider() *schema.Provider { "routeros_ipv6_addresses": DatasourceIPv6Addresses(), "routeros_ipv6_firewall": DatasourceIPv6Firewall(), "routeros_system_resource": DatasourceSystemResource(), + "routeros_system_routerboard": DatasourceSystemRouterboard(), "routeros_wifi_easy_connect": DatasourceWiFiEasyConnect(), "routeros_x509": DatasourceX509(),