-
Notifications
You must be signed in to change notification settings - Fork 133
/
data_hosting_privatedatabase_user_grant.go
79 lines (69 loc) · 1.78 KB
/
data_hosting_privatedatabase_user_grant.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
package ovh
import (
"fmt"
"net/url"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceHostingPrivateDatabaseUserGrant() *schema.Resource {
return &schema.Resource{
Read: dataSourceHostingPrivateDatabaseUserGrantRead,
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",
},
"user_name": {
Type: schema.TypeString,
Required: true,
Description: "User name used to connect to your databases",
},
// Computed
"creation_date": {
Type: schema.TypeString,
Computed: true,
Description: "Creation date of the user",
},
"grant": {
Type: schema.TypeString,
Computed: true,
Description: "Grant name",
},
},
}
}
func dataSourceHostingPrivateDatabaseUserGrantRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
serviceName := d.Get("service_name").(string)
userName := d.Get("user_name").(string)
databaseName := d.Get("database_name").(string)
ds := &DataSourceHostingPrivateDatabaseUserGrant{}
err := config.OVHClient.Get(
fmt.Sprintf(
"/hosting/privateDatabase/%s/user/%s/grant/%s",
url.PathEscape(serviceName),
url.PathEscape(userName),
url.PathEscape(databaseName),
),
&ds,
)
if err != nil {
return fmt.Errorf(
"Error calling hosting/privateDatabase/%s/user/%s/grant/%s:\n\t %q",
serviceName,
userName,
databaseName,
err,
)
}
d.SetId(fmt.Sprintf("%s/%s/%s/%s", serviceName, userName, databaseName, ds.Grant))
for k, v := range ds.ToMap() {
d.Set(k, v)
}
return nil
}