-
Notifications
You must be signed in to change notification settings - Fork 132
/
data_iploadbalancing_vrack_network.go
71 lines (62 loc) · 1.97 KB
/
data_iploadbalancing_vrack_network.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
package ovh
import (
"fmt"
"net/url"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func dataSourceIpLoadbalancingVrackNetwork() *schema.Resource {
return &schema.Resource{
Read: dataSourceIpLoadbalancingVrackNetworkRead,
Schema: map[string]*schema.Schema{
"service_name": {
Type: schema.TypeString,
Description: "The internal name of your IPloadbalancer",
Required: true,
},
"vrack_network_id": {
Type: schema.TypeInt,
Description: "Internal Load Balancer identifier of the vRack private network",
Required: true,
},
//Computed
"display_name": {
Type: schema.TypeString,
Description: "Human readable name for your vrack network",
Computed: true,
},
"nat_ip": {
Type: schema.TypeString,
Description: "An IP block used as a pool of IPs by this Load Balancer to connect to the servers in this private network. The blck must be in the private network and reserved for the Load Balancer",
Computed: true,
},
"subnet": {
Type: schema.TypeString,
Description: "IP block of the private network in the vRack",
Computed: true,
},
"vlan": {
Type: schema.TypeInt,
Description: "VLAN of the private network in the vRack. 0 if the private network is not in a VLAN",
Computed: true,
},
},
}
}
func dataSourceIpLoadbalancingVrackNetworkRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
endpoint := fmt.Sprintf(
"/ipLoadbalancing/%s/vrack/network/%d",
url.PathEscape(d.Get("service_name").(string)),
d.Get("vrack_network_id").(int),
)
vn := &IpLoadbalancingVrackNetwork{}
if err := config.OVHClient.Get(endpoint, &vn); err != nil {
return fmt.Errorf("Error calling GET %s:\n\t %q", endpoint, err)
}
// set resource attributes
for k, v := range vn.ToMap() {
d.Set(k, v)
}
d.SetId(fmt.Sprintf("%s/%d", d.Get("service_name").(string), d.Get("vrack_network_id").(int)))
return nil
}