-
Notifications
You must be signed in to change notification settings - Fork 133
/
data_hosting_privatedatabase_whitelist.go
90 lines (81 loc) · 2.03 KB
/
data_hosting_privatedatabase_whitelist.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
package ovh
import (
"fmt"
"net/url"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceHostingPrivateDatabaseWhitelist() *schema.Resource {
return &schema.Resource{
Read: dataSourceHostingPrivateDatabaseWhitelistRead,
Schema: map[string]*schema.Schema{
"service_name": {
Type: schema.TypeString,
Required: true,
Description: "The internal name of your private database",
},
"ip": {
Type: schema.TypeString,
Optional: true,
Description: "The whitelisted IP in your instance",
},
// Computed
"creation_date": {
Type: schema.TypeString,
Computed: true,
Description: "Creation date of this whitelist",
},
"last_update": {
Type: schema.TypeString,
Computed: true,
Description: "The last update date of this whitelist",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "Custom name for your Whitelisted IP",
},
"service": {
Type: schema.TypeBool,
Computed: true,
Description: "Authorize this IP to access service port",
},
"sftp": {
Type: schema.TypeBool,
Computed: true,
Description: "Authorize this IP to access SFTP port",
},
"status": {
Type: schema.TypeString,
Computed: true,
Description: "Whitelist status",
},
},
}
}
func dataSourceHostingPrivateDatabaseWhitelistRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
serviceName := d.Get("service_name").(string)
ip := d.Get("ip").(string)
ds := &HostingPrivateDatabaseWhitelist{}
err := config.OVHClient.Get(
fmt.Sprintf(
"/hosting/privateDatabase/%s/whitelist/%s",
url.PathEscape(serviceName),
url.PathEscape(ip),
),
&ds,
)
if err != nil {
return fmt.Errorf(
"error calling hosting/privateDatabase/%s/whitelist/%s:\n\t %q",
serviceName,
ip,
err,
)
}
d.SetId(fmt.Sprintf("%s/%s", serviceName, ip))
for k, v := range ds.DataSourceToMap() {
d.Set(k, v)
}
return nil
}