Skip to content

Commit

Permalink
feat(ds): Add /system/resource datasource
Browse files Browse the repository at this point in the history
  • Loading branch information
vaerh committed Nov 13, 2023
1 parent 6ecd622 commit 79a599e
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data "routeros_system_resource" "data" {}
87 changes: 87 additions & 0 deletions routeros/datasource_system_resource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package routeros

// Script generated from sampled device MikroTik 7.10 (stable) on CHR QEMU-x86_64

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

func DatasourceSystemResource() *schema.Resource {
resSchema := map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/system/resource"),
MetaId: PropId(Id),
"architecture_name": { // Sample = architecture-name: "x86_64"
Type: schema.TypeString,
Computed: true,
},
"board_name": { // Sample = board-name: "CHR"
Type: schema.TypeString,
Computed: true,
},
"build_time": { // Sample = build-time: "Jun/15/2023 05:17:29"
Type: schema.TypeString,
Computed: true,
},
"cpu": { // Sample = cpu: "QEMU"
Type: schema.TypeString,
Computed: true,
},
"cpu_count": { // Sample = cpu-count: "4"
Type: schema.TypeInt,
Computed: true,
},
"cpu_frequency": { // Sample = cpu-frequency: "2396"
Type: schema.TypeInt,
Computed: true,
},
"cpu_load": { // Sample = cpu-load: "3"
Type: schema.TypeInt,
Computed: true,
},
"factory_software": { // Sample = factory-software: "7.1"
Type: schema.TypeString,
Computed: true,
},
"free_hdd_space": { // Sample = free-hdd-space: "74567680"
Type: schema.TypeInt,
Computed: true,
},
"free_memory": { // Sample = free-memory: "393805824"
Type: schema.TypeInt,
Computed: true,
},
"platform": { // Sample = platform: "MikroTik"
Type: schema.TypeString,
Computed: true,
},
"total_hdd_space": { // Sample = total-hdd-space: "93564928"
Type: schema.TypeInt,
Computed: true,
},
"total_memory": { // Sample = total-memory: "469762048"
Type: schema.TypeInt,
Computed: true,
},
"uptime": { // Sample = uptime: "21h43m21s"
Type: schema.TypeString,
Computed: true,
},
"version": { // Sample = version: "7.10 (stable)"
Type: schema.TypeString,
Computed: true,
},
"write_sect_since_reboot": { // Sample = write-sect-since-reboot: "6936"
Type: schema.TypeInt,
Computed: true,
},
"write_sect_total": { // Sample = write-sect-total: "6936"
Type: schema.TypeInt,
Computed: true,
},
}

return &schema.Resource{
ReadContext: DefaultSystemDatasourceRead(resSchema),
Schema: resSchema,
}
}
39 changes: 39 additions & 0 deletions routeros/datasource_system_resource_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package routeros

import (
"testing"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

const testDatasourceSystemResource = "data.routeros_system_resource.data"

func TestAccDatasourceSystemResourceTest_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,
Steps: []resource.TestStep{
{
Config: testAccDatasourceSystemResourceConfig(),
Check: resource.ComposeTestCheckFunc(
testResourcePrimaryInstanceId(testDatasourceSystemResource),
),
},
},
})

})
}
}

func testAccDatasourceSystemResourceConfig() string {
return providerConfig + `
data "routeros_system_resource" "data" {}
`
}
12 changes: 7 additions & 5 deletions routeros/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,13 @@ func Provider() *schema.Provider {
"routeros_wireguard_keys": ResourceWireguardKeys(),
},
DataSourcesMap: map[string]*schema.Resource{
"routeros_interfaces": DatasourceInterfaces(),
"routeros_ip_addresses": DatasourceIPAddresses(),
"routeros_ip_routes": DatasourceIPRoutes(),
"routeros_firewall": DatasourceFirewall(),
"routeros_ipv6_addresses": DatasourceIPv6Addresses(),
"routeros_firewall": DatasourceFirewall(),
"routeros_interfaces": DatasourceInterfaces(),
"routeros_ip_addresses": DatasourceIPAddresses(),
"routeros_ip_arp": DatasourceIpArp(),
"routeros_ip_routes": DatasourceIPRoutes(),
"routeros_ipv6_addresses": DatasourceIPv6Addresses(),
"routeros_system_resource": DatasourceSystemResource(),
},
ConfigureContextFunc: NewClient,
}
Expand Down

0 comments on commit 79a599e

Please sign in to comment.