/
data_dedicated_nasha.go
105 lines (95 loc) · 2.4 KB
/
data_dedicated_nasha.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package ovh
import (
"context"
"fmt"
"net/url"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceDedicatedNasha() *schema.Resource {
return &schema.Resource{
ReadContext: dataSourceDedicatedNashaRead,
Schema: map[string]*schema.Schema{
"service_name": {
Type: schema.TypeString,
Required: true,
Description: "The storage service name",
},
// Computed
"urn": {
Type: schema.TypeString,
Computed: true,
},
"can_create_partition": {
Type: schema.TypeBool,
Computed: true,
Description: "True, if partition creation is allowed on this HA-NAS",
},
"custom_name": {
Type: schema.TypeString,
Computed: true,
Description: "The name you give to the HA-NAS",
},
"datacenter": {
Type: schema.TypeString,
Computed: true,
Description: "area of HA-NAS",
},
"disk_type": {
Type: schema.TypeString,
Computed: true,
Description: "the disk type of the HA-NAS",
},
"ip": {
Type: schema.TypeString,
Computed: true,
Description: "Access IP of HA-NAS",
},
"monitored": {
Type: schema.TypeBool,
Computed: true,
Description: "Send an email to customer if any issue is detected",
},
"zpool_capacity": {
Type: schema.TypeFloat,
Computed: true,
Description: "percentage of HA-NAS space used in %",
},
"zpool_size": {
Type: schema.TypeFloat,
Computed: true,
Description: "the size of the HA-NAS",
},
},
}
}
func dataSourceDedicatedNashaRead(c context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
config := meta.(*Config)
serviceName := d.Get("service_name").(string)
ds := &DedicatedNASHA{}
err := config.OVHClient.Get(
fmt.Sprintf(
"/dedicated/nasha/%s",
url.PathEscape(serviceName),
),
&ds,
)
if err != nil {
return diag.Errorf(
"Error calling /dedicated/nasha/%s:\n\t %q",
serviceName,
err,
)
}
d.SetId(ds.ServiceName)
d.Set("urn", ds.URN)
d.Set("service_name", ds.ServiceName)
d.Set("monitored", ds.Monitored)
d.Set("zpool_size", ds.ZpoolSize)
d.Set("zpool_capacity", ds.ZpoolCapacity)
d.Set("datacenter", ds.Datacenter)
d.Set("disk_type", ds.DiskType)
d.Set("can_create_partition", ds.CanCreatePartition)
d.Set("ip", ds.Ip)
return nil
}