/
data_source_appgate_ip_pool.go
64 lines (58 loc) · 1.47 KB
/
data_source_appgate_ip_pool.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package appgate
import (
"context"
"strconv"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceAppgateIPPool() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceAppgateIPPoolRead,
Schema: map[string]*schema.Schema{
"ip_pool_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"ip_pool_name": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"lease_time_days": {
Type: schema.TypeInt,
Computed: true,
},
"total": {
Type: schema.TypeString,
Computed: true,
},
"currently_used": {
Type: schema.TypeString,
Computed: true,
},
"reserved": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
func dataSourceAppgateIPPoolRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
token, err := meta.(*Client).GetToken()
if err != nil {
return diag.FromErr(err)
}
api := meta.(*Client).API.IPPoolsApi
ippool, diags := ResolveIpPoolFromResourceData(ctx, d, api, token)
if diags != nil {
return diags
}
d.SetId(ippool.GetId())
d.Set("ip_pool_name", ippool.GetName())
d.Set("lease_time_days", ippool.GetLeaseTimeDays())
d.Set("total", ippool.GetTotal().String())
d.Set("currently_used", strconv.FormatInt(ippool.GetCurrentlyUsed(), 10))
d.Set("reserved", strconv.FormatInt(ippool.GetReserved(), 10))
return nil
}