-
Notifications
You must be signed in to change notification settings - Fork 131
/
data_ip_service.go
94 lines (82 loc) · 1.97 KB
/
data_ip_service.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
package ovh
import (
"fmt"
"log"
"net/url"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceIpService() *schema.Resource {
return &schema.Resource{
Read: func(d *schema.ResourceData, meta interface{}) error {
return dataSourceIpServiceRead(d, meta)
},
Schema: map[string]*schema.Schema{
"service_name": {
Type: schema.TypeString,
Description: "The service name",
Required: true,
},
//computed
"can_be_terminated": {
Type: schema.TypeBool,
Computed: true,
},
"country": {
Type: schema.TypeString,
Computed: true,
},
"description": {
Type: schema.TypeString,
Description: "Custom description on your ip",
Computed: true,
},
"ip": {
Type: schema.TypeString,
Computed: true,
},
"organisation_id": {
Type: schema.TypeString,
Description: "IP block organisation Id",
Computed: true,
},
"routed_to": {
Type: schema.TypeList,
Description: "Routage information",
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"service_name": {
Type: schema.TypeString,
Description: "Service where ip is routed to",
Computed: true,
},
},
},
},
"type": {
Type: schema.TypeString,
Description: "Possible values for ip type",
Computed: true,
},
},
}
}
func dataSourceIpServiceRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
serviceName := d.Get("service_name").(string)
log.Printf("[DEBUG] Will read ip service %s", serviceName)
endpoint := fmt.Sprintf("/ip/service/%s",
url.PathEscape(serviceName),
)
ip := &IpService{}
if err := config.OVHClient.Get(endpoint, &ip); err != nil {
return fmt.Errorf("Error calling GET %s:\n\t %q", endpoint, err)
}
for k, v := range ip.ToMap() {
if k != "id" {
d.Set(k, v)
}
}
d.SetId(serviceName)
return nil
}