Skip to content

Commit

Permalink
Implement ip/service data source
Browse files Browse the repository at this point in the history
Closes #391.
  • Loading branch information
OJFord committed Mar 23, 2024
1 parent 28ba260 commit 928aa0a
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 0 deletions.
33 changes: 33 additions & 0 deletions docs/data-sources/ip_services.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# routeros_ip_services (Data Source)




<!-- schema generated by tfplugindocs -->
## Schema

### Optional

- `filter` (Map of String) Additional request filtering options.

### Read-Only

- `id` (String) The ID of this resource.
- `services` (List of Object) (see [below for nested schema](#nestedatt--services))

<a id="nestedatt--services"></a>
### Nested Schema for `services`

Read-Only:

- `address` (String)
- `certificate` (String)
- `disabled` (Boolean)
- `id` (String)
- `invalid` (String)
- `name` (String)
- `port` (Number)
- `tls_version` (String)
- `vrf` (String)


76 changes: 76 additions & 0 deletions routeros/datasource_ip_services.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package routeros

import (
"context"

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

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

KeyFilter: PropFilterRw,
"services": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
},
"address": {
Type: schema.TypeString,
Computed: true,
},
"certificate": {
Type: schema.TypeString,
Computed: true,
},
"disabled": {
Type: schema.TypeBool,
Computed: true,
},
"invalid": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"port": {
Type: schema.TypeInt,
Computed: true,
},
"tls_version": {
Type: schema.TypeString,
Computed: true,
},
"vrf": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
}
}

func datasourceIPServicesRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
s := DatasourceIPServices().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, "services", s, d)
}
1 change: 1 addition & 0 deletions routeros/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ func Provider() *schema.Provider {
"routeros_ip_arp": DatasourceIpArp(),
"routeros_ip_dhcp_server_leases": DatasourceIpDhcpServerLeases(),
"routeros_ip_routes": DatasourceIPRoutes(),
"routeros_ip_services": DatasourceIPServices(),
"routeros_ipv6_addresses": DatasourceIPv6Addresses(),
"routeros_system_resource": DatasourceSystemResource(),
},
Expand Down

0 comments on commit 928aa0a

Please sign in to comment.