-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Data source to list DHCP leases
Fixes #316
- Loading branch information
Showing
3 changed files
with
103 additions
and
7 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
examples/data-sources/routeros_ip_dhcp_server_leases/data-source.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
data "routeros_ip_dhcp_server_leases" "data" {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
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 DatasourceIpDhcpServerLeases() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: datasourceIpDhcpServerLeasesRead, | ||
Schema: map[string]*schema.Schema{ | ||
MetaResourcePath: PropResourcePath("/ip/dhcp-server/lease"), | ||
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, | ||
}, | ||
"address": { // Sample = address: "192.168.0.1" | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"address_lists": { // Sample = address-lists: "" | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"blocked": { // Sample = blocked: "false" | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"comment": { // Sample = comment: "server1 " | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"dhcp_option": { // Sample = dhcp-option: "" | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"disabled": { // Sample = disabled: "true" | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"dynamic": { // Sample = dynamic: "false" | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"last_seen": { // Sample = last-seen: "never" | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"mac_address": { // Sample = mac-address: "00:0C:29:00:01:A0" | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"radius": { // Sample = radius: "false" | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"server": { // Sample = server: "bridge_dhcp_lan" | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"status": { // Sample = status: "waiting" | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func datasourceIpDhcpServerLeasesRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
s := DatasourceIpDhcpServerLeases().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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters