Skip to content

Commit

Permalink
feat(ds): Add new datasource routeros_system_routerboard
Browse files Browse the repository at this point in the history
Please provide a /system/routerboard datasource
Fixes #588
  • Loading branch information
vaerh committed Nov 10, 2024
1 parent a9f95aa commit 2f78e94
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data "routeros_system_routerboard" "data" {}
60 changes: 60 additions & 0 deletions routeros/datasource_system_routerboard.go
Original file line number Diff line number Diff line change
@@ -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,
}
}
43 changes: 43 additions & 0 deletions routeros/datasource_system_routerboard_test.go
Original file line number Diff line number Diff line change
@@ -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" {}
`
}
*/
1 change: 1 addition & 0 deletions routeros/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),

Expand Down

0 comments on commit 2f78e94

Please sign in to comment.