Skip to content

Commit

Permalink
feat(ds): Add /ip/arp datasource
Browse files Browse the repository at this point in the history
  • Loading branch information
vaerh committed Nov 13, 2023
1 parent 568f2f5 commit 6ecd622
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/data-sources/routeros_ip_arp/data-source.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
data "routeros_ip_arp" "data" {}
82 changes: 82 additions & 0 deletions routeros/datasource_ip_arp.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package routeros

// Script generated from sampled device MikroTik 7.11.2 (stable) on CHR AMD-x86_64

import (
"context"

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

func DatasourceIpArp() *schema.Resource {
return &schema.Resource{
ReadContext: datasourceIpArpRead,
Schema: map[string]*schema.Schema{
MetaResourcePath: PropResourcePath("/ip/arp"),
MetaId: PropId(Id),

KeyFilter: PropFilterRw,
"data": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": { // Sample = .id: "*1"
Type: schema.TypeString,
Computed: true,
},
"dhcp": { // Sample = DHCP: "false"
Type: schema.TypeBool,
Computed: true,
},
"address": { // Sample = address: "192.168.9.10"
Type: schema.TypeString,
Computed: true,
},
"complete": { // Sample = complete: "true"
Type: schema.TypeBool,
Computed: true,
},
"disabled": { // Sample = disabled: "false"
Type: schema.TypeBool,
Computed: true,
},
"dynamic": { // Sample = dynamic: "true"
Type: schema.TypeBool,
Computed: true,
},
"interface": { // Sample = interface: "ether1"
Type: schema.TypeString,
Computed: true,
},
"invalid": { // Sample = invalid: "false"
Type: schema.TypeBool,
Computed: true,
},
"mac_address": { // Sample = mac-address: "70:85:C2:37:5A:21"
Type: schema.TypeString,
Computed: true,
},
"published": { // Sample = published: "false"
Type: schema.TypeBool,
Computed: true,
},
},
},
},
},
}
}

func datasourceIpArpRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
s := DatasourceIpArp().Schema
path := s[MetaResourcePath].Default.(string)

res, err := ReadItemsFiltered(buildReadFilter(d.Get(KeyFilter).(map[string]interface{})), path, m.(Client))
if err != nil {
return diag.FromErr(err)
}

return MikrotikResourceDataToTerraformDatasource(res, "data", s, d)
}
39 changes: 39 additions & 0 deletions routeros/datasource_ip_arp_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 testDatasourceIpArp = "data.routeros_ip_arp.data"

func TestAccDatasourceIpArpTest_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: testAccDatasourceIpArpConfig(),
Check: resource.ComposeTestCheckFunc(
testResourcePrimaryInstanceId(testDatasourceIpArp),
),
},
},
})

})
}
}

func testAccDatasourceIpArpConfig() string {
return providerConfig + `
data "routeros_ip_arp" "data" {}
`
}

0 comments on commit 6ecd622

Please sign in to comment.