-
Notifications
You must be signed in to change notification settings - Fork 132
/
data_hosting_privatedatabase.go
143 lines (134 loc) · 3.34 KB
/
data_hosting_privatedatabase.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package ovh
import (
"fmt"
"net/url"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceHostingPrivateDatabase() *schema.Resource {
return &schema.Resource{
Read: dataSourceHostingPrivateDatabaseRead,
Schema: map[string]*schema.Schema{
"service_name": {
Type: schema.TypeString,
Required: true,
},
// Computed
"cpu": {
Type: schema.TypeInt,
Computed: true,
Description: "Number of CPU on your private database",
},
"datacenter": {
Type: schema.TypeString,
Computed: true,
Description: "Datacenter where this private database is located",
},
"display_name": {
Type: schema.TypeString,
Computed: true,
Description: "Name displayed in customer panel for your private database",
},
"hostname": {
Type: schema.TypeString,
Computed: true,
Description: "Private database hostname",
},
"hostname_ftp": {
Type: schema.TypeString,
Computed: true,
Description: "Private database FTP hostname",
},
"infrastructure": {
Type: schema.TypeString,
Computed: true,
Description: "Infrastructure where service was stored",
},
"offer": {
Type: schema.TypeString,
Computed: true,
Description: "Type of the private database offer",
},
"port": {
Type: schema.TypeInt,
Computed: true,
Description: "Private database service port",
},
"port_ftp": {
Type: schema.TypeInt,
Computed: true,
Description: "Private database FTP port",
},
"quota_size": {
Type: schema.TypeInt,
Computed: true,
Description: "Space allowed (in MB) on your private database",
},
"quota_used": {
Type: schema.TypeInt,
Computed: true,
Description: "Space used (in MB) on your private database",
},
"ram": {
Type: schema.TypeInt,
Computed: true,
Description: "Amount of ram (in MB) on your private database",
},
"server": {
Type: schema.TypeString,
Computed: true,
Description: "Private database server name",
},
"state": {
Type: schema.TypeString,
Computed: true,
Description: "Private database state",
},
"type": {
Type: schema.TypeString,
Computed: true,
Description: "Private database type",
},
"version": {
Type: schema.TypeString,
Computed: true,
Description: "Private database available versions",
},
"version_label": {
Type: schema.TypeString,
Computed: true,
Description: "Private database version label",
},
"version_number": {
Type: schema.TypeFloat,
Computed: true,
Description: "Private database version number",
},
},
}
}
func dataSourceHostingPrivateDatabaseRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
serviceName := d.Get("service_name").(string)
ds := &HostingPrivateDatabase{}
err := config.OVHClient.Get(
fmt.Sprintf(
"/hosting/privateDatabase/%s",
url.PathEscape(serviceName),
),
&ds,
)
if err != nil {
return fmt.Errorf(
"Error calling hosting/privateDatabase/%s:\n\t %q",
serviceName,
err,
)
}
for k, v := range ds.ToMap() {
if k != "service_name" {
d.Set(k, v)
}
}
d.SetId(ds.ServiceName)
return nil
}