-
Notifications
You must be signed in to change notification settings - Fork 131
/
types_ip_service.go
88 lines (71 loc) · 2.19 KB
/
types_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
package ovh
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/ovh/terraform-provider-ovh/ovh/helpers"
)
type IpService struct {
CanBeTerminated bool `json:"canBeTerminated"`
Country *string `json:"country"`
Description *string `json:"description"`
Ip string `json:"ip"`
OrganisationId *string `json:"organisationId"`
RoutedTo *IpServiceRoutedTo `json:"routedTo"`
Type string `json:"type"`
}
func (v IpService) ToMap() map[string]interface{} {
obj := make(map[string]interface{})
obj["can_be_terminated"] = v.CanBeTerminated
obj["ip"] = v.Ip
obj["type"] = v.Type
if v.Country != nil {
obj["country"] = *v.Country
}
if v.Description != nil {
obj["description"] = *v.Description
}
if v.OrganisationId != nil {
obj["organisation_id"] = *v.OrganisationId
}
if v.RoutedTo != nil {
obj["routed_to"] = []interface{}{v.RoutedTo.ToMap()}
}
return obj
}
type IpServiceRoutedTo struct {
ServiceName string `json:"serviceName"`
}
func (v IpServiceRoutedTo) ToMap() map[string]interface{} {
obj := make(map[string]interface{})
obj["service_name"] = v.ServiceName
return obj
}
type IpServiceUpdateOpts struct {
Description *string `json:"description,omitempty"`
}
func (opts *IpServiceUpdateOpts) FromResource(d *schema.ResourceData) *IpServiceUpdateOpts {
opts.Description = helpers.GetNilStringPointerFromData(d, "description")
return opts
}
// see https://api.ovh.com/console/#/ip/%7Bip%7D/move~POST
type IpMoveOpts struct {
NextHop *string `json:"nexthop,omitempty"`
To *string `json:"to"`
}
func (opts *IpMoveOpts) FromResource(d *schema.ResourceData) (*IpMoveOpts, error) {
opts.To = GetRoutedToServiceName(d)
return opts, nil
}
func GetRoutedToServiceName(d *schema.ResourceData) *string {
routedTo := (d.Get("routed_to")).([]interface{})
if routedTo == nil || len(routedTo) == 0 || routedTo[0] == nil {
return nil
}
serviceName := (routedTo[0].(map[string]interface{}))["service_name"].(string)
if serviceName == "" {
return nil
}
return &serviceName
}
type IpServiceConfirmTerminationOpts struct {
Token string `json:"token"`
}