-
Notifications
You must be signed in to change notification settings - Fork 131
/
data_hosting_privatedatabase_database.go
83 lines (73 loc) · 2.11 KB
/
data_hosting_privatedatabase_database.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
package ovh
import (
"fmt"
"net/url"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceHostingPrivateDatabaseDatabase() *schema.Resource {
return &schema.Resource{
Read: dataSourceHostingPrivateDatabaseDatabaseRead,
Schema: map[string]*schema.Schema{
"service_name": {
Type: schema.TypeString,
Required: true,
Description: "The internal name of your private database",
},
"database_name": {
Type: schema.TypeString,
Required: true,
Description: "Database name",
},
// Computed
"backup_time": {
Type: schema.TypeString,
Computed: true,
Description: "Time of the next backup (every day)",
},
"creation_date": {
Type: schema.TypeString,
Computed: true,
Description: "Creation date of the database",
},
"quota_used": {
Type: schema.TypeInt,
Computed: true,
Description: "Space used by the database (in MB)",
},
"users": {
Type: schema.TypeSet,
Computed: true,
Description: "Users granted to this database",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"user_name": {
Type: schema.TypeString,
Description: "User's name granted on this database",
Computed: true,
},
"grant_type": {
Type: schema.TypeString,
Description: "User's rights on this database",
Computed: true,
},
},
},
},
},
}
}
func dataSourceHostingPrivateDatabaseDatabaseRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
serviceName := d.Get("service_name").(string)
databaseName := d.Get("database_name").(string)
ds := &DataSourceHostingPrivateDatabaseDatabase{}
err := config.OVHClient.Get(fmt.Sprintf("/hosting/privateDatabase/%s/database/%s", url.PathEscape(serviceName), url.PathEscape(databaseName)), &ds)
if err != nil {
return fmt.Errorf("error calling hosting/privateDatabase/%s/database/%s:\n\t %q", serviceName, databaseName, err)
}
d.SetId(serviceName)
for k, v := range ds.ToMap() {
d.Set(k, v)
}
return nil
}